diff --git a/CMakeLists.txt b/CMakeLists.txt index 59d1ba31..64299c95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,6 +119,17 @@ set(SOURCES sources/System/BumperTimer/BumperTimerSystem.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 + 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 sources/main.cpp diff --git a/assets/sounds/splash_sound.ogg b/assets/sounds/splash_sound.ogg new file mode 100644 index 00000000..d9092e53 Binary files /dev/null and b/assets/sounds/splash_sound.ogg differ 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/lib/Ray/sources/Drawables/3D/Cube.cpp b/lib/Ray/sources/Drawables/3D/Cube.cpp index 6f651a15..1af236d1 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, this->_debugColor); + } } \ 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..8e2ff386 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, this->_debugColor); + } } \ 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..f87c3fa5 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, this->_debugColor); + } } \ 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..2d7cfaf2 100644 --- a/lib/Ray/sources/Drawables/ADrawable3D.cpp +++ b/lib/Ray/sources/Drawables/ADrawable3D.cpp @@ -36,4 +36,18 @@ namespace RAY::Drawables this->_position = position; return *this; } + + 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 cc989fed..58aa5359 100644 --- a/lib/Ray/sources/Drawables/ADrawable3D.hpp +++ b/lib/Ray/sources/Drawables/ADrawable3D.hpp @@ -30,12 +30,21 @@ 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; - + //! @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; @@ -49,6 +58,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 9fd5b31e..fefa29ea 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, this->_debugColor); + } + } + 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/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..0def3a25 --- /dev/null +++ b/sources/Component/IntroAnimation/IntroAnimationComponent.hpp @@ -0,0 +1,39 @@ +#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 frameCounter = 0; + + enum animationSteps { + boxBlinking, + topLeftgrowing, + bottomRightGrowing, + lettersTyping, + fading, + prompt, + }; + + enum animationSteps currentStep = boxBlinking; + + //! @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/Map/Map.cpp b/sources/Map/Map.cpp index 9af4cc26..85967077 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -9,6 +9,7 @@ #include #include #include +#include "Component/Movable/MovableComponent.hpp" #include #include #include @@ -81,6 +82,7 @@ namespace BBM wal.getScene()->scheduleNewEntity("Bonus") .addComponent(position) .addComponent>() + .addComponent() .addComponent(1, [](WAL::Entity &entity, WAL::Wal &wal) { entity.scheduleDeletion(); }) @@ -193,7 +195,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/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/Models/Vector3.hpp b/sources/Models/Vector3.hpp index a2266e07..8e8b4093 100644 --- a/sources/Models/Vector3.hpp +++ b/sources/Models/Vector3.hpp @@ -173,6 +173,11 @@ namespace BBM return Vector3(std::round(this->x), std::round(this->y), std::round(this->z)); } + [[nodiscard]] bool isNull() const + { + return this->x == 0 && this->y == 0 && this->z == 0; + } + operator RAY::Vector3() const requires(std::is_same_v) { return RAY::Vector3(this->x, this->y, this->z); 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/GameScene.cpp b/sources/Runner/GameScene.cpp new file mode 100644 index 00000000..7668a043 --- /dev/null +++ b/sources/Runner/GameScene.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/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 "Component/Gravity/GravityComponent.hpp" +#include "Component/BumperTimer/BumperTimerComponent.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(0, 1.01, 0) + .addComponent("assets/player/player.iqm", true, std::make_pair(MAP_DIFFUSE, "assets/player/blue.png")) + .addComponent() + .addComponent() + .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/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 a981c9a2..05ddb71e 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,27 +21,19 @@ #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" -#include "Component/Gravity/GravityComponent.hpp" #include "System/Gravity/GravitySystem.hpp" -#include "Component/BumperTimer/BumperTimerComponent.hpp" #include "System/BumperTimer/BumperTimerSystem.hpp" +#include "System/Music/MusicSystem.hpp" namespace RAY3D = RAY::Drawables::Drawables3D; namespace RAY2D = RAY::Drawables::Drawables2D; @@ -62,11 +46,14 @@ namespace BBM { if (RAY::Window::getInstance().shouldClose()) engine.shouldClose = true; - if (gameState.currentScene == GameState::SceneID::GameScene) { + if (gameState.currentScene == GameState::SceneID::GameScene || gameState.currentScene == GameState::SceneID::SplashScreen) { for (auto &[_, component]: engine.getScene()->view()) { - 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; } } } @@ -91,11 +78,12 @@ namespace BBM .addSystem() .addSystem() .addSystem() - .addSystem() - .addSystem() .addSystem() .addSystem() .addSystem() + .addSystem() + .addSystem() + .addSystem() .addSystem(); } @@ -108,508 +96,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 = { - {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; - } - - 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(0, 1.01, 0) - .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() - .addComponent() - .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, 25, 7) - .addComponent(Vector3f(8, 0, 8)); - MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16, true, false), scene); - - 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; - } - void Runner::loadScenes() { gameState._loadedScenes[GameState::SceneID::MainMenuScene] = loadMainMenuScene(); @@ -618,6 +104,7 @@ namespace BBM gameState._loadedScenes[GameState::SceneID::PauseMenuScene] = loadPauseMenuScene(); gameState._loadedScenes[GameState::SceneID::TitleScreenScene] = loadTitleScreenScene(); gameState._loadedScenes[GameState::SceneID::CreditScene] = loadCreditScene(); + gameState._loadedScenes[GameState::SceneID::SplashScreen] = loadSplashScreenScene(); } int Runner::run() @@ -627,7 +114,7 @@ namespace BBM Runner::addSystems(wal); Runner::enableRaylib(wal); Runner::loadScenes(); - wal.changeScene(Runner::gameState._loadedScenes[GameState::SceneID::TitleScreenScene]); + wal.changeScene(Runner::gameState._loadedScenes[GameState::SceneID::SplashScreen]); try { wal.run(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(); }; 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 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 diff --git a/sources/System/BombHolder/BombHolderSystem.cpp b/sources/System/BombHolder/BombHolderSystem.cpp index d91c2a27..6fe1055d 100644 --- a/sources/System/BombHolder/BombHolderSystem.cpp +++ b/sources/System/BombHolder/BombHolderSystem.cpp @@ -22,23 +22,25 @@ namespace BBM std::chrono::nanoseconds BombHolderSystem::explosionTimer = 2s; void BombHolderSystem::_bombCollide(WAL::Entity &entity, - const WAL::Entity &bomb, - CollisionComponent::CollidedAxis collidedAxis) + const WAL::Entity &bomb, + CollisionComponent::CollidedAxis collidedAxis) { auto &bombInfo = bomb.getComponent(); if (bombInfo.ignoreOwner && bombInfo.ownerID == entity.getUid()) return; - return MapGenerator::wallCollided( entity, bomb, collidedAxis); + return MapGenerator::wallCollided(entity, bomb, collidedAxis); } - BombHolderSystem::BombHolderSystem(WAL::Wal &wal) : System(wal) {} - void BombHolderSystem::_dispatchExplosion(Vector3f position, WAL::Wal &wal, int count) + void BombHolderSystem::_dispatchExplosion(const Vector3f &position, + WAL::Wal &wal, + int size, + ExpansionDirection expansionDirections) { - if (count <= 0) + if (size <= 0) return; wal.getScene()->scheduleNewEntity("explosion") .addComponent(position) @@ -46,8 +48,11 @@ namespace BBM explosion.scheduleDeletion(); }) .addComponent("assets/bombs/explosion/explosion.glb", false, - std::make_pair(MAP_DIFFUSE, "assets/bombs/explosion/blast.png")); - wal.getSystem().dispatchEvent([position, count](WAL::Wal &wal) { + std::make_pair( + MAP_DIFFUSE, + "assets/bombs/explosion/blast.png" + )); + wal.getSystem().dispatchEvent([position, size, expansionDirections](WAL::Wal &wal) { for (auto &[entity, pos, _] : wal.getScene()->view>()) { if (pos.position.round() == position) { if (auto *health = entity.tryGetComponent()) @@ -55,10 +60,18 @@ namespace BBM return; } } - _dispatchExplosion(position + Vector3f(1, 0, 0), wal, count - 1); - _dispatchExplosion(position + Vector3f(-1, 0, 0), wal, count - 1); - _dispatchExplosion(position + Vector3f(0, 0, 1), wal, count - 1); - _dispatchExplosion(position + Vector3f(0, 0, -1), wal, count - 1); + if (expansionDirections & ExpansionDirection::FRONT) { + _dispatchExplosion(position + Vector3f{1, 0, 0}, wal, size - 1, ExpansionDirection::FRONT); + } + if (expansionDirections & ExpansionDirection::BACK) { + _dispatchExplosion(position + Vector3f{-1, 0, 0}, wal, size - 1, ExpansionDirection::BACK); + } + if (expansionDirections & ExpansionDirection::LEFT) { + _dispatchExplosion(position + Vector3f{0, 0, 1}, wal, size - 1, ExpansionDirection::LEFT); + } + if (expansionDirections & ExpansionDirection::RIGHT) { + _dispatchExplosion(position + Vector3f{0, 0, -1}, wal, size - 1, ExpansionDirection::RIGHT); + } }); } @@ -67,7 +80,7 @@ namespace BBM bomb.scheduleDeletion(); auto position = bomb.getComponent().position.round(); auto explosionRadius = bomb.getComponent().explosionRadius; - _dispatchExplosion(position, wal, 3 + (explosionRadius - 3)); + _dispatchExplosion(position, wal, explosionRadius); } void BombHolderSystem::_spawnBomb(Vector3f position, BombHolderComponent &holder, unsigned id) @@ -76,16 +89,21 @@ namespace BBM .addComponent(position.round()) .addComponent(holder.damage, holder.explosionRadius, id) .addComponent(BombHolderSystem::explosionTimer, &BombHolderSystem::_bombExplosion) - .addComponent(WAL::Callback(), - &BombHolderSystem::_bombCollide, 0.25, .75) + .addComponent( + WAL::Callback(), + &BombHolderSystem::_bombCollide, 0.25, .75) .addComponent("assets/bombs/bomb.obj", false, - std::make_pair(MAP_DIFFUSE, "assets/bombs/bomb_normal.png")); + std::make_pair( + MAP_DIFFUSE, + "assets/bombs/bomb_normal.png" + )); holder.damage = 1; holder.explosionRadius = 3; } - void BombHolderSystem::onUpdate(WAL::ViewEntity &entity, - std::chrono::nanoseconds dtime) + void + BombHolderSystem::onUpdate(WAL::ViewEntity &entity, + std::chrono::nanoseconds dtime) { auto &holder = entity.get(); auto &position = entity.get(); diff --git a/sources/System/BombHolder/BombHolderSystem.hpp b/sources/System/BombHolder/BombHolderSystem.hpp index 6d26435e..c5631190 100644 --- a/sources/System/BombHolder/BombHolderSystem.hpp +++ b/sources/System/BombHolder/BombHolderSystem.hpp @@ -14,6 +14,22 @@ namespace BBM { + enum ExpansionDirection + { + UP = 1, + DOWN = 2, + LEFT = 4, + RIGHT = 8, + FRONT = 16, + BACK = 32 + }; + + //! @brief Ta avoid explicit casting + inline ExpansionDirection operator|(ExpansionDirection a, ExpansionDirection b) + { + return static_cast(static_cast(a) | static_cast(b)); + } + //! @brief The system that allow one to place bombs. class BombHolderSystem : public WAL::System { @@ -22,13 +38,23 @@ namespace BBM void _spawnBomb(Vector3f position, BombHolderComponent &holder, unsigned id); //! @brief Spawn a bomb at the specified position. - static void _dispatchExplosion(Vector3f position, WAL::Wal &, int count); + static void _dispatchExplosion(const Vector3f &position, + WAL::Wal &wal, + int size, + ExpansionDirection expansionDirections = ExpansionDirection::DOWN + | ExpansionDirection::UP + | ExpansionDirection::FRONT + | ExpansionDirection::BACK + | ExpansionDirection::LEFT + | ExpansionDirection::RIGHT); //! @brief The method triggered when the bomb explode. static void _bombExplosion(WAL::Entity &bomb, WAL::Wal &); //! @brief The method called when a player collide with a bomb. - static void _bombCollide(WAL::Entity &entity, const WAL::Entity &wall, BBM::CollisionComponent::CollidedAxis collidedAxis); + static void + _bombCollide(WAL::Entity &entity, const WAL::Entity &wall, BBM::CollisionComponent::CollidedAxis collidedAxis); + public: //! @brief The explosion time of new bombs. static std::chrono::nanoseconds explosionTimer; @@ -39,10 +65,13 @@ namespace BBM //! @brief A default constructor explicit BombHolderSystem(WAL::Wal &wal); + //! @brief A bomb holder system is copy constructable BombHolderSystem(const BombHolderSystem &) = default; + //! @brief A default destructor ~BombHolderSystem() override = default; + //! @brief A bomb holder system is not assignable. BombHolderSystem &operator=(const BombHolderSystem &) = delete; }; diff --git a/sources/System/Collision/CollisionSystem.cpp b/sources/System/Collision/CollisionSystem.cpp index 9054c776..f2604254 100644 --- a/sources/System/Collision/CollisionSystem.cpp +++ b/sources/System/Collision/CollisionSystem.cpp @@ -23,7 +23,7 @@ namespace BBM return (overlapX && overlapY && overlapZ); } - void CollisionSystem::onFixedUpdate(WAL::ViewEntity &entity) + void CollisionSystem::onFixedUpdate(WAL::ViewEntity &entity) { unsigned int entityUid = entity->getUid(); auto &posA = entity.get(); @@ -32,31 +32,34 @@ namespace BBM Vector3f pointAx = pointA; Vector3f pointAy = pointA; Vector3f pointAz = pointA; - bool isMovable = false; - Vector3f minAy; - Vector3f maxAy; - Vector3f minAz; - Vector3f maxAz; - if (auto *movable = entity->tryGetComponent()) { - auto vel = movable->getVelocity(); + auto &movable = entity.get(); + const auto &vel = movable.getVelocity(); + + if (!vel.isNull()) { pointAx.x += vel.x; pointAy.y += vel.y; pointAz.z += vel.z; - isMovable = true; } Vector3f minAx = Vector3f::min(pointAx, pointAx + colA.bound); Vector3f maxAx = Vector3f::max(pointAx, pointAx + colA.bound); - if (isMovable) { + Vector3f minAy; + Vector3f maxAy; + + Vector3f minAz; + Vector3f maxAz; + + if (!vel.isNull()) { minAy = Vector3f::min(pointAy, pointAy + colA.bound); maxAy = Vector3f::max(pointAy, pointAy + colA.bound); minAz = Vector3f::min(pointAz, pointAz + colA.bound); maxAz = Vector3f::max(pointAz, pointAz + colA.bound); } - for (auto &[other, posB, colB] : this->getView()) { + + for (auto &[other, posB, colB] : this->_wal.getScene()->view()) { if (other.getUid() == entityUid) continue; @@ -67,9 +70,9 @@ namespace BBM Vector3f maxB = Vector3f::max(pointB, pointB + colB.bound); if (boxesCollide(minAx, maxAx, minB, maxB)) { - collidedAxis += isMovable ? CollisionComponent::CollidedAxis::X : 7; + collidedAxis += vel.isNull() ? 7 : CollisionComponent::CollidedAxis::X; } - if (isMovable) { + if (!vel.isNull()) { if (boxesCollide(minAy, maxAy, minB, maxB)) { collidedAxis += CollisionComponent::CollidedAxis::Y; } diff --git a/sources/System/Collision/CollisionSystem.hpp b/sources/System/Collision/CollisionSystem.hpp index e1e75ede..d7d31595 100644 --- a/sources/System/Collision/CollisionSystem.hpp +++ b/sources/System/Collision/CollisionSystem.hpp @@ -10,16 +10,17 @@ #include "System/System.hpp" #include "Models/Vector3.hpp" #include "Component/Collision/CollisionComponent.hpp" +#include "Component/Movable/MovableComponent.hpp" #include "Component/Position/PositionComponent.hpp" namespace BBM { //! @brief A system to handle collisions. - class CollisionSystem : public WAL::System + class CollisionSystem : public WAL::System { public: //! @inherit - void onFixedUpdate(WAL::ViewEntity &entity) override; + void onFixedUpdate(WAL::ViewEntity &entity) override; //! @brief A default constructor explicit CollisionSystem(WAL::Wal &wal); diff --git a/sources/System/IntroAnimation/IntroAnimationSystem.cpp b/sources/System/IntroAnimation/IntroAnimationSystem.cpp new file mode 100644 index 00000000..887a11d8 --- /dev/null +++ b/sources/System/IntroAnimation/IntroAnimationSystem.cpp @@ -0,0 +1,103 @@ + +#include "Component/Button/ButtonComponent.hpp" +#include "Component/Position/PositionComponent.hpp" +#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; + +namespace BBM +{ + IntroAnimationSystem::IntroAnimationSystem(WAL::Wal &wal) + : System(wal), wal(wal) + {} + + 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(); + 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); + 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); + static short letterCounter = 0; + + switch (component.currentStep) + { + case IntroAnimationComponent::animationSteps::boxBlinking: + if ((component.frameCounter / 15) % 2) + topRectangle.getComponent().drawable->setColor(BLACK); + else + topRectangle.getComponent().drawable->setColor(WHITE); + if (component.frameCounter >= 60) { + 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(8); + rectangle = dynamic_cast(topRectangle.getComponent().drawable.get()); + 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); + } + break; + case IntroAnimationComponent::animationSteps::bottomRightGrowing: + rectangle = dynamic_cast(bottomRectangle.getComponent().drawable.get()); + rectangle->incrementWidth(8); + rectangle = dynamic_cast(rightRectangle.getComponent().drawable.get()); + rectangle->incrementHeight(8); + if (rectangle->getHeight() >= 256) { + component.currentStep = IntroAnimationComponent::animationSteps::lettersTyping; + component.frameCounter = 0; + } + break; + case IntroAnimationComponent::animationSteps::lettersTyping: + if ((component.frameCounter / 10) % 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; + } + component.frameCounter++; + } + + 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 diff --git a/sources/System/Renderer/RenderSystem.cpp b/sources/System/Renderer/RenderSystem.cpp index 07b64134..d21065c2 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,20 @@ 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.setDebugColor(RED); + boundingBox.drawWiresOn(this->_window); + } + //draws models contours + drawable.drawable->drawWiresOn(this->_window); + } + void RenderSystem::onSelfUpdate() { this->_camera.update(); @@ -42,6 +56,8 @@ namespace BBM drawable.drawable->drawOn(this->_window); if (modelShader) modelShader->model->resetShader(); + if (this->_debugMode) + this->drawBoundingBox(entity, pos, drawable); } this->_window.unuseCamera(); @@ -59,7 +75,7 @@ namespace BBM } } if (this->_debugMode) - this->_window.drawFPS(Vector2f()); + this->_window.drawFPS(Vector2f(10, 10)); this->_window.endDrawing(); } 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 diff --git a/tests/CollisionTest.cpp b/tests/CollisionTest.cpp index bf5a31dc..6c0795c4 100644 --- a/tests/CollisionTest.cpp +++ b/tests/CollisionTest.cpp @@ -17,6 +17,8 @@ using namespace WAL; using namespace BBM; +// WARN THE COLLISION SYSTEM IS ONLY CHECKING/LOOPING ON MOVABLE ENTITIES + TEST_CASE("Collision test", "[Component][System]") { @@ -25,6 +27,7 @@ TEST_CASE("Collision test", "[Component][System]") wal.changeScene(std::make_shared()); wal.getScene()->addEntity("player") .addComponent() + .addComponent() .addComponent([](Entity &actual, const Entity &, int _) { try { auto &pos = actual.getComponent(); @@ -118,6 +121,7 @@ TEST_CASE("Collision test callbacks calls", "[Component][System]") wal.getScene()->addEntity("block") .addComponent(0, 0, 0) + .addComponent() .addComponent( [&nbCallbacksCalled](Entity &actual, const Entity &, int) { nbCallbacksCalled++; }, [&nbCallbacksCalled](Entity &actual, const Entity &, int) { @@ -156,6 +160,7 @@ TEST_CASE("Collision test callbacks args", "[Component][System]") wal.getScene()->addEntity("player") .addComponent() + .addComponent() .addComponent( [&nbCallbacksCalled](Entity &actual, const Entity &other, int) { nbCallbacksCalled++; @@ -170,6 +175,7 @@ TEST_CASE("Collision test callbacks args", "[Component][System]") wal.getScene()->addEntity("block") .addComponent(0, 0, 0) + .addComponent() .addComponent( [&nbCallbacksCalled](Entity &actual, const Entity &other, int) { nbCallbacksCalled++; @@ -193,6 +199,57 @@ TEST_CASE("Collision test callbacks args", "[Component][System]") REQUIRE(nbCallbacksCalled == 4); } +TEST_CASE("Collision test callbacks args with only one movable entity", "[Component][System]") +{ + int nbCallbacksCalled = 0; + Wal wal; + CollisionSystem collision(wal); + MovableSystem movable(wal); + + wal.changeScene(std::make_shared()); + + wal.getScene()->addEntity("player") + .addComponent() + .addComponent() + .addComponent( + [&nbCallbacksCalled](Entity &actual, const Entity &other, int) { + nbCallbacksCalled++; + REQUIRE(actual.getName() == "player"); + REQUIRE(other.getName() == "block"); + }, + [&nbCallbacksCalled](Entity &actual, const Entity &other, int) { + // lambda should not be called + nbCallbacksCalled++; + REQUIRE(other.getName() == "plfayer"); + REQUIRE(actual.getName() == "blofck"); + }, 0, 5.0); + + wal.getScene()->addEntity("block") + .addComponent(0, 0, 0) + .addComponent( + [&nbCallbacksCalled](Entity &actual, const Entity &other, int) { + // lambda should not be called + nbCallbacksCalled++; + REQUIRE(other.getName() == "playefr"); + REQUIRE(actual.getName() == "blocfk"); + }, + [&nbCallbacksCalled](Entity &actual, const Entity &other, int) { + nbCallbacksCalled++; + REQUIRE(actual.getName() == "player"); + REQUIRE(other.getName() == "block"); + }, 0, 1); + Entity &entity = wal.getScene()->getEntities().front(); + REQUIRE(entity.getComponent().position == Vector3f()); + + entity.getComponent().bound.x = 5; + entity.getComponent().bound.y = 5; + entity.getComponent().bound.z = 5; + + collision.update(std::chrono::nanoseconds(1)); + collision.fixedUpdate(); + REQUIRE(nbCallbacksCalled == 2); +} + TEST_CASE("Vector round", "[Vector]") { Vector3f v(1.3, 1.5, 1.7);