-
Notifications
You must be signed in to change notification settings - Fork 1
/
Game.cpp
82 lines (66 loc) · 2.6 KB
/
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "Game.hpp"
#include "SceneGame.hpp"
Game::Game() : _window(sf::VideoMode::getFullscreenModes()[0],"dhfgsadhkf", sf::Style::Close | sf::Style::Fullscreen) {
_window.setFramerateLimit(FRAMERATE);
_window.setKeyRepeatEnabled(false);
_lastScene = nullptr;
_currentScene = nullptr;
initInput();
Resources::load();
SoundManager::load();
SoundManager::setGlobalSoundVolumen(100.0f);
SoundManager::setGlobalMusicVolumen(100.0f);
SoundManager::playMusic("music");
SoundManager::setLoop(true, "music");
}
Game::~Game() {
for (auto it = _scenes.begin(); it != _scenes.end(); ++it) {
delete it->second;
}
}
void Game::start() {
loadScenes();
changeScene("test");
while (_currentScene != nullptr) {
_currentScene->run();
}
exit(0);
}
void Game::changeScene(std::string sceneName) {
auto it = _scenes.find(sceneName);
if (it == _scenes.end()) {
if(sceneName == "previous" && _lastScene != nullptr){
_currentScene = _lastScene;
_lastScene = nullptr;
} else {
std::cout << "The selected scene does not exist: " << sceneName << std::endl;
exit(EXIT_FAILURE);
}
} else {
if (_currentScene != nullptr) {
_lastScene = _currentScene;
_currentScene->killScene();
}
_currentScene = (*it).second;
_currentScene->init();
}
}
void Game::loadScenes() {
_scenes.insert(std::make_pair("test", new SceneTest(this, &_window, "test2")));
_scenes.insert(std::make_pair("test2", new SceneGame(this, &_window)));
_scenes.insert(std::make_pair("EndRed", new SceneTest(this, &_window, "previous", "First Player Won! Press a key to restart")));
_scenes.insert(std::make_pair("EndGreen", new SceneTest(this, &_window, "previous", "Second Player Won! Press any key to restart")));
}
void Game::loadScene(std::string sceneName) {}
void Game::initInput() {
InputManager::bind(InputAction::firstUp, sf::Keyboard::W);
InputManager::bind(InputAction::firstDown, sf::Keyboard::S);
InputManager::bind(InputAction::firstLeft, sf::Keyboard::A);
InputManager::bind(InputAction::firstRight, sf::Keyboard::D);
InputManager::bind(InputAction::firstAction, sf::Keyboard::Space);
InputManager::bind(InputAction::secondUp, sf::Keyboard::Up);
InputManager::bind(InputAction::secondDown, sf::Keyboard::Down);
InputManager::bind(InputAction::secondLeft, sf::Keyboard::Left);
InputManager::bind(InputAction::secondRight, sf::Keyboard::Right);
InputManager::bind(InputAction::secondAction, sf::Keyboard::RShift);
}