Преглед изворни кода

Gegenstände despawnen jetzt nach 2 minuten wenn sie nicht eingesammelt werden

Kolja Strohm пре 4 година
родитељ
комит
42c386564a

+ 7 - 0
StickmanWorldOnline/Gegenstand.cpp

@@ -109,6 +109,7 @@ GegenstandTyp GegenstandTypVar::getValue() const
 Gegenstand::Gegenstand( int id, GegenstandTyp typ, int x, int y, int w, int h )
     : GameObject( GEGENSTAND, x, y, w, h )
 {
+    timeLeft = 120;
     this->id = id;
     this->typ = typ;
 }
@@ -118,6 +119,12 @@ int Gegenstand::getId() const
     return id;
 }
 
+bool Gegenstand::tick( double zeit )
+{
+    timeLeft -= zeit;
+    return timeLeft <= 0;
+}
+
 GegenstandTyp Gegenstand::getTyp() const
 {
     return typ;

+ 3 - 0
StickmanWorldOnline/Gegenstand.h

@@ -25,10 +25,13 @@ class Gegenstand : public GameObject
 {
 private:
     GegenstandTyp typ;
+    double timeLeft;
     int id;
 
 public:
     Gegenstand( int id, GegenstandTyp typ, int x = 0, int y = 0, int w = 50, int h = 50 );
     int getId() const;
+    // gibt 1 zurück, wenn der gegenstand despornt
+    bool tick( double zeit );
     GegenstandTyp getTyp() const;
 };

+ 9 - 0
StickmanWorldOnline/Spiel.cpp

@@ -522,6 +522,15 @@ void Spiel::tick( double zeit )
             }
         }
     }
+    // gegenstand despawn
+    for( int i = 0; i < items.getEintragAnzahl(); i++ )
+    {
+        if( items.z( i )->tick( zeit ) )
+        {
+            items.remove( i );
+            i--;
+        }
+    }
     Richtung rs[] = { OBEN, RECHTS, UNTEN, LINKS };
     // spieler bewegungen
     for( auto s = spieler.getIterator(); s; s++ )