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