Umlenkung.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. case MITTE:
  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. }