Geschoss.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #include "Geschoss.h"
  2. Geschoss::Geschoss( int id, float speed, GeschossTyp typ, Richtung r, int x, int y, Spieler *besitzer )
  3. : GameObject( GESCHOSS, x, y, 20, 20 )
  4. {
  5. if( typ == GESCHOSS_PFEIL )
  6. {
  7. if( r == OBEN || r == UNTEN )
  8. setHeight( 50 );
  9. else
  10. setWidth( 50 );
  11. }
  12. this->speed = speed;
  13. this->richtung = richtung;
  14. this->besitzer = besitzer;
  15. this->typ = typ;
  16. tunnelBenutzt = 0;
  17. umgelenkt = 0;
  18. geschosseGetroffen = 0;
  19. schalter = 0;
  20. this->id = id;
  21. }
  22. Geschoss::~Geschoss()
  23. {
  24. if( besitzer )
  25. besitzer->release();
  26. }
  27. void Geschoss::invertDirection()
  28. {
  29. richtung = invert( richtung );
  30. }
  31. void Geschoss::addUmlenkung()
  32. {
  33. umgelenkt++;
  34. }
  35. void Geschoss::addGeschossTreffer()
  36. {
  37. geschosseGetroffen++;
  38. }
  39. void Geschoss::addTunnel()
  40. {
  41. schalter++;
  42. }
  43. void Geschoss::addSchalter()
  44. {
  45. id++;
  46. }
  47. void Geschoss::setRichtung( Richtung r )
  48. {
  49. richtung = r;
  50. }
  51. void Geschoss::tick( double zeit )
  52. {
  53. switch( richtung )
  54. {
  55. case OBEN:
  56. y -= (float)zeit * speed;
  57. break;
  58. case UNTEN:
  59. y += (float)zeit * speed;
  60. break;
  61. case RECHTS:
  62. x += (float)zeit * speed;
  63. break;
  64. case LINKS:
  65. x -= (float)zeit * speed;
  66. break;
  67. case MITTE:
  68. break;
  69. }
  70. }
  71. GeschossTyp Geschoss::getTyp() const
  72. {
  73. return typ;
  74. }
  75. Spieler *Geschoss::zBesitzer() const
  76. {
  77. return besitzer;
  78. }
  79. Spieler *Geschoss::getBesitzer() const
  80. {
  81. return besitzer ? (Spieler *)besitzer->getThis() : 0;
  82. }
  83. Richtung Geschoss::getRichtung() const
  84. {
  85. return richtung;
  86. }
  87. FeuerballTreffer::FeuerballTreffer( int id, int x, int y, Spieler *besitzer, int maxZeit )
  88. : GameObject( FEUERBALL_TREFFER, x - 75, y - 75, 150, 150 )
  89. {
  90. this->id = id;
  91. this->besitzer = besitzer;
  92. this->timeLeft = (float)maxZeit;
  93. count = 0;
  94. }
  95. FeuerballTreffer::~FeuerballTreffer()
  96. {
  97. besitzer->release();
  98. }
  99. void FeuerballTreffer::tick( double zeit )
  100. {
  101. timeLeft -= (float)zeit;
  102. count++;
  103. }
  104. bool FeuerballTreffer::isOver() const
  105. {
  106. return timeLeft <= 0;
  107. }
  108. bool FeuerballTreffer::makeDamage() const
  109. {
  110. return count % 2;
  111. }
  112. Spieler *FeuerballTreffer::zVerursacher() const
  113. {
  114. return besitzer;
  115. }