-
Notifications
You must be signed in to change notification settings - Fork 5
/
GameStateManager.cpp
53 lines (42 loc) · 1.25 KB
/
GameStateManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "GameStateManager.h"
GameStateManager::GameStateManager() {
currentState = nullptr;
}
void GameStateManager::addState(GameState *state) {
states.push_back(state);
}
void GameStateManager::deleteState(GameState *state) {
if(state == currentState) // you can't delete the current state
std::cerr << "Cannot delete current state from state manager.\n";
else
for(int i = 0; i < states.size(); ++i)
if(states[i] == state)
states.erase(states.begin()+i);
}
void GameStateManager::setState(GameState *state) {
if(currentState != nullptr)
currentState->leave();
currentState = state;
currentState->enter();
}
void GameStateManager::update() {
currentState->update();
}
void GameStateManager::render() {
currentState->render();
}
void GameStateManager::changeSize(int w, int h) {
currentState->changeSize(w, h);
}
void GameStateManager::keyboardDown(unsigned char key, int x, int y) {
currentState->keyboardDown(key, x, y);
}
void GameStateManager::keyboardUp(unsigned char key, int x, int y) {
currentState->keyboardUp(key, x, y);
}
void GameStateManager::mousePress(int button, int state, int x, int y) {
currentState->mousePress(button, state, x, y);
}
void GameStateManager::mouseMove(int x, int y) {
currentState->mouseMove(x, y);
}