Skip to content

Commit

Permalink
feat(endgame): added button at the end of the game
Browse files Browse the repository at this point in the history
  • Loading branch information
victorpalle committed Jun 19, 2022
1 parent a93b088 commit a172301
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
25 changes: 23 additions & 2 deletions project/Conf/Scenes/EndGameScene/button.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,29 @@
"2-Continue": {
"type": "button",
"nbFrame": 3,
"position": [1770, 900, 0],
"position": [940, 900, 0],
"audio": "Ressources/buttons/click_sound.ogg",
"texture": "Ressources/buttons/next_button.png"
"texture": "Ressources/buttons/little_button.png",
"text": {
"font": "Ressources/fonts/squarefont/Square.ttf",
"text": "Main Menu",
"color": [255, 255, 255, 255],
"fontSize": 40,
"position": [80, 40, 0]
}
},
"3-Restart": {
"type": "button",
"nbFrame": 3,
"position": [1470, 900, 0],
"texture": "Ressources/buttons/little_button.png",
"audio": "Ressources/buttons/click_sound.ogg",
"text": {
"font": "Ressources/fonts/squarefont/Square.ttf",
"text": "Battle Again",
"color": [255, 255, 255, 255],
"fontSize": 40,
"position": [80, 40, 0]
}
}
}
2 changes: 1 addition & 1 deletion project/Source/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void Core::loadMenuScenes()
updateLoadingScreen(".");
_menuScenes.emplace(Scene::Scenes::SELECT_PLAYER, std::make_shared<Scene::SelectPlayerScene>(_settings, _gameSettings, _parallax, std::bind(&Scene::GameScene::applyGameParams, gameScene)));
updateLoadingScreen("");
_menuScenes.emplace(Scene::Scenes::END_GAME, std::make_shared<Scene::EndGameScene>(_settings, _gameSettings, _parallax));
_menuScenes.emplace(Scene::Scenes::END_GAME, std::make_shared<Scene::EndGameScene>(_settings, _gameSettings, _parallax, std::bind(&Scene::GameScene::applyGameParams, gameScene)));
updateLoadingScreen(".");
_menuScenes.emplace(Scene::Scenes::SELECT_MAP, std::make_shared<Scene::SelectMapScene>(_settings, _gameSettings, _parallax));
updateLoadingScreen("..");
Expand Down
10 changes: 9 additions & 1 deletion project/Source/Scenes/GameScenes/EndGameScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@ void Scene::EndGameScene::goToMainMenu()
_nextScene = Scene::Scenes::MAIN_MENU;
}

Scene::EndGameScene::EndGameScene(std::shared_ptr<Settings> settings, std::shared_ptr<GameSettings> gameSettings, std::vector<std::unique_ptr<Object::Image>> &parallax) : AScene(settings), _gameSettings(gameSettings), _parallax(parallax)
void Scene::EndGameScene::restartGame()
{
_restartGameCallBack();
_nextScene = Scene::Scenes::GAME;
}

Scene::EndGameScene::EndGameScene(std::shared_ptr<Settings> settings, std::shared_ptr<GameSettings> gameSettings, std::vector<std::unique_ptr<Object::Image>> &parallax, std::function<void(void)> restartCallBack) : AScene(settings), _gameSettings(gameSettings), _parallax(parallax)
{
_buttons = loadObjects<Object::Button>("Conf/Scenes/EndGameScene/button.json");
_buttons.at(0)->setCallBack(std::bind(&Scene::EndGameScene::goToMainMenu, this));
_buttons.at(1)->setCallBack(std::bind(&Scene::EndGameScene::restartGame, this));
_texts = loadObjects<Object::Text>("Conf/Scenes/EndGameScene/text.json");
_images = loadObjects<Object::Image>("Conf/Scenes/EndGameScene/image.json");
_winner = loadObjects<Object::Image>("Conf/Scenes/EndGameScene/winner.json");
_nextScene = Scene::Scenes::END_GAME;
_restartGameCallBack = restartCallBack;
}

Scene::Scenes Scene::EndGameScene::handleEvent()
Expand Down
10 changes: 8 additions & 2 deletions project/Source/Scenes/GameScenes/EndGameScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,22 @@ namespace Scene {
* @param settings Shared pointer to Settings class
* @param gameSettings Shared pointer to Game Settings class
*/
EndGameScene(std::shared_ptr<Settings> settings, std::shared_ptr<GameSettings> gameSettings, std::vector<std::unique_ptr<Object::Image>> &parallax);
EndGameScene(std::shared_ptr<Settings> settings, std::shared_ptr<GameSettings> gameSettings, std::vector<std::unique_ptr<Object::Image>> &parallax, std::function<void(void)> _restartCallBack);
~EndGameScene();

Scenes handleEvent() override;
void draw () override;

/**
* @brief Call back function executed when next button is pressed to set next scene to main menu scene
*/
*/
void goToMainMenu();

/**
* @brief Call back function executed to restart the game
*/
void restartGame();

void drawPlayerNameAndScore(Object::PLAYER_ORDER player, std::size_t score, std::size_t nbText);
void drawScore();

Expand All @@ -46,6 +51,7 @@ namespace Scene {
std::vector<std::unique_ptr<Object::Image>> _winner;
std::shared_ptr<GameSettings> _gameSettings;
int _winnerId;
std::function<void(void)> _restartGameCallBack;
};
}

Expand Down

0 comments on commit a172301

Please sign in to comment.