-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameEngine.cpp
More file actions
100 lines (80 loc) · 1.75 KB
/
GameEngine.cpp
File metadata and controls
100 lines (80 loc) · 1.75 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "GameEngine.h"
#include "GameState.h"
void CGameEngine::Init(const char* title, int width, int height, bool fullscreen)
{
if ( fullscreen ) {
//flags = SDL_FULLSCREEN;
}
window.create(sf::VideoMode(width, height), title);
window.setFramerateLimit(60);
m_fullscreen = fullscreen;
m_running = true;
clock.setSampleDepth(100);
printf("CGameEngine Init\n");
}
void CGameEngine::Cleanup()
{
// cleanup the all states
while ( !states.empty() ) {
states.back()->Cleanup();
states.pop_back();
}
// switch back to windowed mode so other
// programs won't get accidentally resized
if ( m_fullscreen ) {
//screen = SDL_SetVideoMode(640, 480, 0, 0);
}
printf("CGameEngine Cleanup\n");
// shutdown SDL
//SDL_Quit();
}
void CGameEngine::ChangeState(CGameState* state)
{
// cleanup the current state
if ( !states.empty() ) {
states.back()->Cleanup();
states.pop_back();
}
// store and init the new state
states.push_back(state);
states.back()->Init(this);
}
void CGameEngine::PushState(CGameState* state)
{
// pause current state
if ( !states.empty() ) {
states.back()->Pause();
}
// store and init the new state
states.push_back(state);
states.back()->Init(this);
}
void CGameEngine::PopState()
{
// cleanup the current state
if ( !states.empty() ) {
states.back()->Cleanup();
states.pop_back();
}
// resume previous state
if ( !states.empty() ) {
states.back()->Resume(this);
}
}
void CGameEngine::HandleEvents()
{
// let the state handle events
states.back()->HandleEvents(this);
}
void CGameEngine::Update()
{
clock.beginFrame();
// let the state update the game
states.back()->Update(this);
}
void CGameEngine::Draw()
{
// let the state draw the screen
states.back()->Draw(this);
clock.endFrame();
}