Geschoss.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. if( richtung == OBEN )
  30. richtung = UNTEN;
  31. else if( richtung == RECHTS )
  32. richtung = LINKS;
  33. else if( richtung == UNTEN )
  34. richtung = OBEN;
  35. else if( richtung == LINKS )
  36. richtung = RECHTS;
  37. }
  38. void Geschoss::addUmlenkung()
  39. {
  40. umgelenkt++;
  41. }
  42. void Geschoss::addGeschossTreffer()
  43. {
  44. geschosseGetroffen++;
  45. }
  46. void Geschoss::addTunnel()
  47. {
  48. schalter++;
  49. }
  50. void Geschoss::addSchalter()
  51. {
  52. id++;
  53. }
  54. void Geschoss::setRichtung( Richtung r )
  55. {
  56. richtung = r;
  57. }
  58. void Geschoss::tick( double zeit )
  59. {
  60. switch( richtung )
  61. {
  62. case OBEN:
  63. y -= zeit * speed;
  64. break;
  65. case UNTEN:
  66. y += zeit * speed;
  67. break;
  68. case RECHTS:
  69. x += zeit * speed;
  70. break;
  71. case LINKS:
  72. x -= zeit * speed;
  73. break;
  74. }
  75. }
  76. GeschossTyp Geschoss::getTyp() const
  77. {
  78. return typ;
  79. }
  80. Spieler *Geschoss::zBesitzer() const
  81. {
  82. return besitzer;
  83. }
  84. Spieler *Geschoss::getBesitzer() const
  85. {
  86. return besitzer ? (Spieler *)besitzer->getThis() : 0;
  87. }