#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) {} void IntroAnimationSystem::onFixedUpdate(WAL::ViewEntity &entity) { static const RAY::Vector2 logoPos(1920 / 2 - 128, 1080 / 2 - 128); auto &component = entity.get(); auto scene = this->_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(std::chrono::nanoseconds) { } }