Bariere.cpp 3.0 KB

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