Bariere.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #include "Bariere.h"
  2. Bariere::Bariere( int id, int x, int y, int breite, int height, int style, int verschiebungWeite, int autoSchaltungMaxTime, Team *team )
  3. : GameObject( x, y, breite, height )
  4. {
  5. this->id = id;
  6. this->style = style;
  7. this->autoSchaltungMaxTime = autoSchaltungMaxTime;
  8. autoSchaltungCurrentTime = (float)autoSchaltungMaxTime;
  9. this->verschiebungWeite = verschiebungWeite;
  10. currentWeite = 0;
  11. verschiebungAnzahl = 0;
  12. schaltungAnzahl = 0;
  13. this->team = team;
  14. }
  15. Bariere::~Bariere()
  16. {
  17. team->release();
  18. }
  19. void Bariere::setStyle( int style, bool add )
  20. {
  21. if( add )
  22. this->style |= style;
  23. else
  24. this->style &= ~style;
  25. }
  26. void Bariere::setAutoVerschiebungWeite( int pixel )
  27. {
  28. autoSchaltungMaxTime = pixel;
  29. }
  30. void Bariere::startAutoVerschiebung()
  31. {
  32. if( hatStyle( Style::AutoVerschiebung ) )
  33. return;
  34. currentWeite = 0;
  35. setStyle( Style::InVerschiebung, 1 );
  36. }
  37. void Bariere::setAutoSchaltungMaxTime( int seconds )
  38. {
  39. autoSchaltungMaxTime = seconds;
  40. }
  41. void Bariere::startAutoSchaltung()
  42. {
  43. if( hatStyle( Style::AutoSchaltung ) )
  44. return;
  45. autoSchaltungCurrentTime = (float)autoSchaltungMaxTime;
  46. setStyle( Style::InSchaltung, 1 );
  47. }
  48. void Bariere::setTeam( Team *team )
  49. {
  50. this->team->release();
  51. this->team = team;
  52. }
  53. void Bariere::tick( double time )
  54. {
  55. if( hatStyle( Style::InSchaltung ) )
  56. {
  57. autoSchaltungCurrentTime -= (float)time;
  58. if( autoSchaltungCurrentTime < 0 )
  59. {
  60. setStyle( Style::InSchaltung, 0 );
  61. setStyle( Style::Aktiv, !hatStyle( Style::Aktiv ) );
  62. schaltungAnzahl++;
  63. }
  64. }
  65. if( hatStyle( Style::InVerschiebung ) )
  66. {
  67. int last = (int)currentWeite;
  68. currentWeite += (float)time * 10;
  69. if( currentWeite >= verschiebungWeite )
  70. {
  71. currentWeite = (float)verschiebungWeite;
  72. setStyle( Style::InVerschiebung, 0 );
  73. setStyle( Style::NextVerschiebungLinksOben, !hatStyle( Style::NextVerschiebungLinksOben ) );
  74. verschiebungAnzahl++;
  75. }
  76. if( hatStyle( Style::VerschiebungWaagerecht ) )
  77. {
  78. if( hatStyle( Style::NextVerschiebungLinksOben ) )
  79. setX( getX() + last - (int)currentWeite );
  80. else
  81. setX( getX() - last + (int)currentWeite );
  82. }
  83. else
  84. {
  85. if( hatStyle( Style::NextVerschiebungLinksOben ) )
  86. setY( getX() + last - (int)currentWeite );
  87. else
  88. setY( getX() - last + (int)currentWeite );
  89. }
  90. }
  91. }
  92. bool Bariere::hatStyle( int style ) const
  93. {
  94. return ( this->style | style ) == this->style;
  95. }
  96. int Bariere::getVerschiebungAnzahl() const
  97. {
  98. return verschiebungAnzahl;
  99. }
  100. int Bariere::getSchaltungAnzahl() const
  101. {
  102. return schaltungAnzahl;
  103. }
  104. Team *Bariere::getTeam() const
  105. {
  106. return (Team*)team->getThis();
  107. }
  108. Team *Bariere::zTeam() const
  109. {
  110. return team;
  111. }