Umlenkung.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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( 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. }
  48. }
  49. abklingzeitVerbleibend = maxAbklingzeit;
  50. }
  51. void Umlenkung::tick( double time )
  52. {
  53. if( abklingzeitVerbleibend > 0 )
  54. {
  55. abklingzeitVerbleibend -= time;
  56. if( abklingzeitVerbleibend < 0 )
  57. abklingzeitVerbleibend = 0;
  58. }
  59. }
  60. bool Umlenkung::isAktive() const
  61. {
  62. return aktiv;
  63. }
  64. bool Umlenkung::hatAbklingzeit() const
  65. {
  66. return abklingzeitVerbleibend > 0;
  67. }
  68. bool Umlenkung::istDrehend() const
  69. {
  70. return drehend;
  71. }
  72. int Umlenkung::getMaxAbklingzeit() const
  73. {
  74. return maxAbklingzeit;
  75. }
  76. Richtung Umlenkung::getRichtung() const
  77. {
  78. return richtung;
  79. }