summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-11-19 00:42:19 +0100
committerAki <please@ignore.pl>2022-11-19 00:42:19 +0100
commit5680dc7b0c93d208fab8c4c30172ab2c3b53f82b (patch)
treefb3271782d57f4f496226eb027298c8e539dbd8d
parent5059c1888b7a78bdbf2347baf4ec6372c1e6236f (diff)
downloadkurator-5680dc7b0c93d208fab8c4c30172ab2c3b53f82b.zip
kurator-5680dc7b0c93d208fab8c4c30172ab2c3b53f82b.tar.gz
kurator-5680dc7b0c93d208fab8c4c30172ab2c3b53f82b.tar.bz2
Split damage pop into more verbose components
-rw-r--r--kurator/src/Battle.cpp38
-rw-r--r--kurator/src/DamagePop.h15
-rw-r--r--kurator/src/components.h34
3 files changed, 59 insertions, 28 deletions
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp
index ffddc92..bee8932 100644
--- a/kurator/src/Battle.cpp
+++ b/kurator/src/Battle.cpp
@@ -7,13 +7,14 @@
#include <raylib.h>
+#include <kurator/battles/Battle.h>
#include <kurator/battles/components.h>
#include <kurator/battles/events.h>
-#include <kurator/battles/Battle.h>
+#include <kurator/battles/Point.h>
#include <kurator/battles/scenarios.h>
#include <kurator/universe/ShipType.h>
-#include "DamagePop.h"
+#include "components.h"
#include "Session.h"
#include "Title.h"
@@ -41,12 +42,21 @@ Battle::update(const float dt)
{
battle->update(dt);
auto& registry = battle->registry();
- auto pops = registry.view<DamagePop>();
- for (auto&& [entity, pop] : pops.each()) {
- pop.timer -= dt;
- if (pop.timer < 0.0)
+ auto timers = registry.view<Timed>();
+ for (auto&& [entity, timer] : timers.each()) {
+ timer.left -= dt;
+ if (timer.left < 0.0)
registry.destroy(entity);
}
+ auto pops = registry.view<PopMove, battles::Transform>();
+ for (auto&& [entity, pop, transform] : pops.each()) {
+ const auto speed = pop.speed.scale(dt);
+ transform.position.x += speed.x;
+ transform.position.y += speed.y;
+ const auto damp = pop.speed.scale(pop.damp).scale(dt);
+ pop.speed.x -= damp.x;
+ pop.speed.y -= damp.y;
+ }
if (IsKeyPressed(KEY_SPACE))
session->set(std::make_shared<Title>(session));
}
@@ -69,12 +79,11 @@ Battle::draw() const
DrawLine(x, y, x + 6 * std::cos(transform.angle), y + 6 * std::sin(transform.angle), WHITE);
DrawText(ship_type.name.c_str(), x+10, y-10, 20.0f, GRAY);
}
- auto pops = registry.view<DamagePop, const battles::Transform>();
- for (auto [entity, pop, transform] : pops.each()) {
- const int x = width/2 + transform.position.x*scale;
- const int y = height/2 + transform.position.y*scale;
- const int text = MeasureText(pop.text, 10);
- DrawText(pop.text, x-text/2, y-5-22*(0.4-pop.timer), 10, RED);
+ auto pops = registry.view<CenteredText, battles::Transform>();
+ for (const auto& [entity, text, transform] : pops.each()) {
+ const int x = width/2 + transform.position.x*scale - text.width/2;
+ const int y = height/2 + transform.position.y*scale - text.font_size/2;
+ DrawText(text.text, x, y, text.font_size, text.color);
}
}
@@ -86,9 +95,12 @@ Battle::receive(const battles::Hit& hit)
if (!registry.valid(hit.victim))
return;
const auto entity = registry.create();
+ const auto text = TextFormat("%.1f", hit.damage);
const auto& transform = registry.get<battles::Transform>(hit.victim);
- registry.emplace<DamagePop>(entity, 0.4, TextFormat("%.1f", hit.damage));
+ registry.emplace<Timed>(entity, 1.2);
+ registry.emplace<CenteredText>(entity, text, MeasureText(text, 10), 10, RED);
registry.emplace<battles::Transform>(entity, transform.position, 0.0);
+ registry.emplace<PopMove>(entity, battles::Point{0.0, -0.6}, 0.998);
}
diff --git a/kurator/src/DamagePop.h b/kurator/src/DamagePop.h
deleted file mode 100644
index dc4c19a..0000000
--- a/kurator/src/DamagePop.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#pragma once
-
-
-namespace kurator
-{
-
-
-struct DamagePop
-{
- double timer;
- const char* text;
-};
-
-
-} // namespace kurator
diff --git a/kurator/src/components.h b/kurator/src/components.h
new file mode 100644
index 0000000..655db2f
--- /dev/null
+++ b/kurator/src/components.h
@@ -0,0 +1,34 @@
+#pragma once
+
+#include <raylib.h>
+
+#include <kurator/battles/Point.h>
+
+
+namespace kurator
+{
+
+
+struct Timed
+{
+ double left;
+};
+
+
+struct CenteredText
+{
+ const char* text;
+ int width;
+ int font_size;
+ Color color;
+};
+
+
+struct PopMove
+{
+ battles::Point speed;
+ double damp;
+};
+
+
+} // namespace kurator