summaryrefslogtreecommitdiff
path: root/battles
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-11-17 23:42:16 +0100
committerAki <please@ignore.pl>2022-11-17 23:50:47 +0100
commit5059c1888b7a78bdbf2347baf4ec6372c1e6236f (patch)
tree642f1d7dc432160c877d6bd3c2469e3c455df240 /battles
parent068d56e95ab3a96c25ec3a2d2e8fff74e527a6eb (diff)
downloadkurator-5059c1888b7a78bdbf2347baf4ec6372c1e6236f.zip
kurator-5059c1888b7a78bdbf2347baf4ec6372c1e6236f.tar.gz
kurator-5059c1888b7a78bdbf2347baf4ec6372c1e6236f.tar.bz2
Implemented naive hit detection events
Diffstat (limited to 'battles')
-rw-r--r--battles/include/kurator/battles/Battle.h2
-rw-r--r--battles/src/BaseBattle.cpp13
-rw-r--r--battles/src/BaseBattle.h3
3 files changed, 17 insertions, 1 deletions
diff --git a/battles/include/kurator/battles/Battle.h b/battles/include/kurator/battles/Battle.h
index 82a5da5..1542597 100644
--- a/battles/include/kurator/battles/Battle.h
+++ b/battles/include/kurator/battles/Battle.h
@@ -3,6 +3,7 @@
#include <memory>
#include <entt/entity/registry.hpp>
+#include <entt/signal/dispatcher.hpp>
#include "Scenario.h"
@@ -18,6 +19,7 @@ class Battle
public:
virtual ~Battle() = default;
virtual entt::registry& registry() = 0;
+ virtual entt::dispatcher& dispatcher() = 0;
virtual void update(float dt) = 0;
};
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();