From 57f9d5446af7717b9063cd560cfe02ccb713f6cf Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Thu, 10 Jun 2021 15:10:14 +0200 Subject: [PATCH 01/12] add intro animation --- .../IntroAnimationComponent.cpp | 17 +++++++ .../IntroAnimationComponent.hpp | 40 ++++++++++++++++ .../IntroAnimation/IntroAnimationSystem.cpp | 46 +++++++++++++++++++ .../IntroAnimation/IntroAnimationSystem.hpp | 31 +++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 sources/Component/IntroAnimation/IntroAnimationComponent.cpp create mode 100644 sources/Component/IntroAnimation/IntroAnimationComponent.hpp create mode 100644 sources/System/IntroAnimation/IntroAnimationSystem.cpp create mode 100644 sources/System/IntroAnimation/IntroAnimationSystem.hpp diff --git a/sources/Component/IntroAnimation/IntroAnimationComponent.cpp b/sources/Component/IntroAnimation/IntroAnimationComponent.cpp new file mode 100644 index 00000000..261a168e --- /dev/null +++ b/sources/Component/IntroAnimation/IntroAnimationComponent.cpp @@ -0,0 +1,17 @@ +// +// Created by Zoe Roux on 5/24/21. +// + +#include "IntroAnimationComponent.hpp" + +namespace BBM +{ + IntroAnimationComponent::IntroAnimationComponent(WAL::Entity &entity) + : WAL::Component(entity) + {} + + WAL::Component *IntroAnimationComponent::clone(WAL::Entity &entity) const + { + return new IntroAnimationComponent(entity); + } +} \ No newline at end of file diff --git a/sources/Component/IntroAnimation/IntroAnimationComponent.hpp b/sources/Component/IntroAnimation/IntroAnimationComponent.hpp new file mode 100644 index 00000000..694b875a --- /dev/null +++ b/sources/Component/IntroAnimation/IntroAnimationComponent.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include + +namespace BBM +{ + //! @brief A component to slowly center entities to the middle of their current block. + //! This allow flexibility in their movement will preventing them from getting stuck at every corner. + class IntroAnimationComponent : public WAL::Component + { + public: + unsigned int frame = 0; + + enum animationSteps { + init, + boxBlinking, + topLeftgrowing, + bottomRightGrowing, + lettersTyping, + fading, + prompt, + }; + + enum animationSteps currentStep = init; + + //! @inherit + Component *clone(WAL::Entity &entity) const override; + + //! @brief Create a new, default IntroAnimationComponent. + //! @param entity The entity attached to this component. + explicit IntroAnimationComponent(WAL::Entity &entity); + //! @brief A IntroAnimationComponent is copy constructable + //! @param other The other IntroAnimationComponent to copy. + IntroAnimationComponent(const IntroAnimationComponent &other) = default; + //! @brief A default destructor + ~IntroAnimationComponent() override = default; + //! @brief A IntroAnimationComponent is not assignable + IntroAnimationComponent &operator=(const IntroAnimationComponent &) = delete; + }; +} diff --git a/sources/System/IntroAnimation/IntroAnimationSystem.cpp b/sources/System/IntroAnimation/IntroAnimationSystem.cpp new file mode 100644 index 00000000..74f3a89a --- /dev/null +++ b/sources/System/IntroAnimation/IntroAnimationSystem.cpp @@ -0,0 +1,46 @@ + +#include +#include "Component/Button/ButtonComponent.hpp" +#include "Component/Position/PositionComponent.hpp" +#include "System/IntroAnimation/IntroAnimationSystem.hpp" +#include "Component/Controllable/ControllableComponent.hpp" +#include "Entity/Entity.hpp" +#include "Component/Renderer/Drawable2DComponent.hpp" +#include + +namespace RAY2D = RAY::Drawables::Drawables2D; + +namespace BBM +{ + IntroAnimationSystem::IntroAnimationSystem(WAL::Wal &wal) + : System(wal), wal(wal) + {} + + void IntroAnimationSystem::onFixedUpdate(WAL::ViewEntity &entity) + { + auto &component = entity.get(); + auto &scene = wal.getScene(); + + switch (component.currentStep) + { + case IntroAnimationComponent::animationSteps::init: + scene->addEntity("white background") + .addComponent(BBM::Vector2f(), BBM::Vector2f(1920, 1080), WHITE); + + scene->addEntity("blinking square").addComponent(BBM::Vector2f(), BBM::Vector2f(16, 16), WHITE); + component.currentStep = IntroAnimationComponent::animationSteps::boxBlinking; + break; + case IntroAnimationComponent::animationSteps::boxBlinking: + + if ((component.frame / 15) % 2) + scene->getEntities() + break; + + } + component.frame++; + } + + void IntroAnimationSystem::onSelfUpdate(void) + { + } +} \ No newline at end of file diff --git a/sources/System/IntroAnimation/IntroAnimationSystem.hpp b/sources/System/IntroAnimation/IntroAnimationSystem.hpp new file mode 100644 index 00000000..1a266443 --- /dev/null +++ b/sources/System/IntroAnimation/IntroAnimationSystem.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include "Component/IntroAnimation/IntroAnimationComponent.hpp" +#include "System/System.hpp" + +namespace BBM +{ + //! @brief A system to handle Controllable entities in a menu. + class IntroAnimationSystem : public WAL::System + { + private: + //! @brief reference to wal + WAL::Wal &wal; + + public: + //! @inherit + void onSelfUpdate(void) override; + + //! @inherit + void onFixedUpdate(WAL::ViewEntity &entities) override; + + //! @brief A default constructor + IntroAnimationSystem(WAL::Wal &wal); + //! @brief A IntroAnimation system is not copy constructable + IntroAnimationSystem(const IntroAnimationSystem &) = delete; + //! @brief A default destructor + ~IntroAnimationSystem() override = default; + //! @brief A IntroAnimation system is assignable. + IntroAnimationSystem &operator=(const IntroAnimationSystem &) = default; + }; +} \ No newline at end of file From 0a0501a044286f40fd41d537f759fec4514d1477 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Fri, 11 Jun 2021 20:13:27 +0200 Subject: [PATCH 02/12] splash screen has a scene on its own --- sources/Models/GameState.hpp | 5 +++-- sources/Runner/Runner.cpp | 12 +++++++++++- sources/Runner/Runner.hpp | 3 +++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sources/Models/GameState.hpp b/sources/Models/GameState.hpp index 61f7f309..4bb271b5 100644 --- a/sources/Models/GameState.hpp +++ b/sources/Models/GameState.hpp @@ -18,6 +18,7 @@ namespace BBM //! @brief The list of scenes available. enum SceneID { + SplashScreen, MainMenuScene, GameScene, SettingsScene, @@ -29,10 +30,10 @@ namespace BBM //! @brief The currently loaded scene - SceneID currentScene = TitleScreenScene; + SceneID currentScene = SplashScreen; //! @brief The next scene to load (if smae as currentScene, nothing to do) - SceneID nextScene = TitleScreenScene; + SceneID nextScene = SplashScreen; //! @brief The list of loaded scenes. std::unordered_map> _loadedScenes = {}; diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 8b5f68ac..bd8204c1 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -602,6 +602,15 @@ namespace BBM return scene; } + std::shared_ptr Runner::loadSplashScreenScene() + { + auto scene = std::make_shared(); + + auto &background = scene->addEntity("background") + .addComponent(Runner::updateState, Runner::gameState); diff --git a/sources/Runner/Runner.hpp b/sources/Runner/Runner.hpp index 6c42adfe..b7d21729 100644 --- a/sources/Runner/Runner.hpp +++ b/sources/Runner/Runner.hpp @@ -46,6 +46,9 @@ namespace BBM //! @brief load all data related to credit screen static std::shared_ptr loadCreditScene(); + //! @brief load all data related to splash screen + static std::shared_ptr loadSplashScreenScene(); + //! @brief loads all scenes in the game state static void loadScenes(); }; From b5d33751afe5bd2967592a1eac90bee87261a225 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Sat, 12 Jun 2021 14:18:42 +0200 Subject: [PATCH 03/12] square drwing --- CMakeLists.txt | 4 ++ lib/Ray/sources/Drawables/2D/Rectangle.cpp | 36 ++++++++++- lib/Ray/sources/Drawables/2D/Rectangle.hpp | 24 ++++++- .../IntroAnimationComponent.hpp | 5 +- sources/Runner/Runner.cpp | 9 ++- .../IntroAnimation/IntroAnimationSystem.cpp | 62 ++++++++++++++----- 6 files changed, 119 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c7e8b9ed..b4aa8778 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,6 +111,10 @@ set(SOURCES sources/System/Music/MusicSystem.cpp sources/System/Bomb/BombSystem.cpp sources/System/Bomb/BombSystem.hpp + sources/Component/IntroAnimation/IntroAnimationComponent.hpp + sources/Component/IntroAnimation/IntroAnimationComponent.cpp + sources/System/IntroAnimation/IntroAnimationSystem.hpp + sources/System/IntroAnimation/IntroAnimationSystem.cpp ) add_executable(bomberman sources/main.cpp diff --git a/lib/Ray/sources/Drawables/2D/Rectangle.cpp b/lib/Ray/sources/Drawables/2D/Rectangle.cpp index 9f623bee..284e9b27 100644 --- a/lib/Ray/sources/Drawables/2D/Rectangle.cpp +++ b/lib/Ray/sources/Drawables/2D/Rectangle.cpp @@ -33,13 +33,47 @@ namespace RAY::Drawables::Drawables2D return *this; } - Rectangle &Rectangle::setDimensions(int x, int y) + Rectangle &Rectangle::setDimensions(float x, float y) { this->_dimensions.x = x; this->_dimensions.y = y; return *this; } + float Rectangle::getHeight(void) const + { + return this->_dimensions.y; + } + + float Rectangle::getWidth(void) const + { + return this->_dimensions.x; + } + + Rectangle &Rectangle::incrementWidth(float width) + { + this->_dimensions.x += width; + return *this; + } + + Rectangle &Rectangle::incrementHeight(float height) + { + this->_dimensions.y += height; + return *this; + } + + Rectangle &Rectangle::setWidth(float width) + { + this->_dimensions.x = width; + return *this; + } + + Rectangle &Rectangle::setHeight(float height) + { + this->_dimensions.y = height; + return *this; + } + void Rectangle::drawOn(RAY::Window &) { DrawRectangleV(this->_position, this->_dimensions, this->_color); diff --git a/lib/Ray/sources/Drawables/2D/Rectangle.hpp b/lib/Ray/sources/Drawables/2D/Rectangle.hpp index e0d32dff..6442a7f1 100644 --- a/lib/Ray/sources/Drawables/2D/Rectangle.hpp +++ b/lib/Ray/sources/Drawables/2D/Rectangle.hpp @@ -42,11 +42,33 @@ namespace RAY::Drawables::Drawables2D { //! @return the dimensions of the rectangle const Vector2 &getDimensions(void); + //! @return the width of the rectangle + float getWidth(void) const; + + //! @return the height of the rectangle + float getHeight(void) const; + //! @brief set dimensions Rectangle &setDimensions(const Vector2 &dimensions); + //! @brief increment width of the rectangle + //! @param width incrementer + Rectangle &incrementWidth(float width); + + //! @brief increment height of the rectangle + //! @param height incrementer + Rectangle &incrementHeight(float height); + + //! @brief set rectangle's height + //! @param height height of the rectangle + Rectangle &setHeight(float height); + + //! @brief set rectangle's width + //! @param width width of the rectangle + Rectangle &setWidth(float width); + //! @brief set dimensions - Rectangle &setDimensions(int x, int y); + Rectangle &setDimensions(float x, float y); //! @brief Draw point on window virtual void drawOn(RAY::Window &) override; diff --git a/sources/Component/IntroAnimation/IntroAnimationComponent.hpp b/sources/Component/IntroAnimation/IntroAnimationComponent.hpp index 694b875a..0def3a25 100644 --- a/sources/Component/IntroAnimation/IntroAnimationComponent.hpp +++ b/sources/Component/IntroAnimation/IntroAnimationComponent.hpp @@ -9,10 +9,9 @@ namespace BBM class IntroAnimationComponent : public WAL::Component { public: - unsigned int frame = 0; + unsigned int frameCounter = 0; enum animationSteps { - init, boxBlinking, topLeftgrowing, bottomRightGrowing, @@ -21,7 +20,7 @@ namespace BBM prompt, }; - enum animationSteps currentStep = init; + enum animationSteps currentStep = boxBlinking; //! @inherit Component *clone(WAL::Entity &entity) const override; diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index bd8204c1..80f057cc 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include #include @@ -90,6 +92,7 @@ namespace BBM .addSystem() .addSystem() .addSystem() + .addSystem() .addSystem(); } @@ -606,8 +609,12 @@ namespace BBM { auto scene = std::make_shared(); + + auto &splashComponent = scene->addEntity("animation component") + .addComponent(); auto &background = scene->addEntity("background") - .addComponent(0, 0, 0) + .addComponent(RAY::Vector2(), RAY::Vector2(1920, 1080)); return scene; } diff --git a/sources/System/IntroAnimation/IntroAnimationSystem.cpp b/sources/System/IntroAnimation/IntroAnimationSystem.cpp index 74f3a89a..10243eae 100644 --- a/sources/System/IntroAnimation/IntroAnimationSystem.cpp +++ b/sources/System/IntroAnimation/IntroAnimationSystem.cpp @@ -1,9 +1,7 @@ -#include #include "Component/Button/ButtonComponent.hpp" #include "Component/Position/PositionComponent.hpp" #include "System/IntroAnimation/IntroAnimationSystem.hpp" -#include "Component/Controllable/ControllableComponent.hpp" #include "Entity/Entity.hpp" #include "Component/Renderer/Drawable2DComponent.hpp" #include @@ -18,26 +16,60 @@ namespace BBM void IntroAnimationSystem::onFixedUpdate(WAL::ViewEntity &entity) { + static const RAY::Vector2 logoPos(1920 / 2 - 128, 1080 / 2 - 128); auto &component = entity.get(); - auto &scene = wal.getScene(); + auto scene = wal.getScene(); + RAY2D::Rectangle *rectangle = nullptr; + static auto &bottomRectangle = scene->addEntity("bottom Rectangle") + .addComponent(1920 / 2 - 128, 1080 / 2 - 128, 0) + .addComponent(logoPos, RAY::Vector2(16, 16), BLACK); + static auto &leftRectangle = scene->addEntity("left Rectangle") + .addComponent(1920 / 2 - 128, 1080 / 2 - 128, 0) + .addComponent(logoPos, RAY::Vector2(16, 16), BLACK); + static auto &rightRectangle = scene->addEntity("right Rectangle") + .addComponent(1920 / 2 - 128, 1080 / 2 - 128, 0) + .addComponent(logoPos, RAY::Vector2(16, 16), BLACK); + static auto &topRectangle = scene->addEntity("top Rectangle") + .addComponent(1920 / 2 - 128, 1080 / 2 - 128, 0) + .addComponent(logoPos, RAY::Vector2(16, 16), BLACK); switch (component.currentStep) { - case IntroAnimationComponent::animationSteps::init: - scene->addEntity("white background") - .addComponent(BBM::Vector2f(), BBM::Vector2f(1920, 1080), WHITE); - - scene->addEntity("blinking square").addComponent(BBM::Vector2f(), BBM::Vector2f(16, 16), WHITE); - component.currentStep = IntroAnimationComponent::animationSteps::boxBlinking; - break; case IntroAnimationComponent::animationSteps::boxBlinking: - - if ((component.frame / 15) % 2) - scene->getEntities() + if ((component.frameCounter / 15) % 2) + topRectangle.getComponent().drawable->setColor(BLACK); + else + topRectangle.getComponent().drawable->setColor(WHITE); + if (component.frameCounter == 120) { + component.currentStep = IntroAnimationComponent::animationSteps::topLeftgrowing; + component.frameCounter = -1; + topRectangle.getComponent().drawable->setColor(BLACK); + leftRectangle.getComponent().drawable->setColor(BLACK); + } + break; + case IntroAnimationComponent::animationSteps::topLeftgrowing: + rectangle = dynamic_cast(leftRectangle.getComponent().drawable.get()); + rectangle->incrementHeight(4); + rectangle = dynamic_cast(topRectangle.getComponent().drawable.get()); + rectangle->incrementWidth(4); + if (rectangle->getWidth() == 256) { + component.currentStep = IntroAnimationComponent::animationSteps::bottomRightGrowing; + bottomRectangle.getComponent().position = Vector3f(1920 / 2 - 128, 1080 / 2 - 128 + 240, 0); + rightRectangle.getComponent().position = Vector3f(1920 / 2 - 128 + 240, 1080 / 2 - 128, 0); + } + break; + case IntroAnimationComponent::animationSteps::bottomRightGrowing: + rectangle = dynamic_cast(bottomRectangle.getComponent().drawable.get()); + rectangle->incrementWidth(4); + rectangle = dynamic_cast(rightRectangle.getComponent().drawable.get()); + rectangle->incrementHeight(4); + if (rectangle->getHeight() == 256) + component.currentStep = IntroAnimationComponent::animationSteps::lettersTyping; + break; + default: break; - } - component.frame++; + component.frameCounter++; } void IntroAnimationSystem::onSelfUpdate(void) From 5b45158d26cf935e28cdc3f524fbeb7769db3438 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Sat, 12 Jun 2021 14:59:40 +0200 Subject: [PATCH 04/12] sound playing at end of intro --- assets/sounds/splash_sound.ogg | Bin 0 -> 6361 bytes sources/Runner/Runner.cpp | 18 ++++++++--- .../IntroAnimation/IntroAnimationSystem.cpp | 29 ++++++++++++++++-- 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 assets/sounds/splash_sound.ogg diff --git a/assets/sounds/splash_sound.ogg b/assets/sounds/splash_sound.ogg new file mode 100644 index 0000000000000000000000000000000000000000..d9092e5300ff3475036d398a91b032aced870a0b GIT binary patch literal 6361 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 { - if (component.pause) { + if (component.pause && gameState.currentScene == GameState::SceneID::GameScene) { gameState.nextScene = GameState::SceneID::PauseMenuScene; break; + } else if (gameState.currentScene == GameState::SceneID::SplashScreen && component.jump) { + gameState.nextScene = GameState::SceneID::TitleScreenScene; + break; } } } @@ -609,12 +612,19 @@ namespace BBM { auto scene = std::make_shared(); - auto &splashComponent = scene->addEntity("animation component") - .addComponent(); + .addComponent() + .addComponent() + .addComponent(); auto &background = scene->addEntity("background") .addComponent(0, 0, 0) .addComponent(RAY::Vector2(), RAY::Vector2(1920, 1080)); + auto &text = scene->addEntity("powered by text") + .addComponent(1920 / 2 - 200, 1080 / 2 - 180, 0) + .addComponent("powered by", 30, RAY::Vector2(), BLACK); + auto &skipText = scene->addEntity("Press space to skip") + .addComponent(1920 - 250, 1080 - 30, 0) + .addComponent("Press space to skip", 20, RAY::Vector2(), BLACK); return scene; } diff --git a/sources/System/IntroAnimation/IntroAnimationSystem.cpp b/sources/System/IntroAnimation/IntroAnimationSystem.cpp index 10243eae..c5671987 100644 --- a/sources/System/IntroAnimation/IntroAnimationSystem.cpp +++ b/sources/System/IntroAnimation/IntroAnimationSystem.cpp @@ -4,7 +4,11 @@ #include "System/IntroAnimation/IntroAnimationSystem.hpp" #include "Entity/Entity.hpp" #include "Component/Renderer/Drawable2DComponent.hpp" +#include "Component/Controllable/ControllableComponent.hpp" #include +#include +#include "Runner/Runner.hpp" +#include "Component/Music/MusicComponent.hpp" namespace RAY2D = RAY::Drawables::Drawables2D; @@ -20,6 +24,10 @@ namespace BBM auto &component = entity.get(); auto scene = wal.getScene(); RAY2D::Rectangle *rectangle = nullptr; + RAY2D::Text *text = nullptr; + static auto &rayText = scene->addEntity("raylibtext Rectangle") + .addComponent(1920 / 2 - 44, 1080 / 2 + 48, 0) + .addComponent("", 50, RAY::Vector2(), BLACK); static auto &bottomRectangle = scene->addEntity("bottom Rectangle") .addComponent(1920 / 2 - 128, 1080 / 2 - 128, 0) .addComponent(logoPos, RAY::Vector2(16, 16), BLACK); @@ -32,6 +40,7 @@ namespace BBM static auto &topRectangle = scene->addEntity("top Rectangle") .addComponent(1920 / 2 - 128, 1080 / 2 - 128, 0) .addComponent(logoPos, RAY::Vector2(16, 16), BLACK); + static short letterCounter = 0; switch (component.currentStep) { @@ -40,7 +49,7 @@ namespace BBM topRectangle.getComponent().drawable->setColor(BLACK); else topRectangle.getComponent().drawable->setColor(WHITE); - if (component.frameCounter == 120) { + if (component.frameCounter == 60) { component.currentStep = IntroAnimationComponent::animationSteps::topLeftgrowing; component.frameCounter = -1; topRectangle.getComponent().drawable->setColor(BLACK); @@ -63,8 +72,24 @@ namespace BBM rectangle->incrementWidth(4); rectangle = dynamic_cast(rightRectangle.getComponent().drawable.get()); rectangle->incrementHeight(4); - if (rectangle->getHeight() == 256) + if (rectangle->getHeight() == 256) { component.currentStep = IntroAnimationComponent::animationSteps::lettersTyping; + component.frameCounter = 0; + } + break; + case IntroAnimationComponent::animationSteps::lettersTyping: + if ((component.frameCounter / 15) % 2) { + letterCounter++; + text = dynamic_cast(rayText.getComponent().drawable.get()); + if (letterCounter == 2) { + scene->addEntity("startup sound") + .addComponent("assets/sounds/splash_sound.ogg") + .getComponent().playMusic(); + } + text->setText(std::string("raylib").substr(0, letterCounter)); + } + if (component.frameCounter == 60) + Runner::gameState.nextScene = Runner::gameState.TitleScreenScene; break; default: break; From ae68d5ab6883336940376e30c703c6260f713eb2 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Mon, 14 Jun 2021 10:07:08 +0200 Subject: [PATCH 05/12] add wires + bounding box drawing for 3D shapes/Models --- lib/Ray/sources/Drawables/3D/Cube.cpp | 5 +++++ lib/Ray/sources/Drawables/3D/Cube.hpp | 3 +++ lib/Ray/sources/Drawables/3D/Cylinder.cpp | 5 +++++ lib/Ray/sources/Drawables/3D/Cylinder.hpp | 2 ++ lib/Ray/sources/Drawables/3D/Sphere.cpp | 5 +++++ lib/Ray/sources/Drawables/3D/Sphere.hpp | 3 +++ lib/Ray/sources/Drawables/ADrawable3D.cpp | 3 +++ lib/Ray/sources/Drawables/ADrawable3D.hpp | 3 +++ lib/Ray/sources/Model/Model.cpp | 14 ++++++++++++++ lib/Ray/sources/Model/Model.hpp | 3 +++ sources/System/Renderer/RenderSystem.cpp | 4 +++- 11 files changed, 49 insertions(+), 1 deletion(-) diff --git a/lib/Ray/sources/Drawables/3D/Cube.cpp b/lib/Ray/sources/Drawables/3D/Cube.cpp index 6f651a15..7875e99a 100644 --- a/lib/Ray/sources/Drawables/3D/Cube.cpp +++ b/lib/Ray/sources/Drawables/3D/Cube.cpp @@ -30,4 +30,9 @@ namespace RAY::Drawables::Drawables3D { DrawCubeV(this->_position, this->_dimensions, this->_color); } + + void Cube::drawWiresOn(RAY::Window &) + { + DrawCubeWiresV(this->_position, this->_dimensions, GREEN); + } } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/3D/Cube.hpp b/lib/Ray/sources/Drawables/3D/Cube.hpp index d1fff6f9..96347a95 100644 --- a/lib/Ray/sources/Drawables/3D/Cube.hpp +++ b/lib/Ray/sources/Drawables/3D/Cube.hpp @@ -41,6 +41,9 @@ namespace RAY::Drawables::Drawables3D { //! @brief Draw circle on window void drawOn(RAY::Window &) override; + + //! @brief Draw cube's wires on window + void drawWiresOn(RAY::Window &) override; private: //! @brief Dimensions of the cube Vector3 _dimensions; diff --git a/lib/Ray/sources/Drawables/3D/Cylinder.cpp b/lib/Ray/sources/Drawables/3D/Cylinder.cpp index 64db931d..6dfb2a1f 100644 --- a/lib/Ray/sources/Drawables/3D/Cylinder.cpp +++ b/lib/Ray/sources/Drawables/3D/Cylinder.cpp @@ -52,4 +52,9 @@ namespace RAY::Drawables::Drawables3D { DrawCylinder(this->_position, this->_topRadius, this->_bottomRadius, this->_height, 0, this->_color); } + + void Cylinder::drawWiresOn(RAY::Window &) + { + DrawCylinderWires(this->_position, this->_topRadius, this->_bottomRadius, this->_height, 0, GREEN); + } } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/3D/Cylinder.hpp b/lib/Ray/sources/Drawables/3D/Cylinder.hpp index dc09fb5d..32871514 100644 --- a/lib/Ray/sources/Drawables/3D/Cylinder.hpp +++ b/lib/Ray/sources/Drawables/3D/Cylinder.hpp @@ -55,6 +55,8 @@ namespace RAY::Drawables::Drawables3D { //! @brief Draw point on window void drawOn(RAY::Window &) override; + //! @brief Draw cylinder's wires on window + void drawWiresOn(RAY::Window &) override; private: //! @brief Radius of the cylinder float _topRadius; diff --git a/lib/Ray/sources/Drawables/3D/Sphere.cpp b/lib/Ray/sources/Drawables/3D/Sphere.cpp index 7d23fc48..2949606e 100644 --- a/lib/Ray/sources/Drawables/3D/Sphere.cpp +++ b/lib/Ray/sources/Drawables/3D/Sphere.cpp @@ -30,4 +30,9 @@ namespace RAY::Drawables::Drawables3D { DrawSphere(this->_position, this->_radius, this->_color); } + + void Sphere::drawWiresOn(RAY::Window &) + { + DrawSphereWires(this->_position, this->_radius, 10, 10, GREEN); + } } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/3D/Sphere.hpp b/lib/Ray/sources/Drawables/3D/Sphere.hpp index d053ccf9..24c31a8b 100644 --- a/lib/Ray/sources/Drawables/3D/Sphere.hpp +++ b/lib/Ray/sources/Drawables/3D/Sphere.hpp @@ -40,6 +40,9 @@ namespace RAY::Drawables::Drawables3D { //! @brief Draw point on window void drawOn(RAY::Window &) override; + //! @brief Draw sphere's wires on window + void drawWiresOn(RAY::Window &) override; + private: //! @brief Radius of the sphere int _radius; diff --git a/lib/Ray/sources/Drawables/ADrawable3D.cpp b/lib/Ray/sources/Drawables/ADrawable3D.cpp index 0fff69f8..fabc12fd 100644 --- a/lib/Ray/sources/Drawables/ADrawable3D.cpp +++ b/lib/Ray/sources/Drawables/ADrawable3D.cpp @@ -36,4 +36,7 @@ namespace RAY::Drawables this->_position = position; return *this; } + + void ADrawable3D::drawWiresOn(RAY::Window &) + {} } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/ADrawable3D.hpp b/lib/Ray/sources/Drawables/ADrawable3D.hpp index cc989fed..4c82ded6 100644 --- a/lib/Ray/sources/Drawables/ADrawable3D.hpp +++ b/lib/Ray/sources/Drawables/ADrawable3D.hpp @@ -30,6 +30,9 @@ namespace RAY::Drawables { //! @brief Draw drawble on window void drawOn(RAY::Window &) override = 0; + //! @brief Draw drawble's wires on window + virtual void drawWiresOn(RAY::Window &); + //! @return the color of the ADrawable const RAY::Color &getColor(void) const; diff --git a/lib/Ray/sources/Model/Model.cpp b/lib/Ray/sources/Model/Model.cpp index 9fd5b31e..2239c359 100644 --- a/lib/Ray/sources/Model/Model.cpp +++ b/lib/Ray/sources/Model/Model.cpp @@ -114,6 +114,20 @@ namespace RAY::Drawables::Drawables3D this->_color); } + void Model::drawWiresOn(RAY::Window &) + { + if (this->_model->meshCount) { + ::BoundingBox box = GetMeshBoundingBox(*this->_model->meshes); + box.min.x += this->_position.x; + box.min.y += this->_position.y; + box.min.z += this->_position.z; + box.max.x += this->_position.x; + box.max.y += this->_position.y; + box.max.z += this->_position.z; + DrawBoundingBox(box, GREEN); + } + } + void Model::setShader(const RAY::Shader &shader) { this->_originalShader = this->_model->materials[0].shader; diff --git a/lib/Ray/sources/Model/Model.hpp b/lib/Ray/sources/Model/Model.hpp index d67706be..2bf6cf47 100644 --- a/lib/Ray/sources/Model/Model.hpp +++ b/lib/Ray/sources/Model/Model.hpp @@ -87,6 +87,9 @@ namespace RAY::Drawables::Drawables3D { void drawOn(RAY::Window &) override; + //! @brief Draw model's wires on window + void drawWiresOn(RAY::Window &) override; + private: //! @brief Raw data from raylib std::shared_ptr<::Model> _model; diff --git a/sources/System/Renderer/RenderSystem.cpp b/sources/System/Renderer/RenderSystem.cpp index 07b64134..d901b115 100644 --- a/sources/System/Renderer/RenderSystem.cpp +++ b/sources/System/Renderer/RenderSystem.cpp @@ -40,6 +40,8 @@ namespace BBM modelShader->model->setShader(modelShader->getShader()); drawable.drawable->setPosition(pos.position); drawable.drawable->drawOn(this->_window); + if (this->_debugMode) + drawable.drawable->drawWiresOn(this->_window); if (modelShader) modelShader->model->resetShader(); } @@ -59,7 +61,7 @@ namespace BBM } } if (this->_debugMode) - this->_window.drawFPS(Vector2f()); + this->_window.drawFPS(Vector2f(10, 10)); this->_window.endDrawing(); } From ce8ce3b4a9095cf7242dc45aaf3657a44d4d3276 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Mon, 14 Jun 2021 10:26:08 +0200 Subject: [PATCH 06/12] split runner file: splash, title + credit --- CMakeLists.txt | 3 + sources/Runner/CreditScene.cpp | 73 +++++++++++++++++++ sources/Runner/Runner.cpp | 103 --------------------------- sources/Runner/SplashScreenScene.cpp | 37 ++++++++++ sources/Runner/TitleScreenScene.cpp | 47 ++++++++++++ 5 files changed, 160 insertions(+), 103 deletions(-) create mode 100644 sources/Runner/CreditScene.cpp create mode 100644 sources/Runner/SplashScreenScene.cpp create mode 100644 sources/Runner/TitleScreenScene.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b4aa8778..072f19b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,6 +115,9 @@ set(SOURCES sources/Component/IntroAnimation/IntroAnimationComponent.cpp sources/System/IntroAnimation/IntroAnimationSystem.hpp sources/System/IntroAnimation/IntroAnimationSystem.cpp + sources/Runner/SplashScreenScene.cpp + sources/Runner/TitleScreenScene.cpp + sources/Runner/CreditScene.cpp ) add_executable(bomberman sources/main.cpp diff --git a/sources/Runner/CreditScene.cpp b/sources/Runner/CreditScene.cpp new file mode 100644 index 00000000..38c9b77e --- /dev/null +++ b/sources/Runner/CreditScene.cpp @@ -0,0 +1,73 @@ + +#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::loadCreditScene() + { + auto scene = std::make_shared(); + static const std::map sounds = { + {SoundComponent::JUMP, "assets/sounds/click.ogg"} + }; + + scene->addEntity("background") + .addComponent() + .addComponent("assets/plain_menu_background.png"); + + scene->addEntity("Control entity") + .addComponent() + .addComponent() + .addComponent("assets/musics/music_title.ogg") + .addComponent(sounds); + + auto &raylibLogo = scene->addEntity("raylib logo") + .addComponent(1920 / 4, 1080 / 1.75, 0) + .addComponent("assets/raylib.png"); + auto &raylibText = scene->addEntity("raylib text") + .addComponent(1920 / 4, 1080 / 2, 0) + .addComponent("Powered by:", 35, RAY::Vector2(), BLACK); + auto &otherRepoText = scene->addEntity("other repo text") + .addComponent(1920 / 4, 1080 / 4, 0) + .addComponent("Many Thanks to:", 35, RAY::Vector2(), BLACK); + auto &BriansRepo = scene->addEntity("thx brian") + .addComponent(1920 / 3.5, 1080 / 3.5, 0) + .addComponent("Brian Guitteny (and his team)", 35, RAY::Vector2(), BLACK); + auto &team = scene->addEntity("team") + .addComponent(1920 / 1.5, 1080 / 3.5, 0) + .addComponent("Team:\n Zoe Roux\n Clément Le Bihan\n Arthur Jamet\n Louis Auzuret\n Benjamin Henry\n Tom Augier", 35, RAY::Vector2(), BLACK); + 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"); + }); + return scene; + } + +} \ No newline at end of file diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index d9410f21..364f90e4 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -108,35 +108,6 @@ namespace BBM .addSystem(window); } - std::shared_ptr Runner::loadTitleScreenScene() - { - static const std::map sounds = { - {SoundComponent::JUMP, "assets/sounds/click.ogg"} - }; - auto scene = std::make_shared(); - scene->addEntity("control") - .addComponent() - .addComponent() - .addComponent(sounds) - .addComponent("assets/musics/music_title.ogg"); - scene->addEntity("background") - .addComponent() - .addComponent("assets/plain_menu_background.png"); - scene->addEntity("logo") - .addComponent(320, 180, 0) - .addComponent("assets/logo_big.png"); - scene->addEntity("text_prompt") - .addComponent(1920 / 2.5, 1080 - 130, 0) - .addComponent("Press space", 70, RAY::Vector2(), BLACK) - .addComponent() - .addComponent() - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; - }); - return scene; - } - std::shared_ptr Runner::loadMainMenuScene() { static const std::map sounds = { @@ -554,80 +525,6 @@ namespace BBM return scene; } - std::shared_ptr Runner::loadCreditScene() - { - auto scene = std::make_shared(); - static const std::map sounds = { - {SoundComponent::JUMP, "assets/sounds/click.ogg"} - }; - - scene->addEntity("background") - .addComponent() - .addComponent("assets/plain_menu_background.png"); - - scene->addEntity("Control entity") - .addComponent() - .addComponent() - .addComponent("assets/musics/music_title.ogg") - .addComponent(sounds); - - auto &raylibLogo = scene->addEntity("raylib logo") - .addComponent(1920 / 4, 1080 / 1.75, 0) - .addComponent("assets/raylib.png"); - auto &raylibText = scene->addEntity("raylib text") - .addComponent(1920 / 4, 1080 / 2, 0) - .addComponent("Powered by:", 35, RAY::Vector2(), BLACK); - auto &otherRepoText = scene->addEntity("other repo text") - .addComponent(1920 / 4, 1080 / 4, 0) - .addComponent("Many Thanks to:", 35, RAY::Vector2(), BLACK); - auto &BriansRepo = scene->addEntity("thx brian") - .addComponent(1920 / 3.5, 1080 / 3.5, 0) - .addComponent("Brian Guitteny (and his team)", 35, RAY::Vector2(), BLACK); - auto &team = scene->addEntity("team") - .addComponent(1920 / 1.5, 1080 / 3.5, 0) - .addComponent("Team:\n Zoe Roux\n Clément Le Bihan\n Arthur Jamet\n Louis Auzuret\n Benjamin Henry\n Tom Augier", 35, RAY::Vector2(), BLACK); - 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"); - }); - return scene; - } - - std::shared_ptr Runner::loadSplashScreenScene() - { - auto scene = std::make_shared(); - - auto &splashComponent = scene->addEntity("animation component") - .addComponent() - .addComponent() - .addComponent(); - auto &background = scene->addEntity("background") - .addComponent(0, 0, 0) - .addComponent(RAY::Vector2(), RAY::Vector2(1920, 1080)); - auto &text = scene->addEntity("powered by text") - .addComponent(1920 / 2 - 200, 1080 / 2 - 180, 0) - .addComponent("powered by", 30, RAY::Vector2(), BLACK); - auto &skipText = scene->addEntity("Press space to skip") - .addComponent(1920 - 250, 1080 - 30, 0) - .addComponent("Press space to skip", 20, RAY::Vector2(), BLACK); - return scene; - } - void Runner::loadScenes() { gameState._loadedScenes[GameState::SceneID::MainMenuScene] = loadMainMenuScene(); diff --git a/sources/Runner/SplashScreenScene.cpp b/sources/Runner/SplashScreenScene.cpp new file mode 100644 index 00000000..455a0e95 --- /dev/null +++ b/sources/Runner/SplashScreenScene.cpp @@ -0,0 +1,37 @@ + +#include +#include +#include "Runner.hpp" +#include "Component/Music/MusicComponent.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 "Component/IntroAnimation/IntroAnimationComponent.hpp" + +namespace RAY2D = RAY::Drawables::Drawables2D; + +namespace BBM +{ + std::shared_ptr Runner::loadSplashScreenScene() + { + auto scene = std::make_shared(); + + auto &splashComponent = scene->addEntity("animation component") + .addComponent() + .addComponent() + .addComponent(); + auto &background = scene->addEntity("background") + .addComponent(0, 0, 0) + .addComponent(RAY::Vector2(), RAY::Vector2(1920, 1080)); + auto &text = scene->addEntity("powered by text") + .addComponent(1920 / 2 - 200, 1080 / 2 - 180, 0) + .addComponent("powered by", 30, RAY::Vector2(), BLACK); + auto &skipText = scene->addEntity("Press space to skip") + .addComponent(1920 - 250, 1080 - 30, 0) + .addComponent("Press space to skip", 20, RAY::Vector2(), BLACK); + return scene; + } +} \ No newline at end of file diff --git a/sources/Runner/TitleScreenScene.cpp b/sources/Runner/TitleScreenScene.cpp new file mode 100644 index 00000000..0cbbf488 --- /dev/null +++ b/sources/Runner/TitleScreenScene.cpp @@ -0,0 +1,47 @@ + +#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::loadTitleScreenScene() + { + static const std::map sounds = { + {SoundComponent::JUMP, "assets/sounds/click.ogg"} + }; + auto scene = std::make_shared(); + scene->addEntity("control") + .addComponent() + .addComponent() + .addComponent(sounds) + .addComponent("assets/musics/music_title.ogg"); + scene->addEntity("background") + .addComponent() + .addComponent("assets/plain_menu_background.png"); + scene->addEntity("logo") + .addComponent(320, 180, 0) + .addComponent("assets/logo_big.png"); + scene->addEntity("text_prompt") + .addComponent(1920 / 2.5, 1080 - 130, 0) + .addComponent("Press space", 70, RAY::Vector2(), BLACK) + .addComponent() + .addComponent() + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; + }); + return scene; + } +} \ No newline at end of file From 3244110d27b7bdf44b9a1c7751cd9916005d4517 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Mon, 14 Jun 2021 10:47:44 +0200 Subject: [PATCH 07/12] split runner file: game scene --- CMakeLists.txt | 1 + sources/Runner/GameScene.cpp | 69 ++++++++++++++++++++++++++++++++++++ sources/Runner/Runner.cpp | 40 --------------------- 3 files changed, 70 insertions(+), 40 deletions(-) create mode 100644 sources/Runner/GameScene.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 072f19b2..96e41a30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,6 +117,7 @@ set(SOURCES sources/System/IntroAnimation/IntroAnimationSystem.cpp sources/Runner/SplashScreenScene.cpp sources/Runner/TitleScreenScene.cpp + sources/Runner/GameScene.cpp sources/Runner/CreditScene.cpp ) add_executable(bomberman diff --git a/sources/Runner/GameScene.cpp b/sources/Runner/GameScene.cpp new file mode 100644 index 00000000..f3a90aa6 --- /dev/null +++ b/sources/Runner/GameScene.cpp @@ -0,0 +1,69 @@ +#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/Animator/AnimatorComponent.hpp" +#include "Component/Animation/AnimationsComponent.hpp" +#include "Component/Health/HealthComponent.hpp" +#include "Component/Renderer/CameraComponent.hpp" +#include "Component/Collision/CollisionComponent.hpp" +#include "Component/Movable/MovableComponent.hpp" +#include "Component/BombHolder/BombHolderComponent.hpp" +#include "Component/Bonus/PlayerBonusComponent.hpp" +#include "Component/Shaders/ShaderComponent.hpp" +#include "Component/Tag/TagComponent.hpp" +#include "Component/Renderer/Drawable3DComponent.hpp" +#include "Component/Button/ButtonComponent.hpp" +#include "Drawables/2D/Text.hpp" +#include "Model/Model.hpp" +#include "Map/Map.hpp" + +namespace RAY3D = RAY::Drawables::Drawables3D; + +namespace BBM +{ + std::shared_ptr Runner::loadGameScene() + { + auto scene = std::make_shared(); + scene->addEntity("control") + .addComponent() + .addComponent(); + std::map soundPath ={ + {SoundComponent::JUMP, "assets/sounds/jump.wav"}, + {SoundComponent::MOVE, "assets/sounds/move.ogg"}, + {SoundComponent::BOMB, "assets/sounds/bomb_drop.ogg"}, + //{SoundComponent::DEATH, "assets/sounds/death.ogg"} + }; + scene->addEntity("player") + .addComponent() + .addComponent("assets/player/player.iqm", true, std::make_pair(MAP_DIFFUSE, "assets/player/blue.png")) + .addComponent() + .addComponent() + .addComponent() + .addComponent("assets/shaders/glsl330/predator.fs") + .addComponent>() + //.addComponent(0) + .addComponent(RAY::ModelAnimations("assets/player/player.iqm"), 3) + .addComponent(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75}) + .addComponent() + .addComponent(soundPath) + .addComponent("assets/musics/music_battle.ogg") + .addComponent() + .addComponent() + .addComponent(1, [](WAL::Entity &entity, WAL::Wal &wal) { + auto &animation = entity.getComponent(); + animation.setAnimIndex(5); + }); + scene->addEntity("camera") + .addComponent(8, 20, 7) + .addComponent(Vector3f(8, 0, 8)); + MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene); + + return scene; + } +} \ No newline at end of file diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 364f90e4..4c18e18f 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -485,46 +485,6 @@ namespace BBM return scene; } - std::shared_ptr Runner::loadGameScene() - { - auto scene = std::make_shared(); - scene->addEntity("control") - .addComponent() - .addComponent(); - std::map soundPath ={ - {SoundComponent::JUMP, "assets/sounds/jump.wav"}, - {SoundComponent::MOVE, "assets/sounds/move.ogg"}, - {SoundComponent::BOMB, "assets/sounds/bomb_drop.ogg"}, - //{SoundComponent::DEATH, "assets/sounds/death.ogg"} - }; - scene->addEntity("player") - .addComponent() - .addComponent("assets/player/player.iqm", true, std::make_pair(MAP_DIFFUSE, "assets/player/blue.png")) - .addComponent() - .addComponent() - .addComponent() - .addComponent("assets/shaders/glsl330/predator.fs") - .addComponent>() - //.addComponent(0) - .addComponent(RAY::ModelAnimations("assets/player/player.iqm"), 3) - .addComponent(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75}) - .addComponent() - .addComponent(soundPath) - .addComponent("assets/musics/music_battle.ogg") - .addComponent() - .addComponent() - .addComponent(1, [](WAL::Entity &entity, WAL::Wal &wal) { - auto &animation = entity.getComponent(); - animation.setAnimIndex(5); - }); - scene->addEntity("camera") - .addComponent(8, 20, 7) - .addComponent(Vector3f(8, 0, 8)); - MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene); - - return scene; - } - void Runner::loadScenes() { gameState._loadedScenes[GameState::SceneID::MainMenuScene] = loadMainMenuScene(); From 73ee44d7088f76dd0c97deedf64e2aa1e90dc970 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Mon, 14 Jun 2021 11:04:52 +0200 Subject: [PATCH 08/12] split runner file: remove unnecessary includes --- CMakeLists.txt | 3 + sources/Runner/MainMenuScene.cpp | 119 ++++++++ sources/Runner/PauseMenuScene.cpp | 101 +++++++ sources/Runner/Runner.cpp | 393 --------------------------- sources/Runner/SettingsMenuScene.cpp | 212 +++++++++++++++ 5 files changed, 435 insertions(+), 393 deletions(-) create mode 100644 sources/Runner/MainMenuScene.cpp create mode 100644 sources/Runner/PauseMenuScene.cpp create mode 100644 sources/Runner/SettingsMenuScene.cpp 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 From a3236ffba6a29002da19fd06e2eeb433bd4b133d Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Mon, 14 Jun 2021 11:43:39 +0200 Subject: [PATCH 09/12] debug color is now a memeber of the drawable 3D class --- lib/Ray/sources/Drawables/3D/Cube.cpp | 2 +- lib/Ray/sources/Drawables/3D/Cylinder.cpp | 2 +- lib/Ray/sources/Drawables/3D/Sphere.cpp | 2 +- lib/Ray/sources/Drawables/ADrawable3D.hpp | 3 +++ lib/Ray/sources/Model/Model.cpp | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/Ray/sources/Drawables/3D/Cube.cpp b/lib/Ray/sources/Drawables/3D/Cube.cpp index 7875e99a..1af236d1 100644 --- a/lib/Ray/sources/Drawables/3D/Cube.cpp +++ b/lib/Ray/sources/Drawables/3D/Cube.cpp @@ -33,6 +33,6 @@ namespace RAY::Drawables::Drawables3D void Cube::drawWiresOn(RAY::Window &) { - DrawCubeWiresV(this->_position, this->_dimensions, GREEN); + DrawCubeWiresV(this->_position, this->_dimensions, this->_debugColor); } } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/3D/Cylinder.cpp b/lib/Ray/sources/Drawables/3D/Cylinder.cpp index 6dfb2a1f..8e2ff386 100644 --- a/lib/Ray/sources/Drawables/3D/Cylinder.cpp +++ b/lib/Ray/sources/Drawables/3D/Cylinder.cpp @@ -55,6 +55,6 @@ namespace RAY::Drawables::Drawables3D void Cylinder::drawWiresOn(RAY::Window &) { - DrawCylinderWires(this->_position, this->_topRadius, this->_bottomRadius, this->_height, 0, GREEN); + DrawCylinderWires(this->_position, this->_topRadius, this->_bottomRadius, this->_height, 0, this->_debugColor); } } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/3D/Sphere.cpp b/lib/Ray/sources/Drawables/3D/Sphere.cpp index 2949606e..f87c3fa5 100644 --- a/lib/Ray/sources/Drawables/3D/Sphere.cpp +++ b/lib/Ray/sources/Drawables/3D/Sphere.cpp @@ -33,6 +33,6 @@ namespace RAY::Drawables::Drawables3D void Sphere::drawWiresOn(RAY::Window &) { - DrawSphereWires(this->_position, this->_radius, 10, 10, GREEN); + DrawSphereWires(this->_position, this->_radius, 10, 10, this->_debugColor); } } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/ADrawable3D.hpp b/lib/Ray/sources/Drawables/ADrawable3D.hpp index 4c82ded6..3c52f5de 100644 --- a/lib/Ray/sources/Drawables/ADrawable3D.hpp +++ b/lib/Ray/sources/Drawables/ADrawable3D.hpp @@ -52,6 +52,9 @@ namespace RAY::Drawables { //! @brief Color of the ADrawable Color _color; + //! @brief Color of the ADrawable's Debug + Color _debugColor = GREEN; + }; }; diff --git a/lib/Ray/sources/Model/Model.cpp b/lib/Ray/sources/Model/Model.cpp index 2239c359..fefa29ea 100644 --- a/lib/Ray/sources/Model/Model.cpp +++ b/lib/Ray/sources/Model/Model.cpp @@ -124,7 +124,7 @@ namespace RAY::Drawables::Drawables3D box.max.x += this->_position.x; box.max.y += this->_position.y; box.max.z += this->_position.z; - DrawBoundingBox(box, GREEN); + DrawBoundingBox(box, this->_debugColor); } } From ad6b5d133aa15bf2b7c3b08ddf14cabf3c14d734 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Mon, 14 Jun 2021 11:52:55 +0200 Subject: [PATCH 10/12] square drawning quicker --- .../IntroAnimation/IntroAnimationSystem.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sources/System/IntroAnimation/IntroAnimationSystem.cpp b/sources/System/IntroAnimation/IntroAnimationSystem.cpp index c5671987..887a11d8 100644 --- a/sources/System/IntroAnimation/IntroAnimationSystem.cpp +++ b/sources/System/IntroAnimation/IntroAnimationSystem.cpp @@ -49,7 +49,7 @@ namespace BBM topRectangle.getComponent().drawable->setColor(BLACK); else topRectangle.getComponent().drawable->setColor(WHITE); - if (component.frameCounter == 60) { + if (component.frameCounter >= 60) { component.currentStep = IntroAnimationComponent::animationSteps::topLeftgrowing; component.frameCounter = -1; topRectangle.getComponent().drawable->setColor(BLACK); @@ -58,10 +58,10 @@ namespace BBM break; case IntroAnimationComponent::animationSteps::topLeftgrowing: rectangle = dynamic_cast(leftRectangle.getComponent().drawable.get()); - rectangle->incrementHeight(4); + rectangle->incrementHeight(8); rectangle = dynamic_cast(topRectangle.getComponent().drawable.get()); - rectangle->incrementWidth(4); - if (rectangle->getWidth() == 256) { + rectangle->incrementWidth(8); + if (rectangle->getWidth() >= 256) { component.currentStep = IntroAnimationComponent::animationSteps::bottomRightGrowing; bottomRectangle.getComponent().position = Vector3f(1920 / 2 - 128, 1080 / 2 - 128 + 240, 0); rightRectangle.getComponent().position = Vector3f(1920 / 2 - 128 + 240, 1080 / 2 - 128, 0); @@ -69,16 +69,16 @@ namespace BBM break; case IntroAnimationComponent::animationSteps::bottomRightGrowing: rectangle = dynamic_cast(bottomRectangle.getComponent().drawable.get()); - rectangle->incrementWidth(4); + rectangle->incrementWidth(8); rectangle = dynamic_cast(rightRectangle.getComponent().drawable.get()); - rectangle->incrementHeight(4); - if (rectangle->getHeight() == 256) { + rectangle->incrementHeight(8); + if (rectangle->getHeight() >= 256) { component.currentStep = IntroAnimationComponent::animationSteps::lettersTyping; component.frameCounter = 0; } break; case IntroAnimationComponent::animationSteps::lettersTyping: - if ((component.frameCounter / 15) % 2) { + if ((component.frameCounter / 10) % 2) { letterCounter++; text = dynamic_cast(rayText.getComponent().drawable.get()); if (letterCounter == 2) { From a36ab11b6d38e94321d9e9e7af3b56715712b379 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Mon, 14 Jun 2021 13:59:05 +0200 Subject: [PATCH 11/12] draws bounding box + contours --- sources/System/Renderer/RenderSystem.cpp | 21 +++++++++++++++++---- sources/System/Renderer/RenderSystem.hpp | 4 ++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/sources/System/Renderer/RenderSystem.cpp b/sources/System/Renderer/RenderSystem.cpp index d901b115..b6a6e735 100644 --- a/sources/System/Renderer/RenderSystem.cpp +++ b/sources/System/Renderer/RenderSystem.cpp @@ -11,8 +11,8 @@ #include #include "Drawables/ADrawable3D.hpp" #include "Component/Shaders/ShaderComponent.hpp" - - +#include +#include "Models/Vector3.hpp" #include "Component/Collision/CollisionComponent.hpp" namespace BBM @@ -26,6 +26,19 @@ namespace BBM this->_window.setFPS(this->FPS); } + void RenderSystem::drawBoundingBox(const WAL::Entity &entity, const PositionComponent &posComponent, const Drawable3DComponent &drawable) const + { + auto *dimsComponent = entity.tryGetComponent(); + + //draws hitbox + if (dimsComponent) { + RAY::Drawables::Drawables3D::Cube boundingBox(posComponent.position, dimsComponent->bound, WHITE); + boundingBox.drawWiresOn(this->_window); + } + //draws models contours + drawable.drawable->drawWiresOn(this->_window); + } + void RenderSystem::onSelfUpdate() { this->_camera.update(); @@ -39,9 +52,9 @@ namespace BBM if (modelShader) modelShader->model->setShader(modelShader->getShader()); drawable.drawable->setPosition(pos.position); - drawable.drawable->drawOn(this->_window); if (this->_debugMode) - drawable.drawable->drawWiresOn(this->_window); + this->drawBoundingBox(entity, pos, drawable); + drawable.drawable->drawOn(this->_window); if (modelShader) modelShader->model->resetShader(); } diff --git a/sources/System/Renderer/RenderSystem.hpp b/sources/System/Renderer/RenderSystem.hpp index e790a741..bff17267 100644 --- a/sources/System/Renderer/RenderSystem.hpp +++ b/sources/System/Renderer/RenderSystem.hpp @@ -6,6 +6,7 @@ #include "Component/Renderer/CameraComponent.hpp" #include "Component/Position/PositionComponent.hpp" +#include "Component/Renderer/Drawable3DComponent.hpp" #include "System/System.hpp" #include "Camera/Camera2D.hpp" #include "Window.hpp" @@ -39,6 +40,9 @@ namespace BBM //! @param debug true if debug mode should be enabled void setDebug(bool debug); + //! @param entity entity to draw bounding box of + void drawBoundingBox(const WAL::Entity &entity, const PositionComponent &posComponent, const Drawable3DComponent &drawable) const; + //! @brief ctor RenderSystem(WAL::Wal &wal, RAY::Window &window, bool debugMode = false); //! @brief Default copy ctor From a229452dc40bbe1300bcfd54473d19a50196b9c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Mon, 14 Jun 2021 14:41:04 +0200 Subject: [PATCH 12/12] adding red color for collisions boxes --- lib/Ray/sources/Drawables/ADrawable3D.cpp | 11 +++++++++++ lib/Ray/sources/Drawables/ADrawable3D.hpp | 8 +++++++- sources/Map/Map.cpp | 2 +- sources/System/Renderer/RenderSystem.cpp | 5 +++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/Ray/sources/Drawables/ADrawable3D.cpp b/lib/Ray/sources/Drawables/ADrawable3D.cpp index fabc12fd..2d7cfaf2 100644 --- a/lib/Ray/sources/Drawables/ADrawable3D.cpp +++ b/lib/Ray/sources/Drawables/ADrawable3D.cpp @@ -39,4 +39,15 @@ namespace RAY::Drawables void ADrawable3D::drawWiresOn(RAY::Window &) {} + + const RAY::Color &ADrawable3D::getDebugColor(void) const + { + return this->_debugColor; + } + + ADrawable3D &ADrawable3D::setDebugColor(const Color &debugColor) + { + this->_debugColor = debugColor; + return *this; + } } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/ADrawable3D.hpp b/lib/Ray/sources/Drawables/ADrawable3D.hpp index 3c52f5de..58aa5359 100644 --- a/lib/Ray/sources/Drawables/ADrawable3D.hpp +++ b/lib/Ray/sources/Drawables/ADrawable3D.hpp @@ -35,10 +35,16 @@ namespace RAY::Drawables { //! @return the color of the ADrawable const RAY::Color &getColor(void) const; - + //! @brief set color ADrawable3D &setColor(const RAY::Color &color); + //! @return the debug color of the ADrawable + const RAY::Color &getDebugColor(void) const; + + //! @brief set the debug color + ADrawable3D &setDebugColor(const RAY::Color &debugColor); + //! @return the position of the ADrawable virtual const RAY::Vector3 &getPosition(void) const; diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index 9bdc22ae..49841dda 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -165,7 +165,7 @@ namespace BBM for (int i = 0; i < width + 1; i++) { for (int j = 0; j < height + 1; j++) { if (map[std::make_tuple(i, 0, j)] != HOLE && map[std::make_tuple(i, -1, j)] != BUMPER) - scene->addEntity("Unbreakable Wall") + scene->addEntity("Floor") .addComponent(Vector3f(i, -1, j)) .addComponent(floorObj, false, std::make_pair(MAP_DIFFUSE, floorPng)); diff --git a/sources/System/Renderer/RenderSystem.cpp b/sources/System/Renderer/RenderSystem.cpp index b6a6e735..d21065c2 100644 --- a/sources/System/Renderer/RenderSystem.cpp +++ b/sources/System/Renderer/RenderSystem.cpp @@ -33,6 +33,7 @@ namespace BBM //draws hitbox if (dimsComponent) { RAY::Drawables::Drawables3D::Cube boundingBox(posComponent.position, dimsComponent->bound, WHITE); + boundingBox.setDebugColor(RED); boundingBox.drawWiresOn(this->_window); } //draws models contours @@ -52,11 +53,11 @@ namespace BBM if (modelShader) modelShader->model->setShader(modelShader->getShader()); drawable.drawable->setPosition(pos.position); - if (this->_debugMode) - this->drawBoundingBox(entity, pos, drawable); drawable.drawable->drawOn(this->_window); if (modelShader) modelShader->model->resetShader(); + if (this->_debugMode) + this->drawBoundingBox(entity, pos, drawable); } this->_window.unuseCamera();