X-Git-Url: http://gitweb.pgornicz.com/gitweb.cgi?a=blobdiff_plain;f=src%2Fgame.cpp;h=3b7a34b8c785f8c2c5f0a1f04257e96d694b7d43;hb=033c553524d4a0407f6fabd0bcebf1d460519cf5;hp=32a9e0b968c51c5d8c2b00a537efd337162888d5;hpb=054d658f7ba8742cc1bc0a2f16d0f7e4a1499516;p=physics.git diff --git a/src/game.cpp b/src/game.cpp index 32a9e0b..3b7a34b 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1,16 +1,35 @@ -#include -using std::vector; +/* + * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include "game.h" - #include "debug.h" + +#include +using std::vector; + #include "entityCreator.h" +#include "effectManager.h" #include "GameStates/GameState.h" #include "GameStates/Running.h" #include "GameStates/Paused.h" #include "GameStates/CreatingPolygon.h" + /// ***** Private Variables ***** // The stack of active game states @@ -22,25 +41,39 @@ 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 ***** -void gameInit() + +void game::init() { running = new Running(); paused = new Paused(); creating_Polygon = new CreatingPolygon(); - // create starting entities + pop_State = false; + push_State = NULL; + // create starting entities creator::init(); + active_States.push_back(running); + + effect::init(); + #ifdef DEBUGGING cout << "World Created" << endl; #endif } -void gameClean() +void game::clean() { + effect::clean(); + creator::clean(); delete creating_Polygon; @@ -48,43 +81,72 @@ void gameClean() delete running; } -void gameInput() +void game::input() { - int size = active_States.size(); + 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 < size; + i <= last; i++ ) { - if( i-1 == size ) - active_States[i]->handleInput(true); + if( i == last ) + { + if(active_States[i]->popMe()) + pop_State = true; + else + active_States[i]->handleInput(true); + } else active_States[i]->handleInput(false); } - } -void gameUpdate(float time_step) +void game::update(float time_step) { - int size = active_States.size(); + 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 < size; + i <= last; i++ ) { - if( i-1 == size ) + if( i == last ) active_States[i]->update(time_step, true); else active_States[i]->update(time_step, false); } } -void gameDraw() +void game::draw() { - int size = active_States.size(); + int last = active_States.size() -1; for( int i = 0; - i < size; + i <= last; i++ ) { - if( i-1 == size ) + if( i == last ) active_States[i]->draw(true); else active_States[i]->draw(false);