diff --git a/assets/background_game.png b/assets/background_game.png new file mode 100644 index 00000000..e1c52b4d Binary files /dev/null and b/assets/background_game.png differ diff --git a/lib/Ray/sources/Drawables/Image.hpp b/lib/Ray/sources/Drawables/Image.hpp index 7963328d..0ababe08 100644 --- a/lib/Ray/sources/Drawables/Image.hpp +++ b/lib/Ray/sources/Drawables/Image.hpp @@ -21,7 +21,7 @@ namespace RAY public: //! @brief Create an image, loading a file //! @param filename: path to file to load - //! @param lonely: should be set to true if the entity's loaded data must be independant from others + //! @param lonely: should be set to true if the entity's loaded data must be independent from others Image(const std::string &filename, bool lonely = false); //! @brief A default copy constructor diff --git a/sources/Component/Renderer/Drawable2DComponent.hpp b/sources/Component/Renderer/Drawable2DComponent.hpp index 227eacd6..f57e9863 100644 --- a/sources/Component/Renderer/Drawable2DComponent.hpp +++ b/sources/Component/Renderer/Drawable2DComponent.hpp @@ -14,27 +14,32 @@ namespace BBM class Drawable2DComponent : public WAL::Component { public: + //! @brief Tells the renderer to draw in a particular order + bool drawBefore3D = false; + //! @brief The type of the component std::shared_ptr drawable; //! @brief ctor - Drawable2DComponent(WAL::Entity &entity, std::shared_ptr drawable) + Drawable2DComponent(WAL::Entity &entity, std::shared_ptr drawable, bool drawBefore3D = false) : WAL::Component(entity), - drawable(std::move(drawable)) + drawable(std::move(drawable)), + drawBefore3D(drawBefore3D) {} //! ctor template - explicit Drawable2DComponent(WAL::Entity &entity, WAL::TypeHolder, Params &&...params) + explicit Drawable2DComponent(WAL::Entity &entity, WAL::TypeHolder, bool drawBefore3D, Params &&...params) : WAL::Component(entity), - drawable(new T(std::forward(params)...)) + drawable(new T(std::forward(params)...)), + drawBefore3D(drawBefore3D) {} //! @brief Clone a component for another or the same entity. //! @param entity The entity that owns the ne component. WAL::Component *clone(WAL::Entity &entity) const override { - return new Drawable2DComponent(entity, this->drawable); + return new Drawable2DComponent(entity, this->drawable, this->drawBefore3D); } //! @brief Default copy ctor diff --git a/sources/Runner/CreditScene.cpp b/sources/Runner/CreditScene.cpp index 38c9b77e..6bce5029 100644 --- a/sources/Runner/CreditScene.cpp +++ b/sources/Runner/CreditScene.cpp @@ -25,7 +25,7 @@ namespace BBM scene->addEntity("background") .addComponent() - .addComponent("assets/plain_menu_background.png"); + .addComponent(false, "assets/plain_menu_background.png"); scene->addEntity("Control entity") .addComponent() @@ -35,22 +35,22 @@ namespace BBM auto &raylibLogo = scene->addEntity("raylib logo") .addComponent(1920 / 4, 1080 / 1.75, 0) - .addComponent("assets/raylib.png"); + .addComponent(false, "assets/raylib.png"); auto &raylibText = scene->addEntity("raylib text") .addComponent(1920 / 4, 1080 / 2, 0) - .addComponent("Powered by:", 35, RAY::Vector2(), BLACK); + .addComponent(false, "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); + .addComponent(false, "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); + .addComponent(false, "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); + .addComponent(false, "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(false, "assets/buttons/button_back.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; diff --git a/sources/Runner/GameScene.cpp b/sources/Runner/GameScene.cpp index 96478a8f..e506e258 100644 --- a/sources/Runner/GameScene.cpp +++ b/sources/Runner/GameScene.cpp @@ -18,6 +18,8 @@ #include "Component/Shaders/ShaderComponent.hpp" #include "Component/Tag/TagComponent.hpp" #include "Component/Renderer/Drawable3DComponent.hpp" +#include "Component/Renderer/Drawable2DComponent.hpp" +#include #include "Component/Button/ButtonComponent.hpp" #include "Drawables/2D/Text.hpp" #include "Component/Gravity/GravityComponent.hpp" @@ -63,6 +65,10 @@ namespace BBM auto &animation = entity.getComponent(); animation.setAnimIndex(5); }); + + scene->addEntity("background image") + .addComponent(true, "assets/background_game.png", false) + .addComponent(); scene->addEntity("camera") .addComponent(8, 20, 7) .addComponent(Vector3f(8, 0, 8)); diff --git a/sources/Runner/MainMenuScene.cpp b/sources/Runner/MainMenuScene.cpp index 3a515c1e..3970b027 100644 --- a/sources/Runner/MainMenuScene.cpp +++ b/sources/Runner/MainMenuScene.cpp @@ -30,13 +30,13 @@ namespace BBM .addComponent(sounds); scene->addEntity("background") .addComponent() - .addComponent("assets/plain_menu_background.png"); + .addComponent(false, "assets/plain_menu_background.png"); scene->addEntity("logo") .addComponent(1920 / 3, 180, 0) - .addComponent("assets/logo_small.png"); + .addComponent(false, "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(false, "assets/buttons/button_new_game.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); @@ -55,7 +55,7 @@ namespace BBM }); auto &settings = scene->addEntity("settings button") .addComponent(1920 / 2.5, 1080 - 360, 0) - .addComponent("assets/buttons/button_settings.png") + .addComponent(false, "assets/buttons/button_settings.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); @@ -74,7 +74,7 @@ namespace BBM }); auto &exit = scene->addEntity("exit button") .addComponent(1920 / 2.5, 1080 - 180, 0) - .addComponent("assets/buttons/button_exit.png") + .addComponent(false, "assets/buttons/button_exit.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); @@ -93,7 +93,7 @@ namespace BBM }); auto &credits = scene->addEntity("credit button") .addComponent(1920 - 100, 1080 - 30, 0) - .addComponent("Credits", 20, RAY::Vector2(), BLACK) + .addComponent(false, "Credits", 20, RAY::Vector2(), BLACK) .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY2D::Text *text = dynamic_cast(entity.getComponent().drawable.get()); diff --git a/sources/Runner/PauseMenuScene.cpp b/sources/Runner/PauseMenuScene.cpp index ed674e3a..eb342de9 100644 --- a/sources/Runner/PauseMenuScene.cpp +++ b/sources/Runner/PauseMenuScene.cpp @@ -30,13 +30,13 @@ namespace BBM .addComponent(sounds); scene->addEntity("background") .addComponent() - .addComponent("assets/plain_menu_background.png"); + .addComponent(false, "assets/plain_menu_background.png"); scene->addEntity("pause text") .addComponent(1920 / 2.5, 180, 0) - .addComponent("PAUSE", 120, RAY::Vector2(), ORANGE); + .addComponent(false, "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(false, "assets/buttons/button_back.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); @@ -55,7 +55,7 @@ namespace BBM }); auto &settings = scene->addEntity("settings button") .addComponent(1920 / 2.5, 1080 - 360, 0) - .addComponent("assets/buttons/button_settings.png") + .addComponent(false, "assets/buttons/button_settings.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); @@ -74,7 +74,7 @@ namespace BBM }); auto &exit = scene->addEntity("exit button") .addComponent(1920 / 1.5, 1080 - 360, 0) - .addComponent("assets/buttons/button_exit.png") + .addComponent(false, "assets/buttons/button_exit.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); diff --git a/sources/Runner/SettingsMenuScene.cpp b/sources/Runner/SettingsMenuScene.cpp index 4d409aab..f4c47df4 100644 --- a/sources/Runner/SettingsMenuScene.cpp +++ b/sources/Runner/SettingsMenuScene.cpp @@ -31,13 +31,13 @@ namespace BBM .addComponent(sounds); scene->addEntity("background") .addComponent() - .addComponent("assets/plain_menu_background.png"); + .addComponent(false, "assets/plain_menu_background.png"); scene->addEntity("logo") .addComponent(1920 / 3, 180, 0) - .addComponent("assets/logo_small.png"); + .addComponent(false, "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(false, "Music Volume", 70, RAY::Vector2(), BLACK) .addComponent() .addComponent([](WAL::Entity &entity, WAL::Wal &) { @@ -50,7 +50,7 @@ namespace BBM auto &musicUp = scene->addEntity("music up button") .addComponent(1920 / 1.5, 1080 - 540, 0) - .addComponent("assets/buttons/button_plus.png") + .addComponent(false, "assets/buttons/button_plus.png") .addComponent("assets/musics/music_title.ogg") .addComponent([](WAL::Entity &entity, WAL::Wal &) { @@ -73,7 +73,7 @@ namespace BBM auto &musicDown = scene->addEntity("music down button") .addComponent(1920 / 3, 1080 - 540, 0) - .addComponent("assets/buttons/button_minus.png") + .addComponent(false, "assets/buttons/button_minus.png") .addComponent("assets/musics/music_title.ogg") .addComponent([](WAL::Entity &entity, WAL::Wal &) { @@ -96,7 +96,7 @@ namespace BBM auto &sound = scene->addEntity("sound text") .addComponent(1920 / 2.5, 1080 - 360, 0) - .addComponent("Sound Volume", 70, RAY::Vector2(), BLACK) + .addComponent(false, "Sound Volume", 70, RAY::Vector2(), BLACK) .addComponent() .addComponent([](WAL::Entity &entity, WAL::Wal &) { @@ -109,7 +109,7 @@ namespace BBM auto &soundUp = scene->addEntity("sound up button") .addComponent(1920 / 1.5, 1080 - 360, 0) - .addComponent("assets/buttons/button_plus.png") + .addComponent(false, "assets/buttons/button_plus.png") .addComponent(sounds) .addComponent([](WAL::Entity &entity, WAL::Wal &) { @@ -132,7 +132,7 @@ namespace BBM auto &soundDown = scene->addEntity("sound down button") .addComponent(1920 / 3, 1080 - 360, 0) - .addComponent("assets/buttons/button_minus.png") + .addComponent(false, "assets/buttons/button_minus.png") .addComponent(sounds) .addComponent([](WAL::Entity &entity, WAL::Wal &) { @@ -155,7 +155,7 @@ namespace BBM auto &debug = scene->addEntity("debug text") .addComponent(1920 / 2.5, 1080 - 180, 0) - .addComponent("Debug Mode: Off", 70, RAY::Vector2(), BLACK) + .addComponent(false, "Debug Mode: Off", 70, RAY::Vector2(), BLACK) .addComponent([](WAL::Entity &entity, WAL::Wal &wal) { RAY2D::Text *text = dynamic_cast(entity.getComponent().drawable.get()); @@ -178,7 +178,7 @@ namespace BBM }); auto &back = scene->addEntity("back to menu") .addComponent(10, 1080 - 85, 0) - .addComponent("assets/buttons/button_back.png") + .addComponent(false, "assets/buttons/button_back.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; diff --git a/sources/Runner/SplashScreenScene.cpp b/sources/Runner/SplashScreenScene.cpp index 455a0e95..86e62cc1 100644 --- a/sources/Runner/SplashScreenScene.cpp +++ b/sources/Runner/SplashScreenScene.cpp @@ -25,13 +25,13 @@ namespace BBM .addComponent(); auto &background = scene->addEntity("background") .addComponent(0, 0, 0) - .addComponent(RAY::Vector2(), RAY::Vector2(1920, 1080)); + .addComponent(false, 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); + .addComponent(false, "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); + .addComponent(false, "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 index 0cbbf488..2252cfe2 100644 --- a/sources/Runner/TitleScreenScene.cpp +++ b/sources/Runner/TitleScreenScene.cpp @@ -29,13 +29,13 @@ namespace BBM .addComponent("assets/musics/music_title.ogg"); scene->addEntity("background") .addComponent() - .addComponent("assets/plain_menu_background.png"); + .addComponent(false, "assets/plain_menu_background.png"); scene->addEntity("logo") .addComponent(320, 180, 0) - .addComponent("assets/logo_big.png"); + .addComponent(false, "assets/logo_big.png"); scene->addEntity("text_prompt") .addComponent(1920 / 2.5, 1080 - 130, 0) - .addComponent("Press space", 70, RAY::Vector2(), BLACK) + .addComponent(false, "Press space", 70, RAY::Vector2(), BLACK) .addComponent() .addComponent() .addComponent([](WAL::Entity &entity, WAL::Wal &) diff --git a/sources/System/IntroAnimation/IntroAnimationSystem.cpp b/sources/System/IntroAnimation/IntroAnimationSystem.cpp index 887a11d8..13b56f8b 100644 --- a/sources/System/IntroAnimation/IntroAnimationSystem.cpp +++ b/sources/System/IntroAnimation/IntroAnimationSystem.cpp @@ -27,19 +27,19 @@ namespace BBM RAY2D::Text *text = nullptr; static auto &rayText = scene->addEntity("raylibtext Rectangle") .addComponent(1920 / 2 - 44, 1080 / 2 + 48, 0) - .addComponent("", 50, RAY::Vector2(), BLACK); + .addComponent(false, "", 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); + .addComponent(false, 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); + .addComponent(false, 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); + .addComponent(false, 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); + .addComponent(false, logoPos, RAY::Vector2(16, 16), BLACK); static short letterCounter = 0; switch (component.currentStep) diff --git a/sources/System/Renderer/RenderSystem.cpp b/sources/System/Renderer/RenderSystem.cpp index d21065c2..161bd2d8 100644 --- a/sources/System/Renderer/RenderSystem.cpp +++ b/sources/System/Renderer/RenderSystem.cpp @@ -46,6 +46,21 @@ namespace BBM this->_window.beginDrawing(); this->_window.clear(); + for (auto &[entity, pos, drawable] : this->_wal.getScene()->view()) { + if (!drawable.drawBefore3D) + continue; + auto *shader = entity.tryGetComponent(); + + if (shader) { + RAY::Shader::BeginUsingCustomShader(shader->getShader()); + } + drawable.drawable->setPosition(Vector2f(pos.position.x, pos.position.y)); + drawable.drawable->drawOn(this->_window); + if (shader) { + RAY::Shader::EndUsingCustomShader(); + } + } + this->_window.useCamera(this->_camera); for (auto &[entity, pos, drawable] : this->_wal.getScene()->view()) { auto *modelShader = entity.tryGetComponent(); @@ -63,6 +78,8 @@ namespace BBM // TODO sort entities based on the Z axis for (auto &[entity, pos, drawable] : this->_wal.getScene()->view()) { + if (drawable.drawBefore3D) + continue; auto *shader = entity.tryGetComponent(); if (shader) {