-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cpp
62 lines (45 loc) · 951 Bytes
/
Game.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
#include <stack>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <TGUI/TGUI.hpp>
#define THEME_CONFIG_FILE "TGUI/widgets/Black.conf"
#include "Game.h"
#include "GameStart.h"
void Game::ChangeState(GameState* state){
if (states.empty()){
PopState();
}
PushState(state);
}
void Game::PushState(GameState* state){
states.push(state);
}
void Game::PopState(){
delete states.top();
states.pop();
}
GameState* Game::TopState(){
if (states.empty()){
return nullptr; }
return this->states.top();
}
void Game::GameLoop(){
sf::Clock clock;
while (window.isOpen())
{
sf::Time elapsed = clock.restart();
float t = elapsed.asSeconds();
if (TopState() == nullptr){
continue;
}
TopState()->HandleInput();
//TopState()->Update(t);
window.clear();
TopState()->Draw(t);
window.display();
}
}
Game::Game(){
window.create(sf::VideoMode(1024, 768), "Dungeon Crawl");
window.setFramerateLimit(60);
}