diff --git a/CMakeLists.txt b/CMakeLists.txt index 96e41a30..6fda39a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,7 +117,10 @@ set(SOURCES sources/System/IntroAnimation/IntroAnimationSystem.cpp sources/Runner/SplashScreenScene.cpp sources/Runner/TitleScreenScene.cpp + sources/Runner/MainMenuScene.cpp sources/Runner/GameScene.cpp + sources/Runner/PauseMenuScene.cpp + sources/Runner/SettingsMenuScene.cpp sources/Runner/CreditScene.cpp ) add_executable(bomberman diff --git a/sources/Runner/MainMenuScene.cpp b/sources/Runner/MainMenuScene.cpp new file mode 100644 index 00000000..3a515c1e --- /dev/null +++ b/sources/Runner/MainMenuScene.cpp @@ -0,0 +1,119 @@ + +#include +#include +#include "Runner.hpp" +#include +#include "Component/Music/MusicComponent.hpp" +#include "Component/Sound/SoundComponent.hpp" +#include "Component/Controllable/ControllableComponent.hpp" +#include "Component/Position/PositionComponent.hpp" +#include "Component/Keyboard/KeyboardComponent.hpp" +#include "Component/Renderer/Drawable2DComponent.hpp" +#include "Component/Button/ButtonComponent.hpp" +#include "Drawables/2D/Text.hpp" + +namespace RAY2D = RAY::Drawables::Drawables2D; + +namespace BBM +{ + std::shared_ptr Runner::loadMainMenuScene() + { + static const std::map sounds = { + {SoundComponent::JUMP, "assets/sounds/click.ogg"} + }; + auto scene = std::make_shared(); + + scene->addEntity("Control entity") + .addComponent() + .addComponent() + .addComponent("assets/musics/music_title.ogg") + .addComponent(sounds); + scene->addEntity("background") + .addComponent() + .addComponent("assets/plain_menu_background.png"); + scene->addEntity("logo") + .addComponent(1920 / 3, 180, 0) + .addComponent("assets/logo_small.png"); + auto &play = scene->addEntity("play button") + .addComponent(1920 / 2.5, 1080 - 540, 0) + .addComponent("assets/buttons/button_new_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"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_new_game_hovered.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + gameState.nextScene = BBM::GameState::SceneID::GameScene; + }); + auto &settings = scene->addEntity("settings button") + .addComponent(1920 / 2.5, 1080 - 360, 0) + .addComponent("assets/buttons/button_settings.png") + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_settings.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_settings_hovered.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + gameState.nextScene = BBM::GameState::SceneID::SettingsScene; + }); + auto &exit = scene->addEntity("exit button") + .addComponent(1920 / 2.5, 1080 - 180, 0) + .addComponent("assets/buttons/button_exit.png") + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_exit.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_exit_hovered.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &wal) + { + wal.shouldClose = true; + }); + auto &credits = scene->addEntity("credit button") + .addComponent(1920 - 100, 1080 - 30, 0) + .addComponent("Credits", 20, RAY::Vector2(), BLACK) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY2D::Text *text = dynamic_cast(entity.getComponent().drawable.get()); + + text->setColor(BLACK); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY2D::Text *text = dynamic_cast(entity.getComponent().drawable.get()); + + text->setColor(ORANGE); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &wal) + { + gameState.nextScene = BBM::GameState::SceneID::CreditScene; + }); + play.getComponent().setButtonLinks(nullptr, &settings); + settings.getComponent().setButtonLinks(&play, &exit); + exit.getComponent().setButtonLinks(&settings, &credits, nullptr, &credits); + credits.getComponent().setButtonLinks(&exit, nullptr, &exit); + return scene; + } +} \ No newline at end of file diff --git a/sources/Runner/PauseMenuScene.cpp b/sources/Runner/PauseMenuScene.cpp new file mode 100644 index 00000000..ed674e3a --- /dev/null +++ b/sources/Runner/PauseMenuScene.cpp @@ -0,0 +1,101 @@ + +#include +#include +#include "Runner.hpp" +#include +#include "Component/Music/MusicComponent.hpp" +#include "Component/Sound/SoundComponent.hpp" +#include "Component/Controllable/ControllableComponent.hpp" +#include "Component/Position/PositionComponent.hpp" +#include "Component/Keyboard/KeyboardComponent.hpp" +#include "Component/Renderer/Drawable2DComponent.hpp" +#include "Component/Button/ButtonComponent.hpp" +#include "Drawables/2D/Text.hpp" + +namespace RAY2D = RAY::Drawables::Drawables2D; + +namespace BBM +{ + std::shared_ptr Runner::loadPauseMenuScene() + { + static const std::map sounds = { + {SoundComponent::JUMP, "assets/sounds/click.ogg"} + }; + auto scene = std::make_shared(); + + scene->addEntity("Control entity") + .addComponent() + .addComponent() + .addComponent("assets/musics/music_player_select.ogg") + .addComponent(sounds); + scene->addEntity("background") + .addComponent() + .addComponent("assets/plain_menu_background.png"); + scene->addEntity("pause text") + .addComponent(1920 / 2.5, 180, 0) + .addComponent("PAUSE", 120, RAY::Vector2(), ORANGE); + auto &play = scene->addEntity("play button") + .addComponent(1920 / 6.5, 1080 - 360, 0) + .addComponent("assets/buttons/button_back.png") + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_back.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_back_hovered.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + gameState.nextScene = BBM::GameState::SceneID::GameScene; + }); + auto &settings = scene->addEntity("settings button") + .addComponent(1920 / 2.5, 1080 - 360, 0) + .addComponent("assets/buttons/button_settings.png") + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_settings.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_settings_hovered.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + gameState.nextScene = BBM::GameState::SceneID::SettingsScene; + }); + auto &exit = scene->addEntity("exit button") + .addComponent(1920 / 1.5, 1080 - 360, 0) + .addComponent("assets/buttons/button_exit.png") + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_exit.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_exit_hovered.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &wal) + { + gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; + }); + //needed material + //music + play.getComponent().setButtonLinks(nullptr, nullptr, nullptr, &settings); + settings.getComponent().setButtonLinks(nullptr, nullptr, &play, &exit); + exit.getComponent().setButtonLinks(nullptr, nullptr, &settings, nullptr); + return scene; + } +} \ No newline at end of file diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 4c18e18f..97a92ea9 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -11,16 +11,8 @@ #include #include "System/Keyboard/KeyboardSystem.hpp" #include "System/Controllable/ControllableSystem.hpp" -#include "Component/Movable/MovableComponent.hpp" -#include "Component/Controllable/ControllableComponent.hpp" -#include "Component/Keyboard/KeyboardComponent.hpp" #include "System/Gamepad/GamepadSystem.hpp" #include -#include "Component/Button/ButtonComponent.hpp" -#include -#include "Component/Renderer/CameraComponent.hpp" -#include "Component/Renderer/Drawable3DComponent.hpp" -#include "Component/Renderer/Drawable2DComponent.hpp" #include "Runner.hpp" #include "Models/GameState.hpp" #include @@ -29,22 +21,14 @@ #include #include #include -#include -#include #include #include #include -#include -#include -#include "Component/Animation/AnimationsComponent.hpp" #include "System/Animation/AnimationsSystem.hpp" -#include "Component/Shaders/ShaderComponent.hpp" #include "Map/Map.hpp" #include "System/MenuControllable/MenuControllableSystem.hpp" #include #include -#include "Component/Music/MusicComponent.hpp" -#include "Component/Sound/SoundComponent.hpp" #include "System/Sound/PlayerSoundManagerSystem.hpp" #include "System/Sound/MenuSoundManagerSystem.hpp" #include "System/Music/MusicSystem.hpp" @@ -108,383 +92,6 @@ namespace BBM .addSystem(window); } - std::shared_ptr Runner::loadMainMenuScene() - { - static const std::map sounds = { - {SoundComponent::JUMP, "assets/sounds/click.ogg"} - }; - auto scene = std::make_shared(); - - scene->addEntity("Control entity") - .addComponent() - .addComponent() - .addComponent("assets/musics/music_title.ogg") - .addComponent(sounds); - scene->addEntity("background") - .addComponent() - .addComponent("assets/plain_menu_background.png"); - scene->addEntity("logo") - .addComponent(1920 / 3, 180, 0) - .addComponent("assets/logo_small.png"); - auto &play = scene->addEntity("play button") - .addComponent(1920 / 2.5, 1080 - 540, 0) - .addComponent("assets/buttons/button_new_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"); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_new_game_hovered.png"); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - gameState.nextScene = BBM::GameState::SceneID::GameScene; - }); - auto &settings = scene->addEntity("settings button") - .addComponent(1920 / 2.5, 1080 - 360, 0) - .addComponent("assets/buttons/button_settings.png") - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_settings.png"); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_settings_hovered.png"); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - gameState.nextScene = BBM::GameState::SceneID::SettingsScene; - }); - auto &exit = scene->addEntity("exit button") - .addComponent(1920 / 2.5, 1080 - 180, 0) - .addComponent("assets/buttons/button_exit.png") - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_exit.png"); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_exit_hovered.png"); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &wal) - { - wal.shouldClose = true; - }); - auto &credits = scene->addEntity("credit button") - .addComponent(1920 - 100, 1080 - 30, 0) - .addComponent("Credits", 20, RAY::Vector2(), BLACK) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY2D::Text *text = dynamic_cast(entity.getComponent().drawable.get()); - - text->setColor(BLACK); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY2D::Text *text = dynamic_cast(entity.getComponent().drawable.get()); - - text->setColor(ORANGE); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &wal) - { - gameState.nextScene = BBM::GameState::SceneID::CreditScene; - }); - play.getComponent().setButtonLinks(nullptr, &settings); - settings.getComponent().setButtonLinks(&play, &exit); - exit.getComponent().setButtonLinks(&settings, &credits, nullptr, &credits); - credits.getComponent().setButtonLinks(&exit, nullptr, &exit); - return scene; - } - - std::shared_ptr Runner::loadPauseMenuScene() - { - static const std::map sounds = { - {SoundComponent::JUMP, "assets/sounds/click.ogg"} - }; - auto scene = std::make_shared(); - - scene->addEntity("Control entity") - .addComponent() - .addComponent() - .addComponent("assets/musics/music_player_select.ogg") - .addComponent(sounds); - scene->addEntity("background") - .addComponent() - .addComponent("assets/plain_menu_background.png"); - scene->addEntity("pause text") - .addComponent(1920 / 2.5, 180, 0) - .addComponent("PAUSE", 120, RAY::Vector2(), ORANGE); - auto &play = scene->addEntity("play button") - .addComponent(1920 / 6.5, 1080 - 360, 0) - .addComponent("assets/buttons/button_back.png") - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_back.png"); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_back_hovered.png"); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - gameState.nextScene = BBM::GameState::SceneID::GameScene; - }); - auto &settings = scene->addEntity("settings button") - .addComponent(1920 / 2.5, 1080 - 360, 0) - .addComponent("assets/buttons/button_settings.png") - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_settings.png"); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_settings_hovered.png"); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - gameState.nextScene = BBM::GameState::SceneID::SettingsScene; - }); - auto &exit = scene->addEntity("exit button") - .addComponent(1920 / 1.5, 1080 - 360, 0) - .addComponent("assets/buttons/button_exit.png") - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_exit.png"); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_exit_hovered.png"); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &wal) - { - gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; - }); - //needed material - //music - play.getComponent().setButtonLinks(nullptr, nullptr, nullptr, &settings); - settings.getComponent().setButtonLinks(nullptr, nullptr, &play, &exit); - exit.getComponent().setButtonLinks(nullptr, nullptr, &settings, nullptr); - return scene; - } - - std::shared_ptr Runner::loadSettingsMenuScene() - { - auto scene = std::make_shared(); - static const std::map sounds = { - {SoundComponent::JUMP, "assets/sounds/click.ogg"} - }; - - scene->addEntity("Control entity") - .addComponent() - .addComponent() - .addComponent("assets/musics/music_title.ogg") - .addComponent(sounds); - scene->addEntity("background") - .addComponent() - .addComponent("assets/plain_menu_background.png"); - scene->addEntity("logo") - .addComponent(1920 / 3, 180, 0) - .addComponent("assets/logo_small.png"); - auto &music = scene->addEntity("music text") - .addComponent(1920 / 2.5, 1080 - 540, 0) - .addComponent("Music Volume", 70, RAY::Vector2(), BLACK) - .addComponent() - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - entity.getComponent().drawable->setColor(BLACK); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - entity.getComponent().drawable->setColor(ORANGE); - }); - - auto &musicUp = scene->addEntity("music up button") - .addComponent(1920 / 1.5, 1080 - 540, 0) - .addComponent("assets/buttons/button_plus.png") - .addComponent("assets/musics/music_title.ogg") - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_plus.png"); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - auto &component = entity.getComponent(); - - component.turnUpVolume(); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_plus_hovered.png"); - }); - - auto &musicDown = scene->addEntity("music down button") - .addComponent(1920 / 3, 1080 - 540, 0) - .addComponent("assets/buttons/button_minus.png") - .addComponent("assets/musics/music_title.ogg") - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_minus.png"); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - auto &component = entity.getComponent(); - - component.turnDownVolume(); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_minus_hovered.png"); - }); - - auto &sound = scene->addEntity("sound text") - .addComponent(1920 / 2.5, 1080 - 360, 0) - .addComponent("Sound Volume", 70, RAY::Vector2(), BLACK) - .addComponent() - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - entity.getComponent().drawable->setColor(BLACK); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - entity.getComponent().drawable->setColor(ORANGE); - }); - - auto &soundUp = scene->addEntity("sound up button") - .addComponent(1920 / 1.5, 1080 - 360, 0) - .addComponent("assets/buttons/button_plus.png") - .addComponent(sounds) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - auto &component = entity.getComponent(); - - component.turnUpVolume(); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_plus.png"); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_plus_hovered.png"); - }); - - auto &soundDown = scene->addEntity("sound down button") - .addComponent(1920 / 3, 1080 - 360, 0) - .addComponent("assets/buttons/button_minus.png") - .addComponent(sounds) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_minus.png"); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - auto &component = entity.getComponent(); - - component.turnDownVolume(); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_minus_hovered.png"); - }); - - auto &debug = scene->addEntity("debug text") - .addComponent(1920 / 2.5, 1080 - 180, 0) - .addComponent("Debug Mode: Off", 70, RAY::Vector2(), BLACK) - .addComponent([](WAL::Entity &entity, WAL::Wal &wal) - { - RAY2D::Text *text = dynamic_cast(entity.getComponent().drawable.get()); - - if (text->getString().find("Off") != std::string::npos) { - text->setText("Debug Mode: On"); - wal.getSystem().setDebug(true); - } else { - text->setText("Debug Mode: Off"); - wal.getSystem().setDebug(false); - } - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - entity.getComponent().drawable->setColor(BLACK); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - entity.getComponent().drawable->setColor(ORANGE); - }); - auto &back = scene->addEntity("back to menu") - .addComponent(10, 1080 - 85, 0) - .addComponent("assets/buttons/button_back.png") - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_back.png"); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - - texture->use("assets/buttons/button_back_hovered.png"); - }); - //needed material - //music - //sound - - music.getComponent().setButtonLinks(nullptr, &sound, &musicDown, &musicUp); - musicDown.getComponent().setButtonLinks(&debug, &sound, nullptr, &music); - musicUp.getComponent().setButtonLinks(&debug, &sound, &music); - sound.getComponent().setButtonLinks(&music, &debug, &soundDown, &soundUp); - soundDown.getComponent().setButtonLinks(&music, &debug, nullptr, &sound); - soundUp.getComponent().setButtonLinks(&music, &debug, &sound); - debug.getComponent().setButtonLinks(&sound, &back, &back); - back.getComponent().setButtonLinks(&debug, nullptr, nullptr, &debug); - return scene; - } - void Runner::loadScenes() { gameState._loadedScenes[GameState::SceneID::MainMenuScene] = loadMainMenuScene(); diff --git a/sources/Runner/SettingsMenuScene.cpp b/sources/Runner/SettingsMenuScene.cpp new file mode 100644 index 00000000..4d409aab --- /dev/null +++ b/sources/Runner/SettingsMenuScene.cpp @@ -0,0 +1,212 @@ + +#include +#include +#include "Runner.hpp" +#include +#include "Component/Music/MusicComponent.hpp" +#include "Component/Sound/SoundComponent.hpp" +#include "Component/Controllable/ControllableComponent.hpp" +#include "Component/Position/PositionComponent.hpp" +#include "Component/Keyboard/KeyboardComponent.hpp" +#include "Component/Renderer/Drawable2DComponent.hpp" +#include "Component/Button/ButtonComponent.hpp" +#include "Drawables/2D/Text.hpp" +#include "System/Renderer/RenderSystem.hpp" + +namespace RAY2D = RAY::Drawables::Drawables2D; + +namespace BBM +{ + std::shared_ptr Runner::loadSettingsMenuScene() + { + auto scene = std::make_shared(); + static const std::map sounds = { + {SoundComponent::JUMP, "assets/sounds/click.ogg"} + }; + + scene->addEntity("Control entity") + .addComponent() + .addComponent() + .addComponent("assets/musics/music_title.ogg") + .addComponent(sounds); + scene->addEntity("background") + .addComponent() + .addComponent("assets/plain_menu_background.png"); + scene->addEntity("logo") + .addComponent(1920 / 3, 180, 0) + .addComponent("assets/logo_small.png"); + auto &music = scene->addEntity("music text") + .addComponent(1920 / 2.5, 1080 - 540, 0) + .addComponent("Music Volume", 70, RAY::Vector2(), BLACK) + .addComponent() + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + entity.getComponent().drawable->setColor(BLACK); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + entity.getComponent().drawable->setColor(ORANGE); + }); + + auto &musicUp = scene->addEntity("music up button") + .addComponent(1920 / 1.5, 1080 - 540, 0) + .addComponent("assets/buttons/button_plus.png") + .addComponent("assets/musics/music_title.ogg") + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_plus.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + auto &component = entity.getComponent(); + + component.turnUpVolume(); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_plus_hovered.png"); + }); + + auto &musicDown = scene->addEntity("music down button") + .addComponent(1920 / 3, 1080 - 540, 0) + .addComponent("assets/buttons/button_minus.png") + .addComponent("assets/musics/music_title.ogg") + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_minus.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + auto &component = entity.getComponent(); + + component.turnDownVolume(); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_minus_hovered.png"); + }); + + auto &sound = scene->addEntity("sound text") + .addComponent(1920 / 2.5, 1080 - 360, 0) + .addComponent("Sound Volume", 70, RAY::Vector2(), BLACK) + .addComponent() + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + entity.getComponent().drawable->setColor(BLACK); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + entity.getComponent().drawable->setColor(ORANGE); + }); + + auto &soundUp = scene->addEntity("sound up button") + .addComponent(1920 / 1.5, 1080 - 360, 0) + .addComponent("assets/buttons/button_plus.png") + .addComponent(sounds) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + auto &component = entity.getComponent(); + + component.turnUpVolume(); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_plus.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_plus_hovered.png"); + }); + + auto &soundDown = scene->addEntity("sound down button") + .addComponent(1920 / 3, 1080 - 360, 0) + .addComponent("assets/buttons/button_minus.png") + .addComponent(sounds) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_minus.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + auto &component = entity.getComponent(); + + component.turnDownVolume(); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_minus_hovered.png"); + }); + + auto &debug = scene->addEntity("debug text") + .addComponent(1920 / 2.5, 1080 - 180, 0) + .addComponent("Debug Mode: Off", 70, RAY::Vector2(), BLACK) + .addComponent([](WAL::Entity &entity, WAL::Wal &wal) + { + RAY2D::Text *text = dynamic_cast(entity.getComponent().drawable.get()); + + if (text->getString().find("Off") != std::string::npos) { + text->setText("Debug Mode: On"); + wal.getSystem().setDebug(true); + } else { + text->setText("Debug Mode: Off"); + wal.getSystem().setDebug(false); + } + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + entity.getComponent().drawable->setColor(BLACK); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + entity.getComponent().drawable->setColor(ORANGE); + }); + auto &back = scene->addEntity("back to menu") + .addComponent(10, 1080 - 85, 0) + .addComponent("assets/buttons/button_back.png") + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_back.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_back_hovered.png"); + }); + //needed material + //music + //sound + + music.getComponent().setButtonLinks(nullptr, &sound, &musicDown, &musicUp); + musicDown.getComponent().setButtonLinks(&debug, &sound, nullptr, &music); + musicUp.getComponent().setButtonLinks(&debug, &sound, &music); + sound.getComponent().setButtonLinks(&music, &debug, &soundDown, &soundUp); + soundDown.getComponent().setButtonLinks(&music, &debug, nullptr, &sound); + soundUp.getComponent().setButtonLinks(&music, &debug, &sound); + debug.getComponent().setButtonLinks(&sound, &back, &back); + back.getComponent().setButtonLinks(&debug, nullptr, nullptr, &debug); + return scene; + } +} \ No newline at end of file