|
@@ -0,0 +1,126 @@
|
|
|
|
+#include "Bariere.h"
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+Bariere::Bariere( int id, int x, int y, int breite, int height, int style, int verschiebungWeite, int autoSchaltungMaxTime, Team *team )
|
|
|
|
+ : GameObject( x, y, breite, height )
|
|
|
|
+{
|
|
|
|
+ this->id = id;
|
|
|
|
+ this->style = style;
|
|
|
|
+ this->autoSchaltungMaxTime = autoSchaltungMaxTime;
|
|
|
|
+ autoSchaltungCurrentTime = (float)autoSchaltungMaxTime;
|
|
|
|
+ this->verschiebungWeite = verschiebungWeite;
|
|
|
|
+ currentWeite = 0;
|
|
|
|
+ verschiebungAnzahl = 0;
|
|
|
|
+ schaltungAnzahl = 0;
|
|
|
|
+ this->team = team;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+Bariere::~Bariere()
|
|
|
|
+{
|
|
|
|
+ team->release();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Bariere::setStyle( int style, bool add )
|
|
|
|
+{
|
|
|
|
+ if( add )
|
|
|
|
+ this->style |= style;
|
|
|
|
+ else
|
|
|
|
+ this->style &= ~style;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Bariere::setAutoVerschiebungWeite( int pixel )
|
|
|
|
+{
|
|
|
|
+ autoSchaltungMaxTime = pixel;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Bariere::startAutoVerschiebung()
|
|
|
|
+{
|
|
|
|
+ if( hatStyle( Style::AutoVerschiebung ) )
|
|
|
|
+ return;
|
|
|
|
+ currentWeite = 0;
|
|
|
|
+ setStyle( Style::InVerschiebung, 1 );
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Bariere::setAutoSchaltungMaxTime( int seconds )
|
|
|
|
+{
|
|
|
|
+ autoSchaltungMaxTime = seconds;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Bariere::startAutoSchaltung()
|
|
|
|
+{
|
|
|
|
+ if( hatStyle( Style::AutoSchaltung ) )
|
|
|
|
+ return;
|
|
|
|
+ autoSchaltungCurrentTime = (float)autoSchaltungMaxTime;
|
|
|
|
+ setStyle( Style::InSchaltung, 1 );
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Bariere::setTeam( Team *team )
|
|
|
|
+{
|
|
|
|
+ this->team->release();
|
|
|
|
+ this->team = team;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Bariere::tick( double time )
|
|
|
|
+{
|
|
|
|
+ if( hatStyle( Style::InSchaltung ) )
|
|
|
|
+ {
|
|
|
|
+ autoSchaltungCurrentTime -= (float)time;
|
|
|
|
+ if( autoSchaltungCurrentTime < 0 )
|
|
|
|
+ {
|
|
|
|
+ setStyle( Style::InSchaltung, 0 );
|
|
|
|
+ setStyle( Style::Aktiv, !hatStyle( Style::Aktiv ) );
|
|
|
|
+ schaltungAnzahl++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if( hatStyle( Style::InVerschiebung ) )
|
|
|
|
+ {
|
|
|
|
+ int last = (int)currentWeite;
|
|
|
|
+ currentWeite += (float)time * 10;
|
|
|
|
+ if( currentWeite >= verschiebungWeite )
|
|
|
|
+ {
|
|
|
|
+ currentWeite = (float)verschiebungWeite;
|
|
|
|
+ setStyle( Style::InVerschiebung, 0 );
|
|
|
|
+ setStyle( Style::NextVerschiebungLinksOben, !hatStyle( Style::NextVerschiebungLinksOben ) );
|
|
|
|
+ verschiebungAnzahl++;
|
|
|
|
+ }
|
|
|
|
+ if( hatStyle( Style::VerschiebungWaagerecht ) )
|
|
|
|
+ {
|
|
|
|
+ if( hatStyle( Style::NextVerschiebungLinksOben ) )
|
|
|
|
+ setX( getX() + last - (int)currentWeite );
|
|
|
|
+ else
|
|
|
|
+ setX( getX() - last + (int)currentWeite );
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ if( hatStyle( Style::NextVerschiebungLinksOben ) )
|
|
|
|
+ setY( getX() + last - (int)currentWeite );
|
|
|
|
+ else
|
|
|
|
+ setY( getX() - last + (int)currentWeite );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool Bariere::hatStyle( int style ) const
|
|
|
|
+{
|
|
|
|
+ return ( this->style | style ) == this->style;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int Bariere::getVerschiebungAnzahl() const
|
|
|
|
+{
|
|
|
|
+ return verschiebungAnzahl;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int Bariere::getSchaltungAnzahl() const
|
|
|
|
+{
|
|
|
|
+ return schaltungAnzahl;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+Team *Bariere::getTeam() const
|
|
|
|
+{
|
|
|
|
+ return (Team*)team->getThis();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+Team *Bariere::zTeam() const
|
|
|
|
+{
|
|
|
|
+ return team;
|
|
|
|
+}
|