diff --git a/assets/buttons/button_resume_game.png b/assets/buttons/button_resume_game.png new file mode 100644 index 00000000..20cec8d2 Binary files /dev/null and b/assets/buttons/button_resume_game.png differ diff --git a/assets/buttons/button_resume_game_hovered.png b/assets/buttons/button_resume_game_hovered.png new file mode 100644 index 00000000..42719815 Binary files /dev/null and b/assets/buttons/button_resume_game_hovered.png differ diff --git a/assets/buttons/button_save.png b/assets/buttons/button_save.png new file mode 100644 index 00000000..0372a9b3 Binary files /dev/null and b/assets/buttons/button_save.png differ diff --git a/assets/buttons/button_save_hovered.png b/assets/buttons/button_save_hovered.png new file mode 100644 index 00000000..d66bc224 Binary files /dev/null and b/assets/buttons/button_save_hovered.png differ diff --git a/sources/Parser/ParserYaml.cpp b/sources/Parser/ParserYaml.cpp index 493a939d..38fea6c9 100644 --- a/sources/Parser/ParserYaml.cpp +++ b/sources/Parser/ParserYaml.cpp @@ -42,6 +42,7 @@ namespace BBM { std::vector ParserYAML::playerPosition = {}; std::vector ParserYAML::playerBombCount = {}; std::vector ParserYAML::playerExplosionRange = {}; + std::vector ParserYAML::playerSpeed = {}; std::vector ParserYAML::playerAssets = {}; std::string ParserYAML::_getBlockType(std::string blockName) @@ -86,15 +87,17 @@ namespace BBM { auto *position = entity.tryGetComponent(); auto *bombHolder = entity.tryGetComponent(); auto *model = entity.tryGetComponent(); + auto *controllable = entity.tryGetComponent(); auto name = entity.getName(); - if (!position || !bombHolder || !model) + if (!position || !bombHolder || !model || !controllable) return; std::replace(name.begin(), name.end(), ' ', '_'); _player << std::endl << " " << name << ":" << std::endl << " "; _player << "texture_path: " << dynamic_cast(model->drawable.get())->getTextureByMaterial(MAP_DIFFUSE).getResourcePath() << std::endl << " "; _player << "max_bomb: " << std::to_string(bombHolder->maxBombCount) << std::endl << " "; _player << "explosion_radius: " << std::to_string(bombHolder->explosionRadius) << std::endl << " "; + _player << "speed: " << std::to_string(controllable->speed) << std::endl << " "; _player << "position: [" << std::to_string(position->getX()) << " " << std::to_string(position->getY()) << " " << std::to_string(position->getZ()) << "]"; } @@ -162,6 +165,8 @@ namespace BBM { } else if (lines[index].find("texture_path") != std::string::npos && !name.empty()) { playerAssets.push_back(_parseAssets(lines[index])); tmpAssets = _parseAssets(lines[index]); + } else if (lines[index].find("speed") != std::string::npos && !name.empty()) { + playerSpeed.push_back(_parseSpeed(lines[index])); } else { if (!name.empty()) { break; @@ -366,6 +371,13 @@ namespace BBM { return (std::atof(line.substr(line.find(": ") + 2).c_str())); } + float ParserYAML::_parseSpeed(std::string &line) + { + if (line.find(": ") == std::string::npos || !_isFloat(line.substr(line.find(": ") + 2))) + throw (ParserError("Error with saved map: Couldn't parse speed.\n Loading default maps...")); + return (std::atof(line.substr(line.find(": ") + 2).c_str())); + } + MapGenerator::BlockType ParserYAML::_parseBlockType(std::string &blockType) { if (blockType.find(": ") == std::string::npos || !_isInteger(blockType.substr(blockType.find(": ") + 2))) diff --git a/sources/Parser/ParserYaml.hpp b/sources/Parser/ParserYaml.hpp index 9a29d564..2e41c176 100644 --- a/sources/Parser/ParserYaml.hpp +++ b/sources/Parser/ParserYaml.hpp @@ -47,6 +47,9 @@ namespace BBM { //!@brief return explosion radius parsed static float _parseExplosionRadius(std::string &line); //!@param line to parse + //!@brief return speed parsed + static float _parseSpeed(std::string &line); + //!@param line to parse //!@brief return vector3f of position parsed static Vector3f _parsePosition(std::string &line); //!@param blockType to parse @@ -97,8 +100,10 @@ namespace BBM { static std::vector playerPosition; //! @brief The amount of bomb a player had static std::vector playerBombCount; - //! @brief The explosion range per player + //! @brief The explosion range of a player static std::vector playerExplosionRange; + //! @brief The speed of a player + static std::vector playerSpeed; //! @brief The assets of the player static std::vector playerAssets; diff --git a/sources/Runner/MainMenuScene.cpp b/sources/Runner/MainMenuScene.cpp index f784e185..646a6389 100644 --- a/sources/Runner/MainMenuScene.cpp +++ b/sources/Runner/MainMenuScene.cpp @@ -36,7 +36,7 @@ namespace BBM .addComponent(1920 / 3, 180, 0) .addComponent("assets/logo_small.png"); auto &play = scene->addEntity("play button") - .addComponent(1920 / 2.5, 1080 - 720, 0) + .addComponent(1920 / 2.5, 1080 - 650, 0) .addComponent("assets/buttons/button_new_game.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { @@ -56,18 +56,18 @@ namespace BBM }); auto &resume = scene->addEntity("resume button") .addComponent(1920 / 2.5, 1080 - 540, 0) - .addComponent("assets/buttons/button_new_game.png") + .addComponent("assets/buttons/button_resume_game.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - texture->use("assets/buttons/button_new_game.png"); + texture->use("assets/buttons/button_resume_game.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - texture->use("assets/buttons/button_new_game_hovered.png"); + texture->use("assets/buttons/button_resume_game_hovered.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { @@ -88,7 +88,7 @@ namespace BBM Runner::gameState._loadedScenes[GameState::SceneID::GameScene] = scene; }); auto &settings = scene->addEntity("settings button") - .addComponent(1920 / 2.5, 1080 - 360, 0) + .addComponent(1920 / 2.5, 1080 - 430, 0) .addComponent("assets/buttons/button_settings.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { @@ -107,7 +107,7 @@ namespace BBM gameState.nextScene = BBM::GameState::SceneID::SettingsScene; }); auto &exit = scene->addEntity("exit button") - .addComponent(1920 / 2.5, 1080 - 180, 0) + .addComponent(1920 / 2.5, 1080 - 320, 0) .addComponent("assets/buttons/button_exit.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { diff --git a/sources/Runner/PauseMenuScene.cpp b/sources/Runner/PauseMenuScene.cpp index cf7d66c6..294dd860 100644 --- a/sources/Runner/PauseMenuScene.cpp +++ b/sources/Runner/PauseMenuScene.cpp @@ -3,6 +3,7 @@ #include #include "Runner.hpp" #include +#include #include "Component/Music/MusicComponent.hpp" #include "Component/Sound/SoundComponent.hpp" #include "Component/Controllable/ControllableComponent.hpp" @@ -52,6 +53,26 @@ namespace BBM { gameState.nextScene = BBM::GameState::SceneID::GameScene; }); + auto &save = scene->addEntity("save & quit button") + .addComponent(1920 / 2.5, 1080 - 240, 0) + .addComponent("assets/buttons/button_save.png") + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_save.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_save_hovered.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + ParserYAML::save(Runner::gameState._loadedScenes[GameState::SceneID::GameScene]); + gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; + }); auto &settings = scene->addEntity("settings button") .addComponent(1920 / 2.5, 1080 - 360, 0) .addComponent("assets/buttons/button_settings.png") @@ -72,7 +93,7 @@ namespace BBM gameState.nextScene = BBM::GameState::SceneID::SettingsScene; }); auto &exit = scene->addEntity("exit button") - .addComponent(1920 / 1.5, 1080 - 360, 0) + .addComponent(1920 / 1.55, 1080 - 360, 0) .addComponent("assets/buttons/button_exit.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { @@ -92,9 +113,10 @@ namespace BBM }); //needed material //music - play.getComponent().setButtonLinks(nullptr, nullptr, nullptr, &settings); - settings.getComponent().setButtonLinks(nullptr, nullptr, &play, &exit); - exit.getComponent().setButtonLinks(nullptr, nullptr, &settings, nullptr); + save.getComponent().setButtonLinks(&play); + play.getComponent().setButtonLinks(nullptr, &save, nullptr, &settings); + settings.getComponent().setButtonLinks(nullptr, &save, &play, &exit); + exit.getComponent().setButtonLinks(nullptr, &save, &settings, nullptr); return scene; } } \ No newline at end of file diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index e5a65e37..2a395fbd 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -53,7 +53,6 @@ namespace BBM if (gameState.currentScene == GameState::SceneID::GameScene || gameState.currentScene == GameState::SceneID::SplashScreen) { for (auto &[_, component]: engine.getScene()->view()) { if (component.pause && gameState.currentScene == GameState::SceneID::GameScene) { - ParserYAML::save(engine.getScene()); gameState.nextScene = GameState::SceneID::PauseMenuScene; break; } else if (gameState.currentScene == GameState::SceneID::SplashScreen && component.jump) { diff --git a/sources/System/Lobby/LobbySystem.cpp b/sources/System/Lobby/LobbySystem.cpp index 2d4a3ed7..463e68ab 100644 --- a/sources/System/Lobby/LobbySystem.cpp +++ b/sources/System/Lobby/LobbySystem.cpp @@ -188,12 +188,14 @@ namespace BBM auto *position = player.tryGetComponent(); auto *bombHolder = player.tryGetComponent(); auto *model = player.tryGetComponent(); - if (position && bombHolder && model) { + auto *controllable = player.tryGetComponent(); + if (position && bombHolder && model && controllable) { dynamic_cast(model->drawable.get())->setTextureToMaterial(MAP_DIFFUSE, ParserYAML::playerAssets[countPlayer]); position->position = ParserYAML::playerPosition[countPlayer]; bombHolder->explosionRadius = ParserYAML::playerExplosionRange[countPlayer]; bombHolder->maxBombCount = ParserYAML::playerBombCount[countPlayer]; + controllable->speed = ParserYAML::playerSpeed[countPlayer]; } addController(player, lobby.layout); countPlayer++;