Selaa lähdekoodia

Flüssigere Trodesannimation für spieler

Kolja Strohm 6 vuotta sitten
vanhempi
commit
b353ff29cb

+ 4 - 0
Asteroids/Spiel/SpielKlasse.cpp

@@ -143,6 +143,8 @@ void SpielKlasse::load()
         i->load();
     for( auto i = pixel->getIterator(); i; i++ )
         i->load();
+    for( auto i = deads->getIterator(); i; i++ )
+        i->load();
 }
 
 void SpielKlasse::save()
@@ -156,6 +158,8 @@ void SpielKlasse::save()
         i->save();
     for( auto i = pixel->getIterator(); i; i++ )
         i->save();
+    for( auto i = deads->getIterator(); i; i++ )
+        i->save();
 }
 
 void SpielKlasse::tick()

+ 27 - 0
Asteroids/Spiel/Spieler/DeadPlayer.cpp

@@ -22,6 +22,7 @@ DeadPlayer::DeadPlayer( Model2DData *mda, Model2DData *mdb, Vertex posa, Vertex
     m2b->setDrehungSpeed( rotB );
     alpha = 255;
     setCollision( 0 );
+    save();
 }
 
 DeadPlayer::~DeadPlayer()
@@ -63,4 +64,30 @@ Rect2< float > DeadPlayer::getBoundingBox() const
 bool DeadPlayer::isFinished() const
 {
     return alpha == 0;
+}
+
+void DeadPlayer::save()
+{
+    alt.alpha = alpha;
+    alt.posA = m2a->getPosition();
+    alt.speedA = m2a->getSpeed();
+    alt.rotA = m2a->getDrehung();
+    alt.rotSA = m2a->getDrehungSpeed();
+    alt.posB = m2b->getPosition();
+    alt.speedB = m2b->getSpeed();
+    alt.rotB = m2b->getDrehung();
+    alt.rotSB = m2b->getDrehungSpeed();
+}
+
+void DeadPlayer::load()
+{
+    alpha = alt.alpha;
+    m2a->setPosition( alt.posA );
+    m2a->setSpeed( alt.speedA );
+    m2a->setDrehung( alt.rotA );
+    m2a->setDrehungSpeed( alt.rotSA );
+    m2b->setPosition( alt.posB );
+    m2b->setSpeed( alt.speedB );
+    m2b->setDrehung( alt.rotB );
+    m2b->setDrehungSpeed( alt.rotSB );
 }

+ 15 - 0
Asteroids/Spiel/Spieler/DeadPlayer.h

@@ -10,6 +10,19 @@ private:
     Model2DObject *m2a;
     Model2DObject *m2b;
     double alpha;
+    struct SaveData
+    {
+        Vertex posA;
+        Vertex speedA;
+        float rotA;
+        float rotSA;
+        Vertex posB;
+        Vertex speedB;
+        float rotB;
+        float rotSB;
+        double alpha;
+    };
+    SaveData alt;
 
 public:
     DeadPlayer( Model2DData *mda, Model2DData *mdb, Vertex posa, Vertex posb, Vertex speedA, Vertex speedB, float curRotA, float curRotB, float rotA, float rotB, Textur2D *zTextur );
@@ -18,4 +31,6 @@ public:
     bool tick( const WeltInfo &info, double zeit ) override;
     Rect2< float > getBoundingBox() const override;
     bool isFinished() const;
+    void save();
+    void load();
 };