Geschoss.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #include "Geschoss.h"
  2. #include "Spiel.h"
  3. Geschoss::Geschoss( int id, float speed, GeschossTyp typ, Richtung r, int x, int y, Spieler *besitzer )
  4. : GameObject( GESCHOSS, x, y, 15, 15 )
  5. {
  6. if( typ == GESCHOSS_PFEIL )
  7. {
  8. if( r == OBEN || r == UNTEN )
  9. {
  10. setWidth( 7 );
  11. setHeight( 30 );
  12. }
  13. else
  14. {
  15. setWidth( 30 );
  16. setHeight( 7 );
  17. }
  18. }
  19. this->speed = speed;
  20. this->richtung = richtung;
  21. this->besitzer = besitzer;
  22. this->typ = typ;
  23. tunnelBenutzt = 0;
  24. umgelenkt = 0;
  25. geschosseGetroffen = 0;
  26. schalter = 0;
  27. this->id = id;
  28. }
  29. Geschoss::~Geschoss()
  30. {
  31. if( besitzer )
  32. besitzer->release();
  33. }
  34. void Geschoss::invertDirection()
  35. {
  36. richtung = invert( richtung );
  37. }
  38. void Geschoss::addUmlenkung( Spiel *zSpiel )
  39. {
  40. zSpiel->setGeschossZuletztUmgelenkt( (Geschoss *)getThis() );
  41. umgelenkt++;
  42. }
  43. void Geschoss::addGeschossTreffer( Spiel *zSpiel )
  44. {
  45. zSpiel->setGeschossZuletztGeschossGetroffen( (Geschoss *)getThis() );
  46. geschosseGetroffen++;
  47. }
  48. void Geschoss::addTunnel( Spiel *zSpiel )
  49. {
  50. zSpiel->setGeschossZuletztTunnelBenutzt( (Geschoss *)getThis() );
  51. schalter++;
  52. }
  53. void Geschoss::addSchalter()
  54. {
  55. id++;
  56. }
  57. void Geschoss::setSpeed( float speed )
  58. {
  59. this->speed = speed;
  60. }
  61. void Geschoss::setBesitzer( Spieler *besitzer )
  62. {
  63. if( this->besitzer )
  64. this->besitzer->release();
  65. this->besitzer = besitzer;
  66. }
  67. void Geschoss::setTyp( GeschossTyp typ )
  68. {
  69. this->typ = typ;
  70. if( typ == GESCHOSS_PFEIL )
  71. {
  72. if( richtung == OBEN || richtung == UNTEN )
  73. {
  74. setWidth( 7 );
  75. setHeight( 30 );
  76. }
  77. else
  78. {
  79. setWidth( 30 );
  80. setHeight( 7 );
  81. }
  82. }
  83. else
  84. {
  85. setWidth( 15 );
  86. setHeight( 15 );
  87. }
  88. }
  89. void Geschoss::setRichtung( Richtung r )
  90. {
  91. richtung = r;
  92. }
  93. void Geschoss::tick( double zeit )
  94. {
  95. switch( richtung )
  96. {
  97. case OBEN:
  98. y -= (float)zeit * speed;
  99. break;
  100. case UNTEN:
  101. y += (float)zeit * speed;
  102. break;
  103. case RECHTS:
  104. x += (float)zeit * speed;
  105. break;
  106. case LINKS:
  107. x -= (float)zeit * speed;
  108. break;
  109. default:
  110. break;
  111. }
  112. }
  113. GeschossTyp Geschoss::getTyp() const
  114. {
  115. return typ;
  116. }
  117. Spieler *Geschoss::zBesitzer() const
  118. {
  119. return besitzer;
  120. }
  121. Spieler *Geschoss::getBesitzer() const
  122. {
  123. return besitzer ? (Spieler *)besitzer->getThis() : 0;
  124. }
  125. Richtung Geschoss::getRichtung() const
  126. {
  127. return richtung;
  128. }
  129. FeuerballTreffer::FeuerballTreffer( int id, int x, int y, Spieler *besitzer, int maxZeit )
  130. : GameObject( FEUERBALL_TREFFER, x - 75, y - 75, 150, 150 )
  131. {
  132. this->id = id;
  133. this->besitzer = besitzer;
  134. this->timeLeft = (float)maxZeit;
  135. count = 0;
  136. }
  137. FeuerballTreffer::~FeuerballTreffer()
  138. {
  139. besitzer->release();
  140. }
  141. void FeuerballTreffer::tick( double zeit )
  142. {
  143. timeLeft -= (float)zeit;
  144. count++;
  145. }
  146. bool FeuerballTreffer::isOver() const
  147. {
  148. return timeLeft <= 0;
  149. }
  150. bool FeuerballTreffer::makeDamage() const
  151. {
  152. return count % 2;
  153. }
  154. Spieler *FeuerballTreffer::zVerursacher() const
  155. {
  156. return besitzer;
  157. }