Explorar el Código

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

Kolja Strohm hace 4 años
padre
commit
ef2882626d

+ 7 - 0
StickmanWorldOnline/Gegenstand.cpp

@@ -153,6 +153,7 @@ GegenstandTyp GegenstandTypVar::getValue() const
 Gegenstand::Gegenstand( ResourceRegistry *zResources, 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;
     texturScale = 1;
@@ -219,6 +220,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

@@ -28,10 +28,13 @@ class Gegenstand : public GameObject
 {
 private:
     GegenstandTyp typ;
+    double timeLeft;
     int id;
 
 public:
     Gegenstand( ResourceRegistry *zResources, 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;
 };

+ 28 - 16
StickmanWorldOnline/Spiel.cpp

@@ -160,9 +160,12 @@ bool Spiel::istAmLeben() const
 
 void Spiel::tick()
 {
-    rZeit -= TICK;// spieler bewegungen
-    nextAutoVerschiebung -= TICK;
-    nextAutoSchaltung -= TICK;
+    double zeit = TICK;
+    rZeit -= zeit;// spieler bewegungen
+    if( pause )
+        zeit = 0;
+    nextAutoVerschiebung -= zeit;
+    nextAutoSchaltung -= zeit;
     if( nextAutoVerschiebung <= 0 )
     {
         nextAutoVerschiebung += 30 + randG.rand() * 30;
@@ -215,34 +218,43 @@ void Spiel::tick()
             }
         }
     }
+    // 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 };
     for( auto s = spieler.getIterator(); s; s++ )
     {
         for( Richtung r : rs )
         {
-            s->move( r, TICK );
+            s->move( r, zeit );
             if( s->getX() < 0 || s->getY() < 0 || s->getX() + s->getWidth() >= mapSize.x || s->getY() + s->getHeight() >= mapSize.y )
-                s->move( r, -TICK );
+                s->move( r, -zeit );
             else
             {
                 for( auto b = barieren.getIterator(); b; b++ )
                 { // spieler - bariere intersection
                     if( b->hatStyle( Bariere::Style::Aktiv ) && ( b->zTeam() != s->zTeam() ) && b->intersectsWith( s ) )
-                        s->move( r, -TICK );
+                        s->move( r, -zeit );
                 }
             }
         }
     }
     for( auto s = spieler.getIterator(); s; s++ )
-        s->tick( TICK, this );
+        s->tick( zeit, this );
     // barieren bewegung
     for( auto b = barieren.getIterator(); b; b++ )
-        b->tick( TICK, this );
+        b->tick( zeit, this );
     // geschoss bewegung
     for( int i = 0; i < shots.getEintragAnzahl(); i++ )
     {
         Geschoss *g = shots.z( i );
-        g->tick( TICK );
+        g->tick( zeit );
         bool removed = 0;
         // geschoss - bariere intersection
         bool intersectsWithBariere = 0;
@@ -259,7 +271,7 @@ void Spiel::tick()
             if( zuletztBariereGetroffenesGeschoss )
                 zuletztBariereGetroffenesGeschoss->release();
             zuletztBariereGetroffenesGeschoss = (Geschoss *)g->getThis();
-            g->tick( -TICK );
+            g->tick( -zeit );
             switch( g->getTyp() )
             {
             case GESCHOSS_PFEIL:
@@ -430,7 +442,7 @@ void Spiel::tick()
     for( int i = 0; i < feuer.getEintragAnzahl(); i++ )
     {
         FeuerballTreffer *f = feuer.z( i );
-        f->tick( TICK );
+        f->tick( zeit );
         if( f->isOver() )
         {
             feuer.remove( i );
@@ -448,20 +460,20 @@ void Spiel::tick()
     }
     // Drop Ticks
     for( auto d = drops.getIterator(); d; d++ )
-        d->tick( TICK, this );
+        d->tick( zeit, this );
     // Timer Ticks
     for( auto t = timer.getIterator(); t; t++ )
-        t->tick( TICK, this );
+        t->tick( zeit, this );
     // Umlenkung Ticks
     for( auto u = umlenkungen.getIterator(); u; u++ )
-        u->tick( TICK );
+        u->tick( zeit );
     // Base Ticks
     for( auto b = basen.getIterator(); b; b++ )
-        b->tick( TICK, this );
+        b->tick( zeit, this );
     // aktive trigger Ticks
     for( int i = 0; i < triggerRuns.getEintragAnzahl(); i++ )
     {
-        if( !triggerRuns.z( i )->runNext( TICK ) )
+        if( !triggerRuns.z( i )->runNext( zeit ) )
         {
             Ereignis *e = new Ereignis( AUSLOESER_RUNNED );
             e->addParameter( "Betroffener Auslöser", triggerRuns.z( i )->getTrigger() );