diff options
author | Aki <please@ignore.pl> | 2022-11-17 23:42:16 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-11-17 23:50:47 +0100 |
commit | 5059c1888b7a78bdbf2347baf4ec6372c1e6236f (patch) | |
tree | 642f1d7dc432160c877d6bd3c2469e3c455df240 /battles/src | |
parent | 068d56e95ab3a96c25ec3a2d2e8fff74e527a6eb (diff) | |
download | kurator-5059c1888b7a78bdbf2347baf4ec6372c1e6236f.zip kurator-5059c1888b7a78bdbf2347baf4ec6372c1e6236f.tar.gz kurator-5059c1888b7a78bdbf2347baf4ec6372c1e6236f.tar.bz2 |
Implemented naive hit detection events
Diffstat (limited to 'battles/src')
-rw-r--r-- | battles/src/BaseBattle.cpp | 13 | ||||
-rw-r--r-- | battles/src/BaseBattle.h | 3 |
2 files changed, 15 insertions, 1 deletions
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 <entt/entity/registry.hpp> +#include <entt/signal/dispatcher.hpp> #include <kurator/battles/components.h> +#include <kurator/battles/events.h> #include <kurator/battles/Scenario.h> #include <kurator/universe.h> @@ -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<HitPoints>(state.target); const auto& target = _registry.get<Transform>(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 <entt/entity/registry.hpp> +#include <entt/signal/dispatcher.hpp> #include <kurator/battles/Battle.h> #include <kurator/battles/Scenario.h> @@ -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(); |