state changing wrp complete, pause working correctly
authorPatrik Gornicz <Gornicz.P@gmail.com>
Wed, 20 Aug 2008 02:33:00 +0000 (22:33 -0400)
committerPatrik Gornicz <Gornicz.P@gmail.com>
Wed, 20 Aug 2008 02:33:00 +0000 (22:33 -0400)
src/GameStates/Paused.cpp
src/game.cpp

index ed97101..166ac2f 100644 (file)
@@ -47,14 +47,14 @@ void Paused::draw(bool on_top) const
 
 bool Paused::pushMe() const
 {
-    if (input::isPressed(SDLK_p))
+    if (input::wasPressed(SDLK_p))
         return true;
 
     return false;
 }
 bool Paused::popMe() const
 {
-    if (input::isPressed(SDLK_p))
+    if (input::wasPressed(SDLK_p))
         return true;
 
     return false;
index 95cd04d..3b7a34b 100644 (file)
@@ -41,6 +41,11 @@ Running* running;
 Paused* paused;
 CreatingPolygon* creating_Polygon;
 
+// true if the top state requested itself to be poped
+bool pop_State;
+// pointer to a state wishing to be added
+GameState* push_State;
+
 
 /// ***** Public Methods *****
 
@@ -50,6 +55,9 @@ void game::init()
     paused = new Paused();
     creating_Polygon = new CreatingPolygon();
 
+    pop_State = false;
+    push_State = NULL;
+
     // create starting entities
     creator::init();
 
@@ -75,13 +83,28 @@ void game::clean()
 
 void game::input()
 {
+    if(running->pushMe())
+        push_State = running;
+
+    if(paused->pushMe())
+        push_State = paused;
+
+    if(creating_Polygon->pushMe())
+        push_State = creating_Polygon;
+
+
     int last = active_States.size() -1;
     for( int i = 0;
          i <= last;
          i++ )
     {
         if( i == last )
-            active_States[i]->handleInput(true);
+        {
+            if(active_States[i]->popMe())
+                pop_State = true;
+            else
+                active_States[i]->handleInput(true);
+        }
         else
             active_States[i]->handleInput(false);
     }
@@ -89,6 +112,21 @@ void game::input()
 
 void game::update(float time_step)
 {
+    if(push_State != NULL)
+    {
+        // don't want to pop and push same state, pop wins arbitrary
+        if(!pop_State)
+            active_States.push_back(push_State);
+
+        push_State = NULL;
+    }
+
+    if(pop_State)
+    {
+        active_States.pop_back();
+        pop_State = false;
+    }
+
     int last = active_States.size() -1;
     for( int i = 0;
          i <= last;