From 88add0b8f15c5012a5a639d6d7785b8c37bdd783 Mon Sep 17 00:00:00 2001 From: Askou Date: Thu, 17 Jun 2021 09:37:11 +0200 Subject: [PATCH] basic game intro animation with reset --- .../BombHolder/BombHolderComponent.hpp | 2 +- sources/Runner/GameScene.cpp | 2 +- sources/Runner/LobbyScene.cpp | 2 +- sources/System/Animator/AnimatorSystem.cpp | 3 ++ sources/System/Renderer/RenderSystem.cpp | 34 +++++++++++++++++-- sources/System/Renderer/RenderSystem.hpp | 3 ++ 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/sources/Component/BombHolder/BombHolderComponent.hpp b/sources/Component/BombHolder/BombHolderComponent.hpp index 43242338..02b28fcf 100644 --- a/sources/Component/BombHolder/BombHolderComponent.hpp +++ b/sources/Component/BombHolder/BombHolderComponent.hpp @@ -14,7 +14,7 @@ using namespace std::chrono_literals; namespace BBM { - class BombHolderComponent : public WAL::Component + class BombHolderComponent : public WAL::Component { public: //! @brief The number of bomb that this entity hold. diff --git a/sources/Runner/GameScene.cpp b/sources/Runner/GameScene.cpp index 75de7648..51a0221f 100644 --- a/sources/Runner/GameScene.cpp +++ b/sources/Runner/GameScene.cpp @@ -29,7 +29,7 @@ namespace BBM { auto scene = std::make_shared(); scene->addEntity("camera") - .addComponent(8, 20, 7) + .addComponent(8, 0, -5) .addComponent(Vector3f(8, 0, 8)); MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16, hasHeights), scene); return scene; diff --git a/sources/Runner/LobbyScene.cpp b/sources/Runner/LobbyScene.cpp index c2221298..efdd90a3 100644 --- a/sources/Runner/LobbyScene.cpp +++ b/sources/Runner/LobbyScene.cpp @@ -183,7 +183,7 @@ namespace BBM player.addComponent(i, ready, playerTile); } scene->addEntity("camera") - .addComponent(8, 20, 7) + .addComponent(-5, 0, -5) .addComponent(Vector3f(8, 0, 8)); play.getComponent().setButtonLinks(&heightOption, &back, &back, nullptr); back.getComponent().setButtonLinks(&play, nullptr, nullptr, &play); diff --git a/sources/System/Animator/AnimatorSystem.cpp b/sources/System/Animator/AnimatorSystem.cpp index f03aeb9b..5cd1a28d 100644 --- a/sources/System/Animator/AnimatorSystem.cpp +++ b/sources/System/Animator/AnimatorSystem.cpp @@ -27,6 +27,9 @@ namespace BBM auto drawable = entity.get().drawable.get(); auto &animation = entity.get(); auto anim = dynamic_cast(drawable); + + if (entity->shouldDelete()) + return; if (anim && controllable.move != Vector2f(0, 0)) { anim->setRotationAngle(controllable.move.angle(Vector2f(-1, 0))); animation.setAnimIndex(0); diff --git a/sources/System/Renderer/RenderSystem.cpp b/sources/System/Renderer/RenderSystem.cpp index 69b4fca8..483bb9f6 100644 --- a/sources/System/Renderer/RenderSystem.cpp +++ b/sources/System/Renderer/RenderSystem.cpp @@ -80,9 +80,35 @@ namespace BBM this->_window.endDrawing(); } + bool RenderSystem::introAnimation(WAL::ViewEntity &entity, bool restart) + { + auto &pos = entity.get(); + static Vector3f posTarget(8, 25, 7); + static bool hasEnded = false; + + if (restart) { + hasEnded = false; + return (false); + } + if (pos.position.distance(posTarget) < 1 || hasEnded) { + hasEnded = true; + return (true); + } + + auto &cam = entity.get(); + + pos.position += (posTarget - pos.position) / 100; + this->_camera.setPosition(pos.position); + this->_camera.setTarget(cam.target); + return (false); + } + + void RenderSystem::onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) { + if (!introAnimation(entity)) + return; auto &pos = entity.get(); auto &cam = entity.get(); Vector3f newCameraPos = Vector3f(-1, -1, -1); @@ -91,8 +117,10 @@ namespace BBM float lowerXDist = 0; float lowerZDist = 0; - for (auto &[entity, pos, _] : this->_wal.getScene()->view>()) { + for (auto &[entity, pos, _] : this->_wal.getScene()->view>()) playerPos.emplace_back(pos.position); + if (playerPos.size() == 0) + introAnimation(entity, true); if (playerPos.size() == 1) newCameraPos = playerPos[0]; for (int i = 0; i < playerPos.size(); i++) @@ -111,10 +139,10 @@ namespace BBM maxDist = 14; if (maxDist > 25) maxDist = 25; - cam.target += (newCameraPos.abs() - pos.position.abs()) / 5; + cam.target += (newCameraPos.abs() - pos.position.abs()) / 10; newCameraPos.y = maxDist; newCameraPos.z -= 1; - pos.position += (newCameraPos.abs() - pos.position.abs()) / 5; + pos.position += (newCameraPos.abs() - pos.position.abs()) / 10; _camera.setTarget(cam.target); _camera.setPosition(pos.position); } diff --git a/sources/System/Renderer/RenderSystem.hpp b/sources/System/Renderer/RenderSystem.hpp index 7ef2c801..fcb40970 100644 --- a/sources/System/Renderer/RenderSystem.hpp +++ b/sources/System/Renderer/RenderSystem.hpp @@ -43,6 +43,9 @@ namespace BBM //! @param entity entity to draw bounding box of void drawBoundingBox(const WAL::Entity &entity, const PositionComponent &posComponent, const Drawable3DComponent &drawable) const; + + //! @brief introduciton animation when entering gameScene + bool introAnimation(WAL::ViewEntity &entity, bool restart = false); //! @brief ctor RenderSystem(WAL::Wal &wal, RAY::Window &window, bool debugMode = false);