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