Jelajahi Sumber

Bariere fertig

Kolja Strohm 6 tahun lalu
induk
melakukan
63aa8147d9

+ 126 - 0
StickmanWorldOnline/Bariere.cpp

@@ -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;
+}

+ 1 - 0
StickmanWorldOnline/StickmanWorldOnline.vcxproj

@@ -77,6 +77,7 @@
     <IncludePath>..\..\..\..\..\Allgemein\Framework;..\..\..\..\..\Allgemein\Network\Network;../../../Framework/release;../../../Network/release;..\Linie;$(IncludePath)</IncludePath>
   </PropertyGroup>
   <ItemGroup>
+    <ClCompile Include="Bariere.cpp" />
     <ClCompile Include="DllStart.cpp" />
     <ClCompile Include="Reader.cpp" />
     <ClCompile Include="Spiel.cpp" />

+ 3 - 0
StickmanWorldOnline/StickmanWorldOnline.vcxproj.filters

@@ -51,6 +51,9 @@
     <ClCompile Include="Team.cpp">
       <Filter>Spiel\Objekte</Filter>
     </ClCompile>
+    <ClCompile Include="Bariere.cpp">
+      <Filter>Spiel\Objekte</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="SpielKlasse.h">

+ 1 - 1
StickmanWorldOnline/Tunnel.cpp

@@ -16,7 +16,7 @@ void Tunnel::setZielX( int x )
     zielX = x;
 }
 
-int Tunnel::setZielY( int y )
+void Tunnel::setZielY( int y )
 {
     zielY = y;
 }

+ 1 - 1
StickmanWorldOnline/Tunnel.h

@@ -14,7 +14,7 @@ private:
 public:
     Tunnel( int id, int x, int y, int width, int height, int zielX, int zielY, bool aktiv );
     void setZielX( int x );
-    int setZielY( int y );
+    void setZielY( int y );
     void addBenutzung();
     void setAktiv( bool aktiv );
     int getZielX() const;

+ 2 - 2
StickmanWorldOnline/Umlenkung.cpp

@@ -53,14 +53,14 @@ void Umlenkung::addBenutzt()
             richtung = OBEN;
         }
     }
-    abklingzeitVerbleibend = maxAbklingzeit;
+    abklingzeitVerbleibend = (float)maxAbklingzeit;
 }
 
 void Umlenkung::tick( double time )
 {
     if( abklingzeitVerbleibend > 0 )
     {
-        abklingzeitVerbleibend -= time;
+        abklingzeitVerbleibend -= (float)time;
         if( abklingzeitVerbleibend < 0 )
             abklingzeitVerbleibend = 0;
     }