mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-02 02:05:25 +00:00
start animator
This commit is contained in:
+5
-1
@@ -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)
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by hbenjamin on 03/06/2021.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Entity/Entity.hpp>
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
@@ -26,6 +26,8 @@
|
||||
#include "Runner.hpp"
|
||||
#include "Models/GameState.hpp"
|
||||
#include <Model/ModelAnimations.hpp>
|
||||
#include <Component/Animator/AnimatorComponent.hpp>
|
||||
#include <System/Animator/AnimatorSystem.hpp>
|
||||
#include "Component/Animation/AnimationsComponent.hpp"
|
||||
#include "System/Animation/AnimationsSystem.hpp"
|
||||
#include "Map/Map.hpp"
|
||||
@@ -51,6 +53,7 @@ namespace BBM
|
||||
.addSystem<GamepadSystem>()
|
||||
.addSystem<ControllableSystem>()
|
||||
.addSystem<CollisionSystem>(wal)
|
||||
.addSystem<AnimatorSystem>()
|
||||
.addSystem<MovableSystem>();
|
||||
}
|
||||
|
||||
@@ -75,8 +78,9 @@ namespace BBM
|
||||
.addComponent<PositionComponent>()
|
||||
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png"))
|
||||
.addComponent<ControllableComponent>()
|
||||
.addComponent<AnimatorComponent>()
|
||||
.addComponent<KeyboardComponent>()
|
||||
.addComponent<AnimationsComponent>(RAY::ModelAnimations("assets/player/player.iqm"), 1)
|
||||
.addComponent<AnimationsComponent>(RAY::ModelAnimations("assets/player/player.iqm"), 3)
|
||||
.addComponent<CollisionComponent>(2)
|
||||
.addComponent<MovableComponent>();
|
||||
scene->addEntity("cube")
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// Created by hbenjamin on 03/06/2021.
|
||||
//
|
||||
|
||||
#include <Component/Animator/AnimatorComponent.hpp>
|
||||
#include <Component/Keyboard/KeyboardComponent.hpp>
|
||||
#include <Controllers/Keyboard.hpp>
|
||||
#include <Model/Model.hpp>
|
||||
#include <Component/Animation/AnimationsComponent.hpp>
|
||||
#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<KeyboardComponent>())
|
||||
return;
|
||||
auto &model = entity.getComponent<Drawable3DComponent<RAY3D::Model>>();
|
||||
auto &animation = entity.getComponent<AnimationsComponent>();
|
||||
const auto &keyboard = entity.getComponent<KeyboardComponent>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user