ebf2ba77f22319f9fc1bbfa74aa635c95c5d7809
[physics.git] / src / game.cpp
1 #include "game.h"
2 #include "debug.h"
3
4 #include <vector>
5 using std::vector;
6
7 #include "entityCreator.h"
8
9 #include "GameStates/GameState.h"
10 #include "GameStates/Running.h"
11 #include "GameStates/Paused.h"
12 #include "GameStates/CreatingPolygon.h"
13
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();
32
33     // create starting entities
34     creator::init();
35
36     active_States.push_back(running);
37
38 #ifdef DEBUGGING
39     cout << "World Created" << endl;
40 #endif
41 }
42
43 void gameClean()
44 {
45     creator::clean();
46
47     delete creating_Polygon;
48     delete paused;
49     delete running;
50 }
51
52 void gameInput()
53 {
54     int last = active_States.size() -1;
55     for( int i = 0;
56          i <= last;
57          i++ )
58     {
59         if( i == last )
60             active_States[i]->handleInput(true);
61         else
62             active_States[i]->handleInput(false);
63     }
64 }
65
66 void gameUpdate(float time_step)
67 {
68     int last = active_States.size() -1;
69     for( int i = 0;
70          i <= last;
71          i++ )
72     {
73         if( i == last )
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 {
82     int last = active_States.size() -1;
83     for( int i = 0;
84          i <= last;
85          i++ )
86     {
87         if( i == last )
88             active_States[i]->draw(true);
89         else
90             active_States[i]->draw(false);
91     }
92 }