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