mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-02 02:05:25 +00:00
added death animation through a callback onDeath
This commit is contained in:
@@ -18,6 +18,12 @@ namespace BBM
|
||||
_healthPoint(healthPoint)
|
||||
{}
|
||||
|
||||
HealthComponent::HealthComponent(WAL::Entity &entity, unsigned int healthPoint, std::function<void (WAL::Entity &)> callback)
|
||||
: WAL::Component(entity),
|
||||
_healthPoint(healthPoint),
|
||||
onDeath(callback)
|
||||
{}
|
||||
|
||||
WAL::Component *HealthComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new HealthComponent(entity);
|
||||
|
||||
@@ -41,6 +41,9 @@ namespace BBM
|
||||
//! @brief Constructor
|
||||
HealthComponent(WAL::Entity &entity, unsigned int healthPoint);
|
||||
|
||||
//! @brief Constructor
|
||||
HealthComponent(WAL::Entity &entity, unsigned int healthPoint, std::function<void (WAL::Entity &)> callback);
|
||||
|
||||
//! @brief A Health component can't be instantiated, it should be derived.
|
||||
HealthComponent(const HealthComponent &) = default;
|
||||
|
||||
|
||||
@@ -82,7 +82,11 @@ namespace BBM
|
||||
.addComponent<KeyboardComponent>()
|
||||
.addComponent<AnimationsComponent>(RAY::ModelAnimations("assets/player/player.iqm"), 1)
|
||||
.addComponent<CollisionComponent>(2)
|
||||
.addComponent<MovableComponent>();
|
||||
.addComponent<MovableComponent>()
|
||||
.addComponent<HealthComponent>(1, [](WAL::Entity &entity) {
|
||||
auto &animation = entity.getComponent<AnimationsComponent>();
|
||||
animation.setAnimIndex(5);
|
||||
});
|
||||
scene->addEntity("cube")
|
||||
.addComponent<PositionComponent>(-5, 0, -5)
|
||||
.addComponent<Drawable3DComponent<RAY3D::Cube>>(Vector3f(-5, 0, -5), Vector3f(3, 3, 3), RED)
|
||||
|
||||
@@ -28,28 +28,17 @@ namespace BBM
|
||||
{
|
||||
if (!entity.hasComponent<ControllableComponent>())
|
||||
return;
|
||||
const std::vector<std::vector<float>> moveDiag = {{-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}};
|
||||
const std::vector<float> rotationAngle = {0.0f, 45.0f, 90.0f, 135.0f, 180.0f, 225.0f, 270.0f, 315.0f};
|
||||
const auto &controllable = entity.getComponent<ControllableComponent>();
|
||||
auto &model = entity.getComponent<Drawable3DComponent<RAY3D::Model>>();
|
||||
auto &animation = entity.getComponent<AnimationsComponent>();
|
||||
if (controllable.move.x == 1) {
|
||||
model.member.setRotationAngle(180.0f);
|
||||
animation.setAnimIndex(0);
|
||||
return;
|
||||
}
|
||||
if (controllable.move.x == -1) {
|
||||
model.member.setRotationAngle(0.0f);
|
||||
animation.setAnimIndex(0);
|
||||
return;
|
||||
}
|
||||
if (controllable.move.y == 1) {
|
||||
model.member.setRotationAngle(90.0f);
|
||||
animation.setAnimIndex(0);
|
||||
return;
|
||||
}
|
||||
if (controllable.move.y == -1) {
|
||||
model.member.setRotationAngle(270.0f);
|
||||
animation.setAnimIndex(0);
|
||||
return;
|
||||
for (int i = 0; i != moveDiag.size(); i++) {
|
||||
if (controllable.move.x == moveDiag[i][0] && controllable.move.y == moveDiag[i][1]) {
|
||||
model.member.setRotationAngle(rotationAngle[i]);
|
||||
animation.setAnimIndex(0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
animation.setAnimIndex(1);
|
||||
}
|
||||
|
||||
@@ -13,8 +13,7 @@ namespace BBM
|
||||
{
|
||||
HealthSystem::HealthSystem()
|
||||
: WAL::System({
|
||||
typeid(HealthComponent),
|
||||
typeid(AnimationsComponent)
|
||||
typeid(HealthComponent)
|
||||
})
|
||||
{}
|
||||
|
||||
@@ -23,10 +22,6 @@ namespace BBM
|
||||
auto &health = entity.getComponent<HealthComponent>();
|
||||
|
||||
if (health.getHealthPoint() == 0) {
|
||||
if (entity.hasComponent<AnimationsComponent>()) {
|
||||
auto &animation = entity.getComponent<AnimationsComponent>();
|
||||
animation.setAnimIndex(5);
|
||||
}
|
||||
health.onDeath(entity);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user