~leinnan/raylibGame unlisted

78f7658753c01079440ecdaee02660a133d31c99 — Leinnan 1 year, 4 months ago e2276a4
Add Destroyable component
1 files changed, 33 insertions(+), 0 deletions(-)

M src/systems/DamageSystem.cpp
M src/systems/DamageSystem.cpp => src/systems/DamageSystem.cpp +33 -0
@@ 1,9 1,11 @@
#include "DamageSystem.hpp"

#include "components/Actor.hpp"
#include "components/Collisions.hpp"
#include "components/DamageBox.hpp"
#include "components/Destroyable.hpp"
#include "components/Fighter.hpp"
#include "components/Transform.hpp"

#include "raylib.h"



@@ 42,6 44,37 @@ void DamageSystem::Update(entt::registry<> &registry, const float delta) {
                    }
                }
        });

        auto damageBoxes = registry.view<Components::Transform, Components::DamageBox>();

        registry.view<Components::Transform, Components::Destroyable, Components::Collisions>().each(
        [&](const auto entity, const auto &transform, auto &destroyable, const auto& collider){

            const auto boxes = collider.boxes;
            bool isColliding = false;
            int damageTaken = 0;

            for(auto &damageBox : damageBoxes) {
                if(damageBox == entity)
                    continue;

                auto &damage = registry.get<Components::DamageBox>(damageBox).box;

                for(const auto& box : boxes)
                {
                    if(CheckCollisionBoxes(damage, box))
                    {
                        isColliding = true;
                        break;
                    }
                }

                if(isColliding)
                    damageTaken += registry.get<Components::DamageBox>(damageBox).damage;
            }

            destroyable.currentLife -= damageTaken;
        });
}
} // namespace Systems
  // Systems