| 1 | #include "game.h" |
| 2 | #include "debug.h" |
| 3 | |
| 4 | #include <vector> |
| 5 | using std::vector; |
| 6 | |
| 7 | #include "entityCreator.h" |
| 8 | #include "effectManager.h" |
| 9 | |
| 10 | #include "GameStates/GameState.h" |
| 11 | #include "GameStates/Running.h" |
| 12 | #include "GameStates/Paused.h" |
| 13 | #include "GameStates/CreatingPolygon.h" |
| 14 | |
| 15 | |
| 16 | /// ***** Private Variables ***** |
| 17 | |
| 18 | // The stack of active game states |
| 19 | vector<GameState*> active_States; |
| 20 | |
| 21 | // Pointers to each possible game state |
| 22 | // inserted and removed from the active_States |
| 23 | Running* running; |
| 24 | Paused* paused; |
| 25 | CreatingPolygon* creating_Polygon; |
| 26 | |
| 27 | |
| 28 | /// ***** Public Methods ***** |
| 29 | |
| 30 | void game::init() |
| 31 | { |
| 32 | running = new Running(); |
| 33 | paused = new Paused(); |
| 34 | creating_Polygon = new CreatingPolygon(); |
| 35 | |
| 36 | // create starting entities |
| 37 | creator::init(); |
| 38 | |
| 39 | active_States.push_back(running); |
| 40 | |
| 41 | effect::init(); |
| 42 | |
| 43 | #ifdef DEBUGGING |
| 44 | cout << "World Created" << endl; |
| 45 | #endif |
| 46 | } |
| 47 | |
| 48 | void game::clean() |
| 49 | { |
| 50 | effect::clean(); |
| 51 | |
| 52 | creator::clean(); |
| 53 | |
| 54 | delete creating_Polygon; |
| 55 | delete paused; |
| 56 | delete running; |
| 57 | } |
| 58 | |
| 59 | void game::input() |
| 60 | { |
| 61 | int last = active_States.size() -1; |
| 62 | for( int i = 0; |
| 63 | i <= last; |
| 64 | i++ ) |
| 65 | { |
| 66 | if( i == last ) |
| 67 | active_States[i]->handleInput(true); |
| 68 | else |
| 69 | active_States[i]->handleInput(false); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | void game::update(float time_step) |
| 74 | { |
| 75 | int last = active_States.size() -1; |
| 76 | for( int i = 0; |
| 77 | i <= last; |
| 78 | i++ ) |
| 79 | { |
| 80 | if( i == last ) |
| 81 | active_States[i]->update(time_step, true); |
| 82 | else |
| 83 | active_States[i]->update(time_step, false); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | void game::draw() |
| 88 | { |
| 89 | int last = active_States.size() -1; |
| 90 | for( int i = 0; |
| 91 | i <= last; |
| 92 | i++ ) |
| 93 | { |
| 94 | if( i == last ) |
| 95 | active_States[i]->draw(true); |
| 96 | else |
| 97 | active_States[i]->draw(false); |
| 98 | } |
| 99 | } |