mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-07 03:25:10 +00:00
Merge branch 'develop' into wasm
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// Created by cbihan on 01/06/2021.
|
||||
//
|
||||
|
||||
#include "AnimationsComponent.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
#include "Model/ModelAnimations.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
AnimationsComponent::AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations modelAnimation, int animIndex, bool play)
|
||||
: WAL::Component(entity),
|
||||
_modelAnimation(std::move(modelAnimation)),
|
||||
_currentAnimIndex(animIndex),
|
||||
_animDisabled(play)
|
||||
{
|
||||
this->_modelAnimation[this->_currentAnimIndex].setFrameCounter(0);
|
||||
}
|
||||
|
||||
WAL::Component *AnimationsComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new AnimationsComponent(entity,
|
||||
RAY::ModelAnimations(this->_modelAnimation.getFilePath()),
|
||||
this->_currentAnimIndex);
|
||||
}
|
||||
|
||||
size_t AnimationsComponent::getCurrentAnimFrameCounter() const
|
||||
{
|
||||
return this->_modelAnimation.at(this->_currentAnimIndex).getFrameCounter();
|
||||
}
|
||||
|
||||
RAY::ModelAnimation AnimationsComponent::getCurrentModelAnim()
|
||||
{
|
||||
return this->_modelAnimation[this->_currentAnimIndex];
|
||||
}
|
||||
|
||||
void AnimationsComponent::setCurrentAnimFrameCounter(size_t animFrameCounter)
|
||||
{
|
||||
this->_modelAnimation[this->_currentAnimIndex].setFrameCounter(animFrameCounter);
|
||||
}
|
||||
|
||||
void AnimationsComponent::resetCurrentAnimFrameCounter()
|
||||
{
|
||||
this->_modelAnimation[this->_currentAnimIndex].setFrameCounter(0);
|
||||
}
|
||||
|
||||
size_t AnimationsComponent::getCurrentAnimIndex() const
|
||||
{
|
||||
return this->_currentAnimIndex;
|
||||
}
|
||||
|
||||
void AnimationsComponent::setAnimIndex(int animIndex)
|
||||
{
|
||||
this->_currentAnimIndex = animIndex % static_cast<int>(this->_modelAnimation.getAnimationsCount());
|
||||
}
|
||||
|
||||
void AnimationsComponent::incCurrentAnimFrameCounter()
|
||||
{
|
||||
this->_modelAnimation[this->_currentAnimIndex].incrementFrameCounter();
|
||||
}
|
||||
|
||||
void AnimationsComponent::setAnimDisabled(bool disable)
|
||||
{
|
||||
this->_animDisabled = disable;
|
||||
}
|
||||
|
||||
bool AnimationsComponent::isAnimDisabled() const
|
||||
{
|
||||
return this->_animDisabled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// Created by cbihan on 01/06/2021.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <Model/ModelAnimations.hpp>
|
||||
#include <Component/Component.hpp>
|
||||
#include <Entity/Entity.hpp>
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
class AnimationsComponent : public WAL::Component
|
||||
{
|
||||
private:
|
||||
//! @brief To get the animation data
|
||||
RAY::ModelAnimations _modelAnimation;
|
||||
//! @brief The index of the
|
||||
int _currentAnimIndex;
|
||||
//! @brief Bool allowing to play pause an animation
|
||||
bool _animDisabled;
|
||||
public:
|
||||
//! @inherit
|
||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
//! @brief get the current animation index
|
||||
size_t getCurrentAnimIndex() const;
|
||||
|
||||
//! @brief Set the animation index to use
|
||||
void setAnimIndex(int animIndex);
|
||||
|
||||
//! @brief get animation frame counter
|
||||
size_t getCurrentAnimFrameCounter() const;
|
||||
|
||||
//! @brief get the current
|
||||
RAY::ModelAnimation getCurrentModelAnim();
|
||||
|
||||
//! @brief set the anim frame counter
|
||||
void setCurrentAnimFrameCounter(size_t animFrameCounter);
|
||||
|
||||
//! @brief Set the internal anim counter to 0
|
||||
void resetCurrentAnimFrameCounter();
|
||||
|
||||
//! @brief Increment the internal anim counter
|
||||
void incCurrentAnimFrameCounter();
|
||||
|
||||
//! @brief Allow to play pause animations
|
||||
void setAnimDisabled(bool disable);
|
||||
|
||||
//! @brief To know if the animation will be updated or not
|
||||
bool isAnimDisabled() const;
|
||||
|
||||
//! @brief ctor entity and the path of the animation file
|
||||
explicit AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations modelAnimation, int animIndex, bool play = true);
|
||||
//! @brief copy ctor
|
||||
AnimationsComponent(const AnimationsComponent &) = default;
|
||||
//! @brief dtor
|
||||
~AnimationsComponent() override = default;
|
||||
//! @brief assignment operator
|
||||
AnimationsComponent &operator=(const AnimationsComponent &) = delete;
|
||||
};
|
||||
}
|
||||
@@ -25,6 +25,9 @@
|
||||
#include "Component/Renderer/Drawable3DComponent.hpp"
|
||||
#include "Runner.hpp"
|
||||
#include "Models/GameState.hpp"
|
||||
#include <Model/ModelAnimations.hpp>
|
||||
#include "Component/Animation/AnimationsComponent.hpp"
|
||||
#include "System/Animation/AnimationsSystem.hpp"
|
||||
#include "Map/Map.hpp"
|
||||
|
||||
namespace RAY2D = RAY::Drawables::Drawables2D;
|
||||
@@ -66,6 +69,7 @@ namespace BBM
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png"))
|
||||
.addComponent<ControllableComponent>()
|
||||
.addComponent<KeyboardComponent>()
|
||||
.addComponent<AnimationsComponent>(RAY::ModelAnimations("assets/player/player.iqm"), 1)
|
||||
.addComponent<CollisionComponent>(2)
|
||||
.addComponent<MovableComponent>();
|
||||
scene->addEntity("cube")
|
||||
@@ -80,7 +84,7 @@ namespace BBM
|
||||
mov.resetVelocity();
|
||||
} catch (std::exception &e) { };
|
||||
}, 3);
|
||||
|
||||
|
||||
scene->addEntity("camera")
|
||||
.addComponent<PositionComponent>(8, 20, 7)
|
||||
.addComponent<CameraComponent>(Vector3f(8, 0, 8));
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// Created by cbihan on 01/06/2021.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include "AnimationsSystem.hpp"
|
||||
#include "Component/Animation/AnimationsComponent.hpp"
|
||||
#include "Model/Model.hpp"
|
||||
#include "Component/Renderer/Drawable3DComponent.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
|
||||
AnimationsSystem::AnimationsSystem()
|
||||
: WAL::System({
|
||||
typeid(Drawable3DComponent<RAY::Drawables::Drawables3D::Model>),
|
||||
typeid(AnimationsComponent)
|
||||
})
|
||||
{
|
||||
}
|
||||
|
||||
void AnimationsSystem::onUpdate(WAL::Entity &entity, std::chrono::nanoseconds)
|
||||
{
|
||||
auto &model = entity.getComponent<Drawable3DComponent<RAY::Drawables::Drawables3D::Model>>();
|
||||
auto &anim = entity.getComponent<AnimationsComponent>();
|
||||
|
||||
if (anim.isDisabled())
|
||||
return;
|
||||
model.member.setAnimation(anim.getCurrentModelAnim());
|
||||
anim.incCurrentAnimFrameCounter();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by cbihan on 01/06/2021.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <System/System.hpp>
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
class AnimationsSystem : public WAL::System
|
||||
{
|
||||
public:
|
||||
//! @inherit
|
||||
void onUpdate(WAL::Entity &entity, std::chrono::nanoseconds) override;
|
||||
|
||||
//! @brief A default constructor
|
||||
AnimationsSystem();
|
||||
//! @brief A Controllable system is copy constructable
|
||||
AnimationsSystem(const AnimationsSystem &) = default;
|
||||
//! @brief A default destructor
|
||||
~AnimationsSystem() override = default;
|
||||
//! @brief A Controllable system is assignable.
|
||||
AnimationsSystem &operator=(const AnimationsSystem &) = default;
|
||||
};
|
||||
}
|
||||
@@ -10,8 +10,6 @@
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
float ControllableSystem::speed = .25f;
|
||||
|
||||
ControllableSystem::ControllableSystem()
|
||||
: WAL::System({
|
||||
typeid(ControllableComponent),
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace BBM
|
||||
{
|
||||
public:
|
||||
//! @brief The speed applied to every controllable entities.
|
||||
static float speed;
|
||||
static constexpr const float speed = .25f;
|
||||
|
||||
//! @inherit
|
||||
void onFixedUpdate(WAL::Entity &entity) override;
|
||||
|
||||
Reference in New Issue
Block a user