-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cpp
More file actions
65 lines (52 loc) · 1.77 KB
/
Game.cpp
File metadata and controls
65 lines (52 loc) · 1.77 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
#include "Game.hpp"
#include "Portada.hpp"
Game::Game() : _window(sf::VideoMode::getDesktopMode(),"TOPKeK", sf::Style::Fullscreen) {
Portada portada;
portada.display(&_window, "Resources/Textures/portada.png");
portada.display(&_window, "Resources/Textures/BEST.png");
_window.setFramerateLimit(FRAMERATE);
Resources::load();
_currentScene = nullptr;
_lastScene = nullptr;
SoundManager::load();
//SoundManager::setLoop(true, "overWorld");
}
Game::~Game() {
for (auto it = _scenes.begin(); it != _scenes.end(); ++it) {
delete it->second;
}
}
void Game::start() {
loadScenes();
_currentScene = (*_scenes.find("Menu")).second;
while (_currentScene != nullptr) {
_currentScene->run();
}
exit(0);
}
void Game::changeScene(std::string nextSceneName, int nPlayers) { // This will be called by any scene when something trigers to change to anothe scene
std::string sceneName = nextSceneName;
std::cout << "You want to change to: " << sceneName << std::endl;
if (_currentScene != nullptr) {
_lastScene = _currentScene;
_currentScene->killScene();
}
auto it = _scenes.find(sceneName);
if (it == _scenes.end()) {
std::cout << "The selected scene does not exist: " << sceneName << std::endl;
exit(EXIT_FAILURE);
}
Scene* aux = (*it).second;
std::cout << "Changing to scene " << sceneName << std::endl;
_currentScene = aux;
if (nextSceneName == "Jump") _currentScene->init(nPlayers);
else _currentScene->init();
}
void Game::loadScenes() {
_scenes.insert(std::make_pair(
"Menu",
new SceneMenu(this,&_window)));
_scenes.insert(std::make_pair(
"Jump",
new SceneRace(this,&_window)));
}