From 5059c1888b7a78bdbf2347baf4ec6372c1e6236f Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 17 Nov 2022 23:42:16 +0100 Subject: Implemented naive hit detection events --- battles/src/BaseBattle.cpp | 13 ++++++++++++- battles/src/BaseBattle.h | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'battles/src') diff --git a/battles/src/BaseBattle.cpp b/battles/src/BaseBattle.cpp index e7d70c2..4088936 100644 --- a/battles/src/BaseBattle.cpp +++ b/battles/src/BaseBattle.cpp @@ -1,8 +1,10 @@ #include "BaseBattle.h" #include +#include #include +#include #include #include @@ -37,6 +39,13 @@ BaseBattle::registry() } +entt::dispatcher& +BaseBattle::dispatcher() +{ + return _dispatcher; +} + + void BaseBattle::update(const float dt) { @@ -108,8 +117,10 @@ BaseBattle::turrets(const float dt) auto& target_points = _registry.get(state.target); const auto& target = _registry.get(state.target); const auto distance = transform.position - target.position; - if (def.range > distance.magnitude()) + if (def.range > distance.magnitude()) { target_points.health -= def.base_damage; + _dispatcher.trigger(Hit{def.base_damage, entity, state.target}); + } control.reload = def.rate_of_fire; } } diff --git a/battles/src/BaseBattle.h b/battles/src/BaseBattle.h index 02cc024..8240fd2 100644 --- a/battles/src/BaseBattle.h +++ b/battles/src/BaseBattle.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -20,9 +21,11 @@ class BaseBattle : public Battle public: BaseBattle(const Scenario& scenario); entt::registry& registry() override; + entt::dispatcher& dispatcher() override; void update(float dt) override; private: entt::registry _registry; + entt::dispatcher _dispatcher; RandomSpawner spawner; TeamManager manager; void pick_random_targets(); -- cgit v1.1