-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainEngine.cpp
70 lines (65 loc) · 2.02 KB
/
MainEngine.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
66
67
68
69
70
//
// Created by ptdave on 05/12/15.
//
#include "MainEngine.h"
#include "scenes/GameScene.h"
#include "config.h"
using namespace std;
MainEngine::MainEngine() : Game("game",game_DEFAULT_WIDTH,game_DEFAULT_HEIGHT,game_DEFAULT_BPP){
state = MainEngine::UNINITIALIZED;
m_producedBy = std::shared_ptr<Scene>(new ptDaveScene);
m_mainMenu = std::shared_ptr<Scene>(new MainMenu);
m_game = std::shared_ptr<Scene>(new GameScene);
}
void MainEngine::onUpdate(const sf::Time &time) {
switch(state) {
case UNINITIALIZED:
state = PRODUCEDBY;
setScene(m_producedBy);
m_producedBy->init(this->getSize());
break;
case PRODUCEDBY:
if(m_producedBy->isFinished()) {
state = MAINMENU;
setScene(m_mainMenu);
m_mainMenu->init(this->getSize());
}
break;
case MAINMENU:
if(m_mainMenu->isFinished()) {
switch(m_mainMenu->finishState()) {
case MainMenu::EXIT:
quit();
break;
case MainMenu::NEWGAME:
setScene(m_game);
state = GAME;
m_game->init(this->getSize());
break;
case MainMenu::OPTIONS:
break;
}
}
break;
}
}
void MainEngine::onEvent(const sf::Event &event) {
if(event.type == sf::Event::KeyPressed) {
keys[event.key.code] = true;
}
if(event.type == sf::Event::KeyReleased) {
if(keys[event.key.code]) {
if(event.key.code == sf::Keyboard::F1) {
toggleFPS();
cout << (getShowFPS() ? "true": "false") << endl;
}
if(event.key.code == sf::Keyboard::Escape) {
quit();
}
}
keys[event.key.code] = false;
}
if(hasScene()) {
sendEventToScene(event);
}
}