From daf5919523e711f7db5ff76f4411e65493af29e3 Mon Sep 17 00:00:00 2001 From: HENRY Benjamin Date: Thu, 3 Jun 2021 11:38:15 +0200 Subject: [PATCH] start animator --- CMakeLists.txt | 6 ++- .../Component/Animator/AnimatorComponent.cpp | 16 +++++++ .../Component/Animator/AnimatorComponent.hpp | 28 +++++++++++ sources/Runner/Runner.cpp | 6 ++- sources/System/Animator/AnimatorSystem.cpp | 46 +++++++++++++++++++ sources/System/Animator/AnimatorSystem.hpp | 27 +++++++++++ 6 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 sources/Component/Animator/AnimatorComponent.cpp create mode 100644 sources/Component/Animator/AnimatorComponent.hpp create mode 100644 sources/System/Animator/AnimatorSystem.cpp create mode 100644 sources/System/Animator/AnimatorSystem.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index fd2543bf..f7499f20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,12 +64,16 @@ set(SOURCES sources/Component/Collision/CollisionComponent.hpp sources/System/Collision/CollisionSystem.hpp sources/System/Collision/CollisionSystem.cpp + sources/Component/Animator/AnimatorComponent.cpp + sources/Component/Animator/AnimatorComponent.hpp + sources/System/Animator/AnimatorSystem.cpp + sources/System/Animator/AnimatorSystem.hpp ) add_executable(bomberman sources/main.cpp ${SOURCES} - ) + ) target_include_directories(bomberman PUBLIC sources) target_link_libraries(bomberman PUBLIC wal ray) diff --git a/sources/Component/Animator/AnimatorComponent.cpp b/sources/Component/Animator/AnimatorComponent.cpp new file mode 100644 index 00000000..fa5d8cc2 --- /dev/null +++ b/sources/Component/Animator/AnimatorComponent.cpp @@ -0,0 +1,16 @@ +// +// Created by hbenjamin on 03/06/2021. +// + +#include "AnimatorComponent.hpp" + +namespace BBM { + AnimatorComponent::AnimatorComponent(WAL::Entity &entity) + : WAL::Component(entity) + {} + + WAL::Component *AnimatorComponent::clone(WAL::Entity &entity) const + { + return new AnimatorComponent(entity); + } +} \ No newline at end of file diff --git a/sources/Component/Animator/AnimatorComponent.hpp b/sources/Component/Animator/AnimatorComponent.hpp new file mode 100644 index 00000000..0c31b576 --- /dev/null +++ b/sources/Component/Animator/AnimatorComponent.hpp @@ -0,0 +1,28 @@ +// +// Created by hbenjamin on 03/06/2021. +// + +#pragma once + +#include + +namespace BBM { + class AnimatorComponent : public WAL::Component + { + public: + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief An Animator component can't be instantiated, it should be derived. + explicit AnimatorComponent(WAL::Entity &entity); + + //! @brief An Animator component can't be instantiated, it should be derived. + AnimatorComponent(const AnimatorComponent &) = default; + + //! @brief default destructor + ~AnimatorComponent() override = default; + + //! @brief An Animator component can't be assigned + AnimatorComponent &operator=(const AnimatorComponent &) = delete; + }; +} \ No newline at end of file diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 8b1f36fd..9ce162c1 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -26,6 +26,8 @@ #include "Runner.hpp" #include "Models/GameState.hpp" #include +#include +#include #include "Component/Animation/AnimationsComponent.hpp" #include "System/Animation/AnimationsSystem.hpp" #include "Map/Map.hpp" @@ -51,6 +53,7 @@ namespace BBM .addSystem() .addSystem() .addSystem(wal) + .addSystem() .addSystem(); } @@ -75,8 +78,9 @@ namespace BBM .addComponent() .addComponent>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png")) .addComponent() + .addComponent() .addComponent() - .addComponent(RAY::ModelAnimations("assets/player/player.iqm"), 1) + .addComponent(RAY::ModelAnimations("assets/player/player.iqm"), 3) .addComponent(2) .addComponent(); scene->addEntity("cube") diff --git a/sources/System/Animator/AnimatorSystem.cpp b/sources/System/Animator/AnimatorSystem.cpp new file mode 100644 index 00000000..aa13683a --- /dev/null +++ b/sources/System/Animator/AnimatorSystem.cpp @@ -0,0 +1,46 @@ +// +// Created by hbenjamin on 03/06/2021. +// + +#include +#include +#include +#include +#include +#include "AnimatorSystem.hpp" +#include "Component/Renderer/Drawable3DComponent.hpp" + +using Keyboard = RAY::Controller::Keyboard; +namespace RAY3D = RAY::Drawables::Drawables3D; + +namespace BBM +{ + AnimatorSystem::AnimatorSystem() + : WAL::System({ + typeid(AnimatorComponent), + typeid(KeyboardComponent) + }) + {} + + void AnimatorSystem::onFixedUpdate(WAL::Entity &entity) + { + if (!entity.hasComponent()) + return; + auto &model = entity.getComponent>(); + auto &animation = entity.getComponent(); + const auto &keyboard = entity.getComponent(); + animation.setAnimIndex(1); + if (Keyboard::isDown(keyboard.keyRight)) { + model.member.setRotationAngle(180.0f); + } + if (Keyboard::isDown(keyboard.keyLeft)) { + model.member.setRotationAngle(0.0f); + } + if (Keyboard::isDown(keyboard.keyUp)) { + model.member.setRotationAngle(90.0f); + } + if (Keyboard::isDown(keyboard.keyDown)) { + model.member.setRotationAngle(270.0f); + } + } +} \ No newline at end of file diff --git a/sources/System/Animator/AnimatorSystem.hpp b/sources/System/Animator/AnimatorSystem.hpp new file mode 100644 index 00000000..6f4d950c --- /dev/null +++ b/sources/System/Animator/AnimatorSystem.hpp @@ -0,0 +1,27 @@ +// +// Created by hbenjamin on 03/06/2021. +// + +#pragma once + +#include "System/System.hpp" + +namespace BBM +{ + //! @brief A system to handle Health entities. + class AnimatorSystem : public WAL::System + { + public: + //! @inherit + void onFixedUpdate(WAL::Entity &entity) override; + + //! @brief A default constructor + AnimatorSystem(); + //! @brief A Health system is copy constructable + AnimatorSystem(const AnimatorSystem &) = default; + //! @brief A default destructor + ~AnimatorSystem() override = default; + //! @brief A Health system is assignable. + AnimatorSystem &operator=(const AnimatorSystem &) = default; + }; +} \ No newline at end of file