-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameengine.cpp
65 lines (54 loc) · 982 Bytes
/
gameengine.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
54
55
56
57
58
59
60
61
62
63
64
65
#include <SFML/Graphics.hpp>
#include "gameengine.h"
#include "gamestate.h"
void GameEngine::Init(const char* titre, int largeur, int hauteur)
{
m_fenetre = new sf::RenderWindow(sf::VideoMode(largeur, hauteur), titre);
}
void GameEngine::Cleanup()
{
delete m_fenetre;
}
void GameEngine::ChangeState(GameState* state)
{
if(!states.empty())
{
states.back()->Cleanup();
states.pop_back();
}
states.push_back(state);
states.back()->Init();
}
void GameEngine::PushState(GameState* state)
{
if(!states.empty())
{
states.back()->Pause();
}
states.push_back(state);
states.back()->Init();
}
void GameEngine::PopState()
{
if (!states.empty())
{
states.back()->Cleanup();
states.pop_back();
}
if (!states.empty())
{
states.back()->Resume();
}
}
void GameEngine::HandleEvents()
{
states.back()->HandleEvents(this);
}
void GameEngine::Update()
{
states.back()->Update(this);
}
void GameEngine::Draw()
{
states.back()->Draw(this);
}