added GPL copyrights
[physics.git] / src / game.cpp
CommitLineData
e68f847b
PG
1/*
2 * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
a483ed75
PG
18#include "game.h"
19#include "debug.h"
20
054d658f
PG
21#include <vector>
22using std::vector;
23
054d658f 24#include "entityCreator.h"
33b8c69b 25#include "effectManager.h"
054d658f 26
ad9f1fb6
PG
27#include "GameStates/GameState.h"
28#include "GameStates/Running.h"
29#include "GameStates/Paused.h"
30#include "GameStates/CreatingPolygon.h"
31
68b2316d 32
ad9f1fb6
PG
33/// ***** Private Variables *****
34
35// The stack of active game states
36vector<GameState*> active_States;
37
38// Pointers to each possible game state
39// inserted and removed from the active_States
40Running* running;
41Paused* paused;
42CreatingPolygon* creating_Polygon;
43
44
45/// ***** Public Methods *****
68b2316d
PG
46
47void game::init()
ad9f1fb6
PG
48{
49 running = new Running();
50 paused = new Paused();
51 creating_Polygon = new CreatingPolygon();
054d658f
PG
52
53 // create starting entities
054d658f
PG
54 creator::init();
55
a483ed75
PG
56 active_States.push_back(running);
57
33b8c69b
PG
58 effect::init();
59
054d658f
PG
60#ifdef DEBUGGING
61 cout << "World Created" << endl;
62#endif
ad9f1fb6
PG
63}
64
68b2316d 65void game::clean()
ad9f1fb6 66{
33b8c69b
PG
67 effect::clean();
68
054d658f
PG
69 creator::clean();
70
ad9f1fb6
PG
71 delete creating_Polygon;
72 delete paused;
73 delete running;
74}
75
68b2316d 76void game::input()
ad9f1fb6 77{
a483ed75 78 int last = active_States.size() -1;
ad9f1fb6 79 for( int i = 0;
a483ed75 80 i <= last;
ad9f1fb6
PG
81 i++ )
82 {
a483ed75 83 if( i == last )
ad9f1fb6
PG
84 active_States[i]->handleInput(true);
85 else
86 active_States[i]->handleInput(false);
87 }
ad9f1fb6
PG
88}
89
68b2316d 90void game::update(float time_step)
ad9f1fb6 91{
a483ed75 92 int last = active_States.size() -1;
ad9f1fb6 93 for( int i = 0;
a483ed75 94 i <= last;
ad9f1fb6
PG
95 i++ )
96 {
a483ed75 97 if( i == last )
ad9f1fb6
PG
98 active_States[i]->update(time_step, true);
99 else
100 active_States[i]->update(time_step, false);
101 }
102}
103
68b2316d 104void game::draw()
ad9f1fb6 105{
a483ed75 106 int last = active_States.size() -1;
ad9f1fb6 107 for( int i = 0;
a483ed75 108 i <= last;
ad9f1fb6
PG
109 i++ )
110 {
a483ed75 111 if( i == last )
ad9f1fb6
PG
112 active_States[i]->draw(true);
113 else
114 active_States[i]->draw(false);
115 }
116}