diff --git a/.gitignore b/.gitignore index f93eff30..4ea2a783 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .idea cmake-build-debug +cmake-build-release ./bomberman .vscode build/* diff --git a/CMakeLists.txt b/CMakeLists.txt index 38fa4806..951854b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -176,6 +176,8 @@ set(SOURCES sources/Component/Color/ColorComponent.cpp sources/Component/Stat/StatComponent.cpp sources/Component/Stat/StatComponent.hpp + sources/Component/Shaders/Items/AlphaCtxShaderComponent.cpp + sources/Component/Shaders/Items/AlphaCtxShaderComponent.hpp ) add_executable(bomberman diff --git a/assets/shaders/explosion.vs b/assets/shaders/explosion.vs index 26dd04b1..9e1e1fde 100644 --- a/assets/shaders/explosion.vs +++ b/assets/shaders/explosion.vs @@ -104,7 +104,7 @@ varying vec3 fragNormal; void main() { // Send vertex attributes to fragment shader - fragPosition = vertexPosition + vertexPosition * vec3(cnoise(vec3(vertexNormal + vec3(frame))) * 0.5); + fragPosition = vertexPosition + vertexPosition * vec3(cnoise(vec3(vertexNormal + center + vec3(frame))) * 0.5); fragColor = vertexColor; fragNormal = vertexNormal; fragTexCoord = vertexTexCoord; diff --git a/lib/Ray/sources/Shaders/Shaders.cpp b/lib/Ray/sources/Shaders/Shaders.cpp index 0def3c96..811fe34a 100644 --- a/lib/Ray/sources/Shaders/Shaders.cpp +++ b/lib/Ray/sources/Shaders/Shaders.cpp @@ -6,6 +6,7 @@ #include #include "Exceptions/RayError.hpp" +#include "Vector/Vector3.hpp" namespace RAY { @@ -38,6 +39,7 @@ namespace RAY SetShaderValue(*this->_rayLibShader, this->_shaderIndexVars[varName], &value, SHADER_UNIFORM_FLOAT); } + void Shader::setShaderUniformVar(const std::string &varName, int value) { if (this->_shaderIndexVars.find(varName) == this->_shaderIndexVars.end()) { @@ -60,4 +62,18 @@ namespace RAY { EndShaderMode(); } + + void Shader::setShaderUniformVar(const std::string &varName, const RAY::Vector3 &vector) + { + if (this->_shaderIndexVars.find(varName) == this->_shaderIndexVars.end()) { + int varShaderIndex = GetShaderLocation(*this->_rayLibShader, varName.c_str()); + + if (varShaderIndex < 0) { + throw Exception::WrongInputError("The loaded shader doesn't have a variable called: " + varName); + } + this->_shaderIndexVars[varName] = varShaderIndex; + } + SetShaderValue(*this->_rayLibShader, this->_shaderIndexVars[varName], &vector, SHADER_UNIFORM_VEC3); + } + } \ No newline at end of file diff --git a/lib/Ray/sources/Shaders/Shaders.hpp b/lib/Ray/sources/Shaders/Shaders.hpp index 20231ea7..a4616670 100644 --- a/lib/Ray/sources/Shaders/Shaders.hpp +++ b/lib/Ray/sources/Shaders/Shaders.hpp @@ -9,6 +9,7 @@ #include #include #include "Utils/Cache.hpp" +#include "Vector/Vector3.hpp" namespace RAY { @@ -46,6 +47,8 @@ namespace RAY //! @note Throw if the var is not found void setShaderUniformVar(const std::string &varName, int value); + void setShaderUniformVar(const std::string &varName, const RAY::Vector3 &vector); + void setLocation(::ShaderLocationIndex, const std::string &name); //! @brief ctor if no vertexfile in needed set it to nullptr diff --git a/sources/Component/Controllable/ControllableComponent.hpp b/sources/Component/Controllable/ControllableComponent.hpp index c2446c83..66904b20 100644 --- a/sources/Component/Controllable/ControllableComponent.hpp +++ b/sources/Component/Controllable/ControllableComponent.hpp @@ -34,9 +34,9 @@ namespace BBM //! @brief The X and Z abscis of the movement. Vector2f move; - //! @brief input value to select - bool select = false; - //! @brief input value for bomb + //! @brief input value for secondary inputs. + bool secondary = false; + //! @brief input value for bomb and selection bool bomb = false; //! @brief input value for pause bool pause = false; @@ -44,6 +44,8 @@ namespace BBM float speed = .15f; //! @brief The layout used for this controllable. Layout layout = NONE; + //! @brief True if buttons should be triggered every frame where the key is down, false if the button should only be triggered once the key is released. + bool fastClick = false; //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; diff --git a/sources/Component/Gamepad/GamepadComponent.hpp b/sources/Component/Gamepad/GamepadComponent.hpp index 696926ce..9796b991 100644 --- a/sources/Component/Gamepad/GamepadComponent.hpp +++ b/sources/Component/Gamepad/GamepadComponent.hpp @@ -22,9 +22,9 @@ namespace BBM int _ID; public: //! @brief jump key - Button keyJump = GAMEPAD_BUTTON_RIGHT_FACE_DOWN; + Button keySecondary = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT; //! @brief bomb key - Button keyBomb = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT; + Button keyBomb = GAMEPAD_BUTTON_RIGHT_FACE_DOWN; //! @brief pause key Button keyPause = GAMEPAD_BUTTON_MIDDLE; //! @brief move right key diff --git a/sources/Component/Keyboard/KeyboardComponent.cpp b/sources/Component/Keyboard/KeyboardComponent.cpp index 632300be..60acae13 100644 --- a/sources/Component/Keyboard/KeyboardComponent.cpp +++ b/sources/Component/Keyboard/KeyboardComponent.cpp @@ -16,16 +16,16 @@ namespace BBM this->keyDown = KEY_S; this->keyLeft = KEY_A; this->keyRight = KEY_D; - this->keyJump = KEY_SPACE; - this->keyBomb = KEY_E; + this->keyBomb = KEY_SPACE; + this->keySecondary = KEY_LEFT_CONTROL; this->keyPause = KEY_ESCAPE; } else { this->keyUp = KEY_UP; this->keyDown = KEY_DOWN; this->keyLeft = KEY_LEFT; this->keyRight = KEY_RIGHT; - this->keyJump = KEY_RIGHT_CONTROL; - this->keyBomb = KEY_ENTER; + this->keyBomb = KEY_RIGHT_CONTROL; + this->keySecondary = KEY_RIGHT_SHIFT; this->keyPause = KEY_BACKSPACE; } } diff --git a/sources/Component/Keyboard/KeyboardComponent.hpp b/sources/Component/Keyboard/KeyboardComponent.hpp index d7608ed5..c809ab44 100644 --- a/sources/Component/Keyboard/KeyboardComponent.hpp +++ b/sources/Component/Keyboard/KeyboardComponent.hpp @@ -18,7 +18,7 @@ namespace BBM { public: //! @brief jump key - Key keyJump = KEY_SPACE; + Key keySecondary = KEY_SPACE; //! @brief bomb key Key keyBomb = KEY_E; //! @brief pause key diff --git a/sources/Component/Shaders/Items/AlphaCtxShaderComponent.cpp b/sources/Component/Shaders/Items/AlphaCtxShaderComponent.cpp new file mode 100644 index 00000000..49634922 --- /dev/null +++ b/sources/Component/Shaders/Items/AlphaCtxShaderComponent.cpp @@ -0,0 +1,20 @@ +// +// Created by cbihan on 18/06/2021. +// + +#include "AlphaCtxShaderComponent.hpp" + + +namespace BBM +{ + + AlphaVarShaderComponent::AlphaVarShaderComponent(WAL::Entity &entity) : + WAL::Component(entity) + { + } + + WAL::Component *AlphaVarShaderComponent::clone(WAL::Entity &entity) const + { + return new AlphaVarShaderComponent(this->_entity); + } +} \ No newline at end of file diff --git a/sources/Component/Shaders/Items/AlphaCtxShaderComponent.hpp b/sources/Component/Shaders/Items/AlphaCtxShaderComponent.hpp new file mode 100644 index 00000000..5408d091 --- /dev/null +++ b/sources/Component/Shaders/Items/AlphaCtxShaderComponent.hpp @@ -0,0 +1,51 @@ +// +// Created by cbihan on 18/06/2021. +// + +#pragma once + +#include +#include + +using namespace std::chrono_literals; + +namespace BBM +{ + class AlphaVarShaderComponent : public WAL::Component + { + public: + //! @brief Transparency + float alpha = 1; + + //! @brief minimum transparency + float minAlpha = 0.2; + //! @brief maximum transparency + float maxAlpha = 1; + //! @brief inital step value + float initalStepValue = 0.04; + //! @brief how fast the alpha will vary + float step = 0.04; + //! @brief if the alpha should increase or decrease + float balance = -1; + + //! @brief The clock to use + std::chrono::nanoseconds clock = 0ns; + + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief ctor + explicit AlphaVarShaderComponent(WAL::Entity &entity); + + //! @brief Default copy ctor + AlphaVarShaderComponent(const AlphaVarShaderComponent &) = default; + + //! @brief Default dtor + ~AlphaVarShaderComponent() override = default; + + //! @brief Default assignment operator + AlphaVarShaderComponent &operator=(const AlphaVarShaderComponent &) = delete; + }; + +} \ No newline at end of file diff --git a/sources/Component/Timer/TimerComponent.hpp b/sources/Component/Timer/TimerComponent.hpp index 9a6ce3ff..ccbb2260 100644 --- a/sources/Component/Timer/TimerComponent.hpp +++ b/sources/Component/Timer/TimerComponent.hpp @@ -15,6 +15,9 @@ namespace BBM class TimerComponent : public WAL::Component { public: + //! @brief Is the ticking of this component disabled? + bool disabled = false; + //! @brief The callback to call when the timer ring. WAL::Callback callback; //! @brief The ring delay of this timer component. diff --git a/sources/Items/Bonus.cpp b/sources/Items/Bonus.cpp index 6a579d43..c34691bb 100644 --- a/sources/Items/Bonus.cpp +++ b/sources/Items/Bonus.cpp @@ -58,6 +58,7 @@ namespace BBM { if (!playerBonus) return; playerBonus->nextNoClipRate = playerBonus->noClipBonusRate; + playerBonus->isNoClipOn = true; const_cast(bonus).scheduleDeletion(); } diff --git a/sources/Models/GameState.hpp b/sources/Models/GameState.hpp index b3d506be..a87f3c95 100644 --- a/sources/Models/GameState.hpp +++ b/sources/Models/GameState.hpp @@ -31,6 +31,9 @@ namespace BBM }; + //! @brief The scene before the actual one. Used for back buttons. + SceneID previousScene = SplashScreen; + //! @brief The currently loaded scene SceneID currentScene = SplashScreen; @@ -38,6 +41,6 @@ namespace BBM SceneID nextScene = SplashScreen; //! @brief The list of loaded scenes. - std::unordered_map> _loadedScenes = {}; + std::unordered_map> loadedScenes = {}; }; } \ No newline at end of file diff --git a/sources/Runner/GameScene.cpp b/sources/Runner/GameScene.cpp index 42ce18cf..0446d082 100644 --- a/sources/Runner/GameScene.cpp +++ b/sources/Runner/GameScene.cpp @@ -16,7 +16,9 @@ #include "Component/BombHolder/BombHolderComponent.hpp" #include "Component/Tag/TagComponent.hpp" #include "Component/Renderer/Drawable3DComponent.hpp" +#include "Component/Shaders/Items/AlphaCtxShaderComponent.hpp" #include +#include "Component/Shaders/ShaderComponent.hpp" #include "Component/Gravity/GravityComponent.hpp" #include "Component/BumperTimer/BumperTimerComponent.hpp" #include "Component/Timer/TimerComponent.hpp" @@ -67,6 +69,44 @@ namespace BBM .addComponent("assets/player/player.iqm", 3) .addComponent(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75}) .addComponent() + .addComponent() + .addComponent("assets/shaders/alpha.fs", "", [](WAL::Entity &myEntity, WAL::Wal &, std::chrono::nanoseconds dtime) { + auto &ctx = myEntity.getComponent(); + + ctx.clock += dtime; + if (duration_cast(ctx.clock).count() <= 10) + return; + ctx.clock = 0ns; + auto &bonus = myEntity.getComponent(); + auto &shader = myEntity.getComponent(); + + if (!bonus.isNoClipOn) { + ctx.alpha = ctx.maxAlpha; + shader.shader.setShaderUniformVar("alpha", ctx.alpha); + return; + } + + auto nbMilliSec = duration_cast(bonus.nextNoClipRate).count(); + + if (nbMilliSec > 1500) { + ctx.step = ctx.initalStepValue; + } else if (nbMilliSec > 1000) { + ctx.step = 0.15; + } else if (nbMilliSec > 200) { + ctx.step = 0.30; + } else { + ctx.step = 0.5; + } + ctx.alpha += static_cast(ctx.step * ctx.balance); + + if (ctx.alpha <= ctx.minAlpha) { + ctx.balance = 1; + } + if (ctx.alpha >= ctx.maxAlpha) { + ctx.balance = -1; + } + shader.shader.setShaderUniformVar("alpha", ctx.alpha); + }, true) .addComponent(soundPath) .addComponent("assets/musics/music_battle.ogg") .addComponent() @@ -80,7 +120,7 @@ namespace BBM if (entity.hasComponent()) return; entity.getComponent().disabled = true; - entity.addComponent(1s, [](WAL::Entity &ent, WAL::Wal &wal) { + entity.addComponent(1s, [](WAL::Entity &ent, WAL::Wal &) { ent.scheduleDeletion(); }); }); diff --git a/sources/Runner/HowToPlayScene.cpp b/sources/Runner/HowToPlayScene.cpp index 62f549f1..a6082ace 100644 --- a/sources/Runner/HowToPlayScene.cpp +++ b/sources/Runner/HowToPlayScene.cpp @@ -37,16 +37,16 @@ namespace BBM .addComponent("How To Play?", 120, RAY::Vector2(), ORANGE); scene->addEntity("select text") .addComponent(1920 / 8, 1080 / 3, 0) - .addComponent("Select:", 60, RAY::Vector2(), ORANGE); + .addComponent("Select/Drop Bomb:", 60, RAY::Vector2(), ORANGE); scene->addEntity("select") .addComponent(1920 / 7, 1080 / 2.5, 0) - .addComponent("Space/A Button", 35, RAY::Vector2(), BLACK); + .addComponent("Space/Left CTRL/A Button", 35, RAY::Vector2(), BLACK); scene->addEntity("change skin text") .addComponent(1920 / 8, 1080 / 2, 0) - .addComponent("Change Skin/Drop Bomb:", 60, RAY::Vector2(), ORANGE); + .addComponent("Change Skin:", 60, RAY::Vector2(), ORANGE); scene->addEntity("change skin") .addComponent(1920 / 7, 1080 / 1.75, 0) - .addComponent("E/B Button", 35, RAY::Vector2(), BLACK); + .addComponent("Left ctrl/Right shift/B Button", 35, RAY::Vector2(), BLACK); scene->addEntity("move text") .addComponent(1920 / 1.75, 1080 / 3, 0) .addComponent("Move:", 60, RAY::Vector2(), ORANGE); @@ -58,7 +58,7 @@ namespace BBM .addComponent("Back/Pause:", 60, RAY::Vector2(), ORANGE); scene->addEntity("back") .addComponent(1920 / 1.75, 1080 / 1.75, 0) - .addComponent("Esc / Controller's Home button:", 35, RAY::Vector2(), BLACK); + .addComponent("Esc/Backspace/Controller's Home button:", 35, RAY::Vector2(), BLACK); scene->addEntity("back to menu") .addComponent(10, 1080 - 85, 0) .addComponent("assets/buttons/button_back.png") diff --git a/sources/Runner/LobbyScene.cpp b/sources/Runner/LobbyScene.cpp index 677360eb..92f54565 100644 --- a/sources/Runner/LobbyScene.cpp +++ b/sources/Runner/LobbyScene.cpp @@ -16,7 +16,6 @@ #include #include #include -#include "System/Sound/PlayerSoundManagerSystem.hpp" #include "System/Music/MusicSystem.hpp" #include "System/Lobby/LobbySystem.hpp" #include "Component/Lobby/LobbyComponent.hpp" @@ -82,19 +81,20 @@ namespace BBM auto &back = scene->addEntity("back to menu") .addComponent(10, 1080 - 85, 0) .addComponent("assets/buttons/button_back.png") - .addComponent([](WAL::Entity &entity, WAL::Wal &) + .addComponent([](WAL::Entity &, WAL::Wal &wal) { + wal.getSystem().unloadLobby(); gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + auto *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()); + auto *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_back_hovered.png"); }); @@ -117,32 +117,8 @@ namespace BBM texture->use("assets/buttons/button_htp_hovered.png"); }); - auto &lavaOption = scene->addEntity("lava option text") - .addComponent(1920 / 6, 1.85 * 1080 / 3 - 50, 0) - .addComponent("Lava: 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("Lava: On"); - //do - } else { - text->setText("Lava: Off"); - //do - } - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - entity.getComponent().drawable->setColor(BLACK); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - entity.getComponent().drawable->setColor(ORANGE); - }); - auto &heightOption = scene->addEntity("Height option text") - .addComponent(1920 / 6, 2.1 * 1080 / 3 - 50, 0) + .addComponent(1920 / 6, 2 * 1080 / 3 - 50, 0) .addComponent("2nd Level: Off", 70, RAY::Vector2(), BLACK) .addComponent([](WAL::Entity &entity, WAL::Wal &wal) { @@ -217,12 +193,11 @@ namespace BBM scene->addEntity("camera") .addComponent(-5, 0, -5) .addComponent(Vector3f(8, 0, 8)); - play.getComponent().setButtonLinks(&lavaOption, &back, &back, &howToPlay); + play.getComponent().setButtonLinks(&heightOption, &back, &back, &howToPlay); howToPlay.getComponent().setButtonLinks(&play, nullptr, &play); back.getComponent().setButtonLinks(&play, nullptr, nullptr, &play); - lavaOption.getComponent().setButtonLinks(nullptr, &heightOption, nullptr, &aiMore); - heightOption.getComponent().setButtonLinks(&lavaOption, &play, nullptr, &aiLess); - aiMore.getComponent().setButtonLinks(nullptr, &aiLess, &lavaOption, nullptr); + heightOption.getComponent().setButtonLinks(nullptr, &play, nullptr, &aiLess); + aiMore.getComponent().setButtonLinks(nullptr, &aiLess, &heightOption, nullptr); aiLess.getComponent().setButtonLinks(&aiMore, &play, &heightOption, nullptr); return scene; } diff --git a/sources/Runner/PauseMenuScene.cpp b/sources/Runner/PauseMenuScene.cpp index e5531f6e..263c2c1a 100644 --- a/sources/Runner/PauseMenuScene.cpp +++ b/sources/Runner/PauseMenuScene.cpp @@ -3,11 +3,14 @@ #include #include "Runner.hpp" #include +#include +#include "Component/Health/HealthComponent.hpp" +#include "Component/Timer/TimerComponent.hpp" +#include "Component/Tag/TagComponent.hpp" #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" @@ -41,18 +44,39 @@ namespace BBM .addComponent("assets/buttons/button_back.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + auto *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()); + auto *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_back_hovered.png"); }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) + .addComponent([](WAL::Entity &, WAL::Wal &) { + auto &gameScene = gameState.loadedScenes[BBM::GameState::SceneID::GameScene]; + for (auto &[entity, controller, _] : gameScene->view()) { + controller.disabled = true; + controller.pause = false; + controller.bomb = false; + } + for (auto &[_, timer] : gameScene->view()) + timer.disabled = true; + gameScene->scheduleNewEntity("Restart timer") + .addComponent(std::chrono::seconds(3), [gameScene](WAL::Entity &entity, WAL::Wal &) { + for (auto &view : gameScene->view()) { + if (view.get().getHealthPoint() > 0) + view.get().disabled = false; + } + for (auto &view : gameScene->view()) + view.get().disabled = false; + entity.scheduleDeletion(); + }) + .addComponent(1920 / 2 - 2 * 30, 1080 / 2, 0) + .addComponent>() + .addComponent("", 60, RAY::Vector2(), ORANGE); gameState.nextScene = BBM::GameState::SceneID::GameScene; }); auto &settings = scene->addEntity("settings button") @@ -60,17 +84,17 @@ namespace BBM .addComponent("assets/buttons/button_settings.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + auto *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()); + auto *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_settings_hovered.png"); }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) + .addComponent([](WAL::Entity &, WAL::Wal &) { gameState.nextScene = BBM::GameState::SceneID::SettingsScene; }); @@ -79,18 +103,19 @@ namespace BBM .addComponent("assets/buttons/button_exit.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + auto *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()); + auto *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_exit_hovered.png"); }) - .addComponent([](WAL::Entity &entity, WAL::Wal &wal) + .addComponent([](WAL::Entity &, WAL::Wal &wal) { + wal.getSystem().hasEnded = false; gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; }); //needed material diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 46d02511..19019a33 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -55,21 +55,27 @@ namespace BBM engine.shouldClose = true; if (gameState.currentScene == GameState::SceneID::GameScene) { for (auto &[_, component]: engine.getScene()->view()) { + component.fastClick = true; if (component.pause && gameState.currentScene == GameState::SceneID::GameScene) { gameState.nextScene = GameState::SceneID::PauseMenuScene; break; } } - if (gameState.nextScene != GameState::SceneID::GameScene) - engine.getSystem().hasEnded = false; } if (gameState.nextScene == gameState.currentScene) return; - if (gameState.nextScene == GameState::SceneID::ScoreScene) - gameState._loadedScenes[GameState::SceneID::ScoreScene] = Runner::loadScoreScene(*engine.getScene()); + if (gameState.previousScene == GameState::SceneID::GameScene) { + for (auto &[_, component]: engine.getScene()->view()) { + component.fastClick = false; + } + } + if (gameState.nextScene == GameState::SceneID::ScoreScene) { + gameState.loadedScenes[GameState::SceneID::ScoreScene] = Runner::loadScoreScene(*engine.getScene()); + } RAY::Window::getInstance().setVisibleCursor(gameState.nextScene != GameState::SceneID::GameScene); - gameState._loadedScenes[gameState.currentScene] = engine.getScene(); - engine.changeScene(gameState._loadedScenes[gameState.nextScene]); + gameState.loadedScenes[gameState.currentScene] = engine.getScene(); + engine.changeScene(gameState.loadedScenes[gameState.nextScene]); + gameState.previousScene = gameState.currentScene; gameState.currentScene = gameState.nextScene; } @@ -100,9 +106,9 @@ namespace BBM .addSystem() .addSystem() .addSystem() - .addSystem() .addSystem() .addSystem() + .addSystem() .addSystem(); } @@ -139,14 +145,14 @@ namespace BBM void Runner::loadScenes() { - gameState._loadedScenes[GameState::SceneID::MainMenuScene] = loadMainMenuScene(); - gameState._loadedScenes[GameState::SceneID::SettingsScene] = loadSettingsMenuScene(); - gameState._loadedScenes[GameState::SceneID::PauseMenuScene] = loadPauseMenuScene(); - gameState._loadedScenes[GameState::SceneID::TitleScreenScene] = loadTitleScreenScene(); - gameState._loadedScenes[GameState::SceneID::CreditScene] = loadCreditScene(); - gameState._loadedScenes[GameState::SceneID::SplashScreen] = loadSplashScreenScene(); - gameState._loadedScenes[GameState::SceneID::LobbyScene] = loadLobbyScene(); - gameState._loadedScenes[GameState::SceneID::HowToPlayScene] = loadHowToPlayScene(); + gameState.loadedScenes[GameState::SceneID::MainMenuScene] = loadMainMenuScene(); + gameState.loadedScenes[GameState::SceneID::SettingsScene] = loadSettingsMenuScene(); + gameState.loadedScenes[GameState::SceneID::PauseMenuScene] = loadPauseMenuScene(); + gameState.loadedScenes[GameState::SceneID::TitleScreenScene] = loadTitleScreenScene(); + gameState.loadedScenes[GameState::SceneID::CreditScene] = loadCreditScene(); + gameState.loadedScenes[GameState::SceneID::SplashScreen] = loadSplashScreenScene(); + gameState.loadedScenes[GameState::SceneID::LobbyScene] = loadLobbyScene(); + gameState.loadedScenes[GameState::SceneID::HowToPlayScene] = loadHowToPlayScene(); } int Runner::run() @@ -156,7 +162,7 @@ namespace BBM Runner::addSystems(wal); Runner::enableRaylib(wal); Runner::loadScenes(); - wal.changeScene(Runner::gameState._loadedScenes[GameState::SceneID::SplashScreen]); + wal.changeScene(Runner::gameState.loadedScenes[GameState::SceneID::SplashScreen]); wal.run(Runner::updateState, Runner::gameState); return 0; } diff --git a/sources/Runner/ScoreScene.cpp b/sources/Runner/ScoreScene.cpp index ce79f962..53416e07 100644 --- a/sources/Runner/ScoreScene.cpp +++ b/sources/Runner/ScoreScene.cpp @@ -35,11 +35,12 @@ namespace BBM "1st", "2nd", "3rd", "4th" }; - for (WAL::Entity &entity : gameScene.view()) + for (WAL::Entity &entity: gameScene.view()) players.emplace_back(entity); std::sort(players.begin(), players.end(), [](WAL::Entity &entityA, WAL::Entity &entityB) { return entityA.getComponent().aliveTime > entityB.getComponent().aliveTime; }); + auto bestTime = players.front().get().getComponent().aliveTime; int playerID = 0; for (auto &entity : players) { @@ -59,7 +60,7 @@ namespace BBM } addMenuControl(*scene, sounds); - scene->addEntity("Audio ressources") + scene->addEntity("Audio resources") .addComponent("assets/musics/music_result.ogg") .addComponent(sounds); scene->addEntity("background") @@ -74,19 +75,23 @@ namespace BBM scene->addEntity("scene title text") .addComponent(1920 / 2.37, 250, 0) .addComponent("CONGRATS", 50, RAY::Vector2(), ORANGE); - for (size_t i = 0; i < players.size(); i++) { + for (std::size_t i = 0; i < players.size(); i++) { + std::size_t place = i; + if (players[i].get().getComponent().aliveTime == bestTime) + place = 0; + scene->addEntity("player tile") .addComponent(224 * (i + 1) + 200 * i, 1080 / 2.5, 0) .addComponent(RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), - RAY::Vector2(200, 200), tilesColor[i]); + RAY::Vector2(200, 200), tilesColor[place]); scene->addEntity("player rank name") .addComponent(224 * (i + 1) + 200 * i, 1080 / 2.75, 0) - .addComponent(rankName[i], 30, + .addComponent(rankName[place], 30, RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), - tilesColor[i]); + tilesColor[place]); scene->addEntity("player") .addComponent(224 * (i + 1) + 200 * i, 1080 / 2.5, 0) - .addComponent(playersIconPath[i]); + .addComponent(playersIconPath[place]); } auto &play = scene->addEntity("play button") .addComponent(1920 / 2.5, 1080 - 180, 0) @@ -108,17 +113,15 @@ namespace BBM auto &back = scene->addEntity("back to main menu") .addComponent(10, 1080 - 85, 0) .addComponent("assets/buttons/button_back.png") - .addComponent([](WAL::Entity &entity, WAL::Wal &) { + .addComponent([](WAL::Entity &, WAL::Wal &) { gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - + auto *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()); - + auto *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_back_hovered.png"); }); back.getComponent().setButtonLinks(&play, nullptr, nullptr, &play); diff --git a/sources/Runner/SettingsMenuScene.cpp b/sources/Runner/SettingsMenuScene.cpp index 35a587bb..4e5848de 100644 --- a/sources/Runner/SettingsMenuScene.cpp +++ b/sources/Runner/SettingsMenuScene.cpp @@ -97,18 +97,18 @@ namespace BBM texture->use("assets/buttons/button_minus_hovered.png"); }); - auto &musicLevel = scene->addEntity("music level text") + scene->addEntity("music level text") .addComponent(1920 / 2.5, 1080 - 100 - 460, 0) .addComponent(RAY::Vector2(), RAY::Vector2(30, 10), BLACK) .addComponent([audio](Drawable2DComponent &drawble) { - const MusicComponent *music = audio.tryGetComponent(); + const MusicComponent *musicCmp = audio.tryGetComponent(); - if (!music) + if (!musicCmp) return; RAY2D::Rectangle *rect = dynamic_cast(drawble.drawable.get()); if (!rect) return; - rect->setWidth((13 * 36.5) * music->volume); + rect->setWidth((13 * 36.5) * musicCmp->volume); }); auto &sound = scene->addEntity("sound text") @@ -172,18 +172,18 @@ namespace BBM texture->use("assets/buttons/button_minus_hovered.png"); }); - auto &soundLevel = scene->addEntity("sound level text") + scene->addEntity("sound level text") .addComponent(1920 / 2.5, 1080 - 100 - 280, 0) .addComponent(RAY::Vector2(), RAY::Vector2(30, 10), BLACK) - .addComponent([audio](Drawable2DComponent &drawble) { - const SoundComponent *sound = audio.tryGetComponent(); + .addComponent([audio](Drawable2DComponent &drawable) { + const auto *soundCmp = audio.tryGetComponent(); - if (!sound) + if (!soundCmp) return; - RAY2D::Rectangle *rect = dynamic_cast(drawble.drawable.get()); + auto *rect = dynamic_cast(drawable.drawable.get()); if (!rect) return; - rect->setWidth((13 * 36.5) * sound->volume); + rect->setWidth((13 * 36.5) * soundCmp->volume); }); auto &debug = scene->addEntity("debug text") @@ -191,7 +191,7 @@ namespace BBM .addComponent("Debug Mode: Off", 70, RAY::Vector2(), BLACK) .addComponent([](WAL::Entity &entity, WAL::Wal &wal) { - RAY2D::Text *text = dynamic_cast(entity.getComponent().drawable.get()); + auto *text = dynamic_cast(entity.getComponent().drawable.get()); if (text->getString().find("Off") != std::string::npos) { text->setText("Debug Mode: On"); @@ -239,7 +239,7 @@ namespace BBM .addComponent("assets/buttons/button_back.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { - gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; + gameState.nextScene = gameState.previousScene; }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { diff --git a/sources/System/BombHolder/BombHolderSystem.cpp b/sources/System/BombHolder/BombHolderSystem.cpp index f2a2b398..9474e2a5 100644 --- a/sources/System/BombHolder/BombHolderSystem.cpp +++ b/sources/System/BombHolder/BombHolderSystem.cpp @@ -53,6 +53,7 @@ namespace BBM .addComponent("assets/shaders/explosion.fs", "assets/shaders/explosion.vs", [](WAL::Entity &entity, WAL::Wal &, std::chrono::nanoseconds dtime) { auto &ctx = entity.getComponent(); auto &shader = entity.getComponent(); + auto &pos = entity.getComponent(); ctx.clock += dtime; if (duration_cast(ctx.clock).count() <= 10) @@ -69,7 +70,8 @@ namespace BBM shader.shader.setShaderUniformVar("frame", ctx.frameCounter); shader.shader.setShaderUniformVar("alpha", ctx.alpha); shader.shader.setShaderUniformVar("radius", ctx.explosionRadius); - }) + shader.shader.setShaderUniformVar("center", pos.position); + }, true) .addComponent(500ms, [](WAL::Entity &explosion, WAL::Wal &) { explosion.scheduleDeletion(); }) diff --git a/sources/System/EndCondition/EndConditionSystem.cpp b/sources/System/EndCondition/EndConditionSystem.cpp index 93ea2003..3a413d71 100644 --- a/sources/System/EndCondition/EndConditionSystem.cpp +++ b/sources/System/EndCondition/EndConditionSystem.cpp @@ -1,6 +1,7 @@ #include "EndConditionSystem.hpp" #include +#include #include "Runner/Runner.hpp" #include "Component/Score/ScoreComponent.hpp" @@ -23,6 +24,7 @@ namespace BBM if (alivePlayersCount <= 1) { endConditionRate -= dtime; if (endConditionRate <= 0ns) { + this->_wal.getSystem().hasEnded = false; Runner::gameState.nextScene = Runner::gameState.ScoreScene; endConditionRate = 500ms; } diff --git a/sources/System/Gamepad/GamepadSystem.cpp b/sources/System/Gamepad/GamepadSystem.cpp index 036e4623..f59f87dc 100644 --- a/sources/System/Gamepad/GamepadSystem.cpp +++ b/sources/System/Gamepad/GamepadSystem.cpp @@ -27,13 +27,13 @@ namespace BBM Gamepad gamepad(gamepadComponent.getID()); const std::map keyPressedMap = { - {gamepadComponent.keyJump, controllable.select}, - {gamepadComponent.keyBomb, controllable.bomb}, - {gamepadComponent.keyPause, controllable.pause} + {gamepadComponent.keySecondary, controllable.secondary}, + {gamepadComponent.keyBomb, controllable.bomb}, + {gamepadComponent.keyPause, controllable.pause} }; for (auto key : keyPressedMap) - key.second = gamepad.isDown(key.first); + key.second = controllable.fastClick ? gamepad.isDown(key.first) : gamepad.isPressed(key.first); controllable.move.x = gamepad.getAxisValue(gamepadComponent.LeftStickX) * -1; controllable.move.y = gamepad.getAxisValue(gamepadComponent.LeftStickY) * -1; controllable.move.x -= static_cast(gamepad.isDown(gamepadComponent.keyRight)); diff --git a/sources/System/IAControllable/IAControllableSystem.cpp b/sources/System/IAControllable/IAControllableSystem.cpp index d199a58f..f851c859 100644 --- a/sources/System/IAControllable/IAControllableSystem.cpp +++ b/sources/System/IAControllable/IAControllableSystem.cpp @@ -169,7 +169,7 @@ namespace BBM pushInfo(ia._state, player, bombHolder); ia._state.callFunction(1, 4); controllable.bomb = ia._state.getReturnBool(); - controllable.select = ia._state.getReturnBool(); + controllable.secondary = ia._state.getReturnBool(); controllable.move.y = ia._state.getReturnNumber(); controllable.move.x = ia._state.getReturnNumber(); ia._state.popLast(); diff --git a/sources/System/Keyboard/KeyboardSystem.cpp b/sources/System/Keyboard/KeyboardSystem.cpp index e6820f38..c71b86be 100644 --- a/sources/System/Keyboard/KeyboardSystem.cpp +++ b/sources/System/Keyboard/KeyboardSystem.cpp @@ -25,13 +25,13 @@ namespace BBM return; const std::map keyPressedMap = { - {keyboard.keyJump, controllable.select}, - {keyboard.keyBomb, controllable.bomb}, - {keyboard.keyPause, controllable.pause} + {keyboard.keySecondary, controllable.secondary}, + {keyboard.keyBomb, controllable.bomb}, + {keyboard.keyPause, controllable.pause} }; for (auto key : keyPressedMap) - key.second = Keyboard::isDown(key.first); + key.second = controllable.fastClick ? Keyboard::isDown(key.first) : Keyboard ::isPressed(key.first); controllable.move = Vector2f(); if (Keyboard::isDown(keyboard.keyRight)) controllable.move.x -= 1; diff --git a/sources/System/Lobby/LobbySystem.cpp b/sources/System/Lobby/LobbySystem.cpp index 71be154f..8bf01496 100644 --- a/sources/System/Lobby/LobbySystem.cpp +++ b/sources/System/Lobby/LobbySystem.cpp @@ -75,7 +75,7 @@ namespace BBM if (lobby.layout == ControllableComponent::NONE) { for (auto &[_, ctrl] : this->_wal.getScene()->view()) { auto &controller = ctrl; - if (controller.select) { + if (controller.bomb) { if (std::any_of(this->getView().begin(), this->getView().end(), [&controller](WAL::ViewEntity &view) { return view.get().layout == controller.layout; })) @@ -84,7 +84,7 @@ namespace BBM lobby.color = -1; this->_nextColor(entity); lobby.layout = controller.layout; - controller.select = false; + controller.bomb = false; return; } } @@ -93,16 +93,16 @@ namespace BBM for (auto &[_, controller] : this->_wal.getScene()->view()) { if (controller.layout != lobby.layout) continue; - if (controller.select && !lobby.ready) { + if (controller.bomb && !lobby.ready) { lobby.ready = true; lobby.lastInput = lastTick; - controller.select = false; + controller.bomb = false; this->_wal.getSystem().now = lastTick; auto *texture = dynamic_cast(lobby.readyButton.getComponent().drawable.get()); if (texture) texture->use("assets/player/icons/ready.png"); } - if (controller.bomb && !lobby.ready) { + if (controller.secondary && !lobby.ready) { lobby.lastInput = lastTick; this->_nextColor(entity); } @@ -289,7 +289,7 @@ namespace BBM }); playerCount++; } - Runner::gameState._loadedScenes[GameState::SceneID::GameScene] = scene; + Runner::gameState.loadedScenes[GameState::SceneID::GameScene] = scene; Runner::gameState.nextScene = BBM::GameState::SceneID::GameScene; wal.getSystem().unloadLobby(); } diff --git a/sources/System/MenuControllable/MenuControllableSystem.cpp b/sources/System/MenuControllable/MenuControllableSystem.cpp index f0115900..766d575d 100644 --- a/sources/System/MenuControllable/MenuControllableSystem.cpp +++ b/sources/System/MenuControllable/MenuControllableSystem.cpp @@ -55,24 +55,24 @@ namespace BBM bool MenuControllableSystem::_mouseOnButton(const Vector2f &mousePos, WAL::ViewEntity &entity) const { auto &positionComponent = entity.get(); - RAY::Texture *texture = dynamic_cast(entity.get().drawable.get()); - RAY2D::Text *text = dynamic_cast(entity.get().drawable.get()); Vector2f buttonPos(positionComponent.getX(), positionComponent.getY()); Vector2f dimensions; - if (texture) { + if (auto *texture = dynamic_cast(entity.get().drawable.get())) { dimensions.x = texture->getDimensions().x; dimensions.y = texture->getDimensions().y; - } else if (text) { + } + else if (auto *text = dynamic_cast(entity.get().drawable.get())) { dimensions.y = text->getFontSize(); dimensions.x = text->getString().size() * (text->getFontSize()); - } else + } + else return false; return ((buttonPos.x <= mousePos.x && mousePos.x <= buttonPos.x + dimensions.x) - && (buttonPos.y <= mousePos.y && mousePos.y <= buttonPos.y + dimensions.y)); + && (buttonPos.y <= mousePos.y && mousePos.y <= buttonPos.y + dimensions.y)); } - void MenuControllableSystem::onSelfUpdate(std::chrono::nanoseconds dtime) + void MenuControllableSystem::onSelfUpdate(std::chrono::nanoseconds) { RAY::Vector2 rayMousePos = RAYControl::Mouse::getCursorPosition(); RAY::Vector2 winSize = RAY::Window::getInstance().getDimensions(); @@ -95,8 +95,8 @@ namespace BBM if (!this->_currentButton) return; for (auto &[_, controllable]: controllableView) - if (controllable.move.x || controllable.move.y || controllable.select) { - this->_updateCurrentButton(controllable.select, controllable.move); + if (controllable.move.x || controllable.move.y || controllable.bomb) { + this->_updateCurrentButton(controllable.bomb, controllable.move); return; } if (relativeMousePos == this->_oldMousePosition && !RAYControl::Mouse::isPressed(RAYControl::Mouse::Button::MOUSE_BUTTON_LEFT)) diff --git a/sources/System/Renderer/CameraSystem.cpp b/sources/System/Renderer/CameraSystem.cpp index 7e9bf9f2..f33b9f6d 100644 --- a/sources/System/Renderer/CameraSystem.cpp +++ b/sources/System/Renderer/CameraSystem.cpp @@ -31,9 +31,11 @@ namespace BBM .addComponent(1920 / 2 - 2 * 30 - 20, 28, 0) .addComponent(Vector2f(), Vector2f(150, 60), RAY::Color(BLACK).setA(150)); this->_wal.getScene()->scheduleNewEntity("Timer") - .addComponent(std::chrono::minutes (3), [](WAL::Entity &, WAL::Wal &) { + .addComponent(std::chrono::minutes (3), [](WAL::Entity &, WAL::Wal &engine) { + engine.getSystem().hasEnded = false; Runner::gameState.nextScene = GameState::ScoreScene; }) + .addComponent>() .addComponent(1920 / 2 - 2 * 30, 30, 0) .addComponent("", 60, RAY::Vector2(), ORANGE); for (WAL::Entity &player : this->_wal.getScene()->view>()) diff --git a/sources/System/Sound/MenuSoundManagerSystem.cpp b/sources/System/Sound/MenuSoundManagerSystem.cpp index 7f3e57e4..2e827a86 100644 --- a/sources/System/Sound/MenuSoundManagerSystem.cpp +++ b/sources/System/Sound/MenuSoundManagerSystem.cpp @@ -20,7 +20,7 @@ namespace BBM { std::map soundIndex = { {controllable.move.x, SoundComponent::MOVE}, {controllable.move.y, SoundComponent::MOVE}, - {controllable.select, SoundComponent::JUMP}, + {controllable.bomb, SoundComponent::BOMB}, }; for (auto &a : soundIndex) { if (a.first) { diff --git a/sources/System/Sound/PlayerSoundManagerSystem.cpp b/sources/System/Sound/PlayerSoundManagerSystem.cpp index 4068a5e3..4e13dcac 100644 --- a/sources/System/Sound/PlayerSoundManagerSystem.cpp +++ b/sources/System/Sound/PlayerSoundManagerSystem.cpp @@ -21,7 +21,6 @@ namespace BBM { std::map soundIndex = { {health.getHealthPoint() <= 0, SoundComponent::DEATH}, {controllable.bomb, SoundComponent::BOMB}, - {controllable.select, SoundComponent::JUMP}, {controllable.move.x != 0 || controllable.move.y != 0, SoundComponent::MOVE} }; for (auto &a : soundIndex) { diff --git a/sources/System/Timer/TimerSystem.cpp b/sources/System/Timer/TimerSystem.cpp index ded0b52e..42951c00 100644 --- a/sources/System/Timer/TimerSystem.cpp +++ b/sources/System/Timer/TimerSystem.cpp @@ -17,8 +17,13 @@ namespace BBM void TimerSystem::onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) { auto &timer = entity.get(); + + if (timer.disabled) + return; + timer.ringIn -= dtime; if (timer.ringIn <= 0ns) { + timer.disabled = true; timer.callback(entity, this->_wal); } }