Umlenkung.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include "Umlenkung.h"
  2. Umlenkung::Umlenkung( int id, int x, int y, int breite, int height, Richtung richtung, int maxAbklingzeit, bool drehend, bool aktiv )
  3. : GameObject( UMLENKUNG, x, y, breite, height )
  4. {
  5. this->id = id;
  6. this->richtung = richtung;
  7. this->maxAbklingzeit = maxAbklingzeit;
  8. this->drehend = drehend;
  9. this->aktiv = aktiv;
  10. benutzt = 0;
  11. abklingzeitVerbleibend = 0;
  12. }
  13. void Umlenkung::setMaxAbklingzeit( int sekunden )
  14. {
  15. this->maxAbklingzeit = sekunden;
  16. }
  17. void Umlenkung::setAktiv( bool aktiv )
  18. {
  19. this->aktiv = aktiv;
  20. }
  21. void Umlenkung::setDrehend( bool drehend )
  22. {
  23. this->drehend = drehend;
  24. }
  25. void Umlenkung::setRichtung( Richtung r )
  26. {
  27. this->richtung = r;
  28. }
  29. void Umlenkung::addBenutzt()
  30. {
  31. benutzt++;
  32. if( drehend )
  33. {
  34. switch( richtung )
  35. {
  36. case OBEN:
  37. richtung = RECHTS;
  38. break;
  39. case RECHTS:
  40. richtung = UNTEN;
  41. break;
  42. case UNTEN:
  43. richtung = LINKS;
  44. break;
  45. case LINKS:
  46. richtung = OBEN;
  47. break;
  48. default:
  49. break;
  50. }
  51. }
  52. abklingzeitVerbleibend = (float)maxAbklingzeit;
  53. }
  54. void Umlenkung::tick( double time )
  55. {
  56. if( abklingzeitVerbleibend > 0 )
  57. {
  58. abklingzeitVerbleibend -= (float)time;
  59. if( abklingzeitVerbleibend < 0 )
  60. abklingzeitVerbleibend = 0;
  61. }
  62. }
  63. bool Umlenkung::isAktive() const
  64. {
  65. return aktiv;
  66. }
  67. bool Umlenkung::hatAbklingzeit() const
  68. {
  69. return abklingzeitVerbleibend > 0;
  70. }
  71. bool Umlenkung::istDrehend() const
  72. {
  73. return drehend;
  74. }
  75. int Umlenkung::getMaxAbklingzeit() const
  76. {
  77. return maxAbklingzeit;
  78. }
  79. Richtung Umlenkung::getRichtung() const
  80. {
  81. return richtung;
  82. }
  83. int Umlenkung::getBenutzungen() const
  84. {
  85. return benutzt;
  86. }
  87. int Umlenkung::getId() const
  88. {
  89. return id;
  90. }