diff --git a/CMakeLists.txt b/CMakeLists.txt index c7e8b9ed..b4aa8778 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,6 +111,10 @@ set(SOURCES sources/System/Music/MusicSystem.cpp sources/System/Bomb/BombSystem.cpp sources/System/Bomb/BombSystem.hpp + sources/Component/IntroAnimation/IntroAnimationComponent.hpp + sources/Component/IntroAnimation/IntroAnimationComponent.cpp + sources/System/IntroAnimation/IntroAnimationSystem.hpp + sources/System/IntroAnimation/IntroAnimationSystem.cpp ) add_executable(bomberman sources/main.cpp diff --git a/lib/Ray/sources/Drawables/2D/Rectangle.cpp b/lib/Ray/sources/Drawables/2D/Rectangle.cpp index 9f623bee..284e9b27 100644 --- a/lib/Ray/sources/Drawables/2D/Rectangle.cpp +++ b/lib/Ray/sources/Drawables/2D/Rectangle.cpp @@ -33,13 +33,47 @@ namespace RAY::Drawables::Drawables2D return *this; } - Rectangle &Rectangle::setDimensions(int x, int y) + Rectangle &Rectangle::setDimensions(float x, float y) { this->_dimensions.x = x; this->_dimensions.y = y; return *this; } + float Rectangle::getHeight(void) const + { + return this->_dimensions.y; + } + + float Rectangle::getWidth(void) const + { + return this->_dimensions.x; + } + + Rectangle &Rectangle::incrementWidth(float width) + { + this->_dimensions.x += width; + return *this; + } + + Rectangle &Rectangle::incrementHeight(float height) + { + this->_dimensions.y += height; + return *this; + } + + Rectangle &Rectangle::setWidth(float width) + { + this->_dimensions.x = width; + return *this; + } + + Rectangle &Rectangle::setHeight(float height) + { + this->_dimensions.y = height; + return *this; + } + void Rectangle::drawOn(RAY::Window &) { DrawRectangleV(this->_position, this->_dimensions, this->_color); diff --git a/lib/Ray/sources/Drawables/2D/Rectangle.hpp b/lib/Ray/sources/Drawables/2D/Rectangle.hpp index e0d32dff..6442a7f1 100644 --- a/lib/Ray/sources/Drawables/2D/Rectangle.hpp +++ b/lib/Ray/sources/Drawables/2D/Rectangle.hpp @@ -42,11 +42,33 @@ namespace RAY::Drawables::Drawables2D { //! @return the dimensions of the rectangle const Vector2 &getDimensions(void); + //! @return the width of the rectangle + float getWidth(void) const; + + //! @return the height of the rectangle + float getHeight(void) const; + //! @brief set dimensions Rectangle &setDimensions(const Vector2 &dimensions); + //! @brief increment width of the rectangle + //! @param width incrementer + Rectangle &incrementWidth(float width); + + //! @brief increment height of the rectangle + //! @param height incrementer + Rectangle &incrementHeight(float height); + + //! @brief set rectangle's height + //! @param height height of the rectangle + Rectangle &setHeight(float height); + + //! @brief set rectangle's width + //! @param width width of the rectangle + Rectangle &setWidth(float width); + //! @brief set dimensions - Rectangle &setDimensions(int x, int y); + Rectangle &setDimensions(float x, float y); //! @brief Draw point on window virtual void drawOn(RAY::Window &) override; diff --git a/sources/Component/IntroAnimation/IntroAnimationComponent.hpp b/sources/Component/IntroAnimation/IntroAnimationComponent.hpp index 694b875a..0def3a25 100644 --- a/sources/Component/IntroAnimation/IntroAnimationComponent.hpp +++ b/sources/Component/IntroAnimation/IntroAnimationComponent.hpp @@ -9,10 +9,9 @@ namespace BBM class IntroAnimationComponent : public WAL::Component { public: - unsigned int frame = 0; + unsigned int frameCounter = 0; enum animationSteps { - init, boxBlinking, topLeftgrowing, bottomRightGrowing, @@ -21,7 +20,7 @@ namespace BBM prompt, }; - enum animationSteps currentStep = init; + enum animationSteps currentStep = boxBlinking; //! @inherit Component *clone(WAL::Entity &entity) const override; diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index bd8204c1..80f057cc 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include #include @@ -90,6 +92,7 @@ namespace BBM .addSystem() .addSystem() .addSystem() + .addSystem() .addSystem(); } @@ -606,8 +609,12 @@ namespace BBM { auto scene = std::make_shared(); + + auto &splashComponent = scene->addEntity("animation component") + .addComponent(); auto &background = scene->addEntity("background") - .addComponent(0, 0, 0) + .addComponent(RAY::Vector2(), RAY::Vector2(1920, 1080)); return scene; } diff --git a/sources/System/IntroAnimation/IntroAnimationSystem.cpp b/sources/System/IntroAnimation/IntroAnimationSystem.cpp index 74f3a89a..10243eae 100644 --- a/sources/System/IntroAnimation/IntroAnimationSystem.cpp +++ b/sources/System/IntroAnimation/IntroAnimationSystem.cpp @@ -1,9 +1,7 @@ -#include #include "Component/Button/ButtonComponent.hpp" #include "Component/Position/PositionComponent.hpp" #include "System/IntroAnimation/IntroAnimationSystem.hpp" -#include "Component/Controllable/ControllableComponent.hpp" #include "Entity/Entity.hpp" #include "Component/Renderer/Drawable2DComponent.hpp" #include @@ -18,26 +16,60 @@ namespace BBM void IntroAnimationSystem::onFixedUpdate(WAL::ViewEntity &entity) { + static const RAY::Vector2 logoPos(1920 / 2 - 128, 1080 / 2 - 128); auto &component = entity.get(); - auto &scene = wal.getScene(); + auto scene = wal.getScene(); + RAY2D::Rectangle *rectangle = nullptr; + static auto &bottomRectangle = scene->addEntity("bottom Rectangle") + .addComponent(1920 / 2 - 128, 1080 / 2 - 128, 0) + .addComponent(logoPos, RAY::Vector2(16, 16), BLACK); + static auto &leftRectangle = scene->addEntity("left Rectangle") + .addComponent(1920 / 2 - 128, 1080 / 2 - 128, 0) + .addComponent(logoPos, RAY::Vector2(16, 16), BLACK); + static auto &rightRectangle = scene->addEntity("right Rectangle") + .addComponent(1920 / 2 - 128, 1080 / 2 - 128, 0) + .addComponent(logoPos, RAY::Vector2(16, 16), BLACK); + static auto &topRectangle = scene->addEntity("top Rectangle") + .addComponent(1920 / 2 - 128, 1080 / 2 - 128, 0) + .addComponent(logoPos, RAY::Vector2(16, 16), BLACK); switch (component.currentStep) { - case IntroAnimationComponent::animationSteps::init: - scene->addEntity("white background") - .addComponent(BBM::Vector2f(), BBM::Vector2f(1920, 1080), WHITE); - - scene->addEntity("blinking square").addComponent(BBM::Vector2f(), BBM::Vector2f(16, 16), WHITE); - component.currentStep = IntroAnimationComponent::animationSteps::boxBlinking; - break; case IntroAnimationComponent::animationSteps::boxBlinking: - - if ((component.frame / 15) % 2) - scene->getEntities() + if ((component.frameCounter / 15) % 2) + topRectangle.getComponent().drawable->setColor(BLACK); + else + topRectangle.getComponent().drawable->setColor(WHITE); + if (component.frameCounter == 120) { + component.currentStep = IntroAnimationComponent::animationSteps::topLeftgrowing; + component.frameCounter = -1; + topRectangle.getComponent().drawable->setColor(BLACK); + leftRectangle.getComponent().drawable->setColor(BLACK); + } + break; + case IntroAnimationComponent::animationSteps::topLeftgrowing: + rectangle = dynamic_cast(leftRectangle.getComponent().drawable.get()); + rectangle->incrementHeight(4); + rectangle = dynamic_cast(topRectangle.getComponent().drawable.get()); + rectangle->incrementWidth(4); + if (rectangle->getWidth() == 256) { + component.currentStep = IntroAnimationComponent::animationSteps::bottomRightGrowing; + bottomRectangle.getComponent().position = Vector3f(1920 / 2 - 128, 1080 / 2 - 128 + 240, 0); + rightRectangle.getComponent().position = Vector3f(1920 / 2 - 128 + 240, 1080 / 2 - 128, 0); + } + break; + case IntroAnimationComponent::animationSteps::bottomRightGrowing: + rectangle = dynamic_cast(bottomRectangle.getComponent().drawable.get()); + rectangle->incrementWidth(4); + rectangle = dynamic_cast(rightRectangle.getComponent().drawable.get()); + rectangle->incrementHeight(4); + if (rectangle->getHeight() == 256) + component.currentStep = IntroAnimationComponent::animationSteps::lettersTyping; + break; + default: break; - } - component.frame++; + component.frameCounter++; } void IntroAnimationSystem::onSelfUpdate(void)