diff --git a/.idea/editor.xml b/.idea/editor.xml
index 0abfee7..d636c73 100644
--- a/.idea/editor.xml
+++ b/.idea/editor.xml
@@ -283,5 +283,247 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/include/bounding_box.h b/include/bounding_box.h
index 8ec6cbb..66dc6a2 100644
--- a/include/bounding_box.h
+++ b/include/bounding_box.h
@@ -19,10 +19,40 @@
#ifndef BOUNDING_BOX_H
#define BOUNDING_BOX_H
+#include
+
namespace td
{
class bounding_box_t
- {};
+ {
+ public:
+ bounding_box_t(const float xMin, const float yMin, const float xMax, const float yMax): m_min{xMin, yMin}, m_max{xMax, yMax}
+ {}
+
+ bounding_box_t(const blt::vec2& min, const blt::vec2& max): m_min{min}, m_max{max}
+ {}
+
+ [[nodiscard]] bool contains(const blt::vec2& point) const;
+
+ [[nodiscard]] blt::vec2 get_center() const;
+
+ [[nodiscard]] blt::vec2 get_size() const;
+
+ [[nodiscard]] bool intersects(const bounding_box_t& other) const;
+
+ [[nodiscard]] blt::vec2 get_min() const
+ {
+ return m_min;
+ }
+
+ [[nodiscard]] blt::vec2 get_max() const
+ {
+ return m_max;
+ }
+
+ private:
+ blt::vec2 m_min, m_max;
+ };
}
#endif //BOUNDING_BOX_H
diff --git a/include/enemies.h b/include/enemies.h
index 8e0f3be..c550f3a 100644
--- a/include/enemies.h
+++ b/include/enemies.h
@@ -37,17 +37,19 @@ namespace td
struct enemy_instance_t
{
enemy_id_t id;
+ float health_left;
+ float percent_along_path;
};
class enemy_t
{
public:
- enemy_t(std::string texture_name, std::vector children, damage_type_t damage_resistence, blt::i32 health = 1, blt::i32 damage = 1,
+ enemy_t(std::string texture_name, std::vector children, damage_type_t damage_resistence, float health = 1, float damage = 1,
float speed = 1.0f);
enemy_t(std::string texture_name, std::vector children);
- [[nodiscard]] blt::i32 get_health() const
+ [[nodiscard]] float get_health() const
{
return m_health;
}
@@ -67,7 +69,7 @@ namespace td
return m_texture_name;
}
- [[nodiscard]] blt::i32 get_damage() const
+ [[nodiscard]] float get_damage() const
{
return m_damage;
}
@@ -77,7 +79,7 @@ namespace td
return m_speed;
}
- enemy_t& set_health(const blt::i32 value)
+ enemy_t& set_health(const float value)
{
m_health = value;
return *this;
@@ -101,7 +103,7 @@ namespace td
return *this;
}
- enemy_t& set_m_damage(const blt::i32 m_damage)
+ enemy_t& set_m_damage(const float m_damage)
{
this->m_damage = m_damage;
return *this;
@@ -117,8 +119,8 @@ namespace td
std::string m_texture_name;
std::vector m_children;
damage_type_t m_damage_resistence = damage_type_t::BASE;
- blt::i32 m_health = 1;
- blt::i32 m_damage = 1;
+ float m_health = 1;
+ float m_damage = 1;
float m_speed = 1.0f;
};
diff --git a/include/fwddecl.h b/include/fwddecl.h
index cb7856a..dd2a23a 100644
--- a/include/fwddecl.h
+++ b/include/fwddecl.h
@@ -45,6 +45,9 @@ namespace td
{
return (val & static_cast(type)) != 0;
}
+
+ class map_t;
+ class path_segment_t;
}
#endif //FWDDECL_H
diff --git a/include/game.h b/include/game.h
index b331d22..66a49f0 100644
--- a/include/game.h
+++ b/include/game.h
@@ -35,7 +35,6 @@ namespace td
void update();
private:
- std::vector enemies;
};
class event_handler_t
diff --git a/include/map.h b/include/map.h
index e086874..b0014b5 100644
--- a/include/map.h
+++ b/include/map.h
@@ -19,29 +19,46 @@
#ifndef MAP_H
#define MAP_H
-#include
-#include
-#include
#include
+#include
+#include
+#include
+#include
namespace td
{
class path_segment_t
{
+ friend map_t;
public:
- explicit path_segment_t(const blt::gfx::curve2d_t& curve): m_curve{curve}
- {}
+ explicit path_segment_t(const blt::gfx::curve2d_t& curve);
+
+ [[nodiscard]] const bounding_box_t& get_bounding_box() const
+ {
+ return m_bounding_box;
+ }
private:
+ static bounding_box_t get_bounding_box(const blt::gfx::curve2d_t& curve, blt::i32 segments);
+
+ bounding_box_t m_bounding_box;
blt::gfx::curve2d_t m_curve;
+ float m_curve_length;
std::vector m_enemies;
};
class map_t
{
public:
+ explicit map_t(const std::vector& path_segments): m_path_segments{path_segments}
+ {}
+
+ void update();
+
+ [[nodiscard]] blt::gfx::curve2d_mesh_data_t get_mesh_data(float thickness = 1) const;
private:
+ std::vector m_path_segments;
};
}
diff --git a/lib/blt-with-graphics b/lib/blt-with-graphics
index 66e764b..e1e2bb1 160000
--- a/lib/blt-with-graphics
+++ b/lib/blt-with-graphics
@@ -1 +1 @@
-Subproject commit 66e764be6be316c31a35bf62879a8bfc77f12006
+Subproject commit e1e2bb18a4e3dcf3d70ed10bdb5ed50b2490e161
diff --git a/src/bounding_box.cpp b/src/bounding_box.cpp
new file mode 100644
index 0000000..747cbac
--- /dev/null
+++ b/src/bounding_box.cpp
@@ -0,0 +1,42 @@
+/*
+ *
+ * Copyright (C) 2025 Brett Terpstra
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+#include
+
+namespace td
+{
+ bool bounding_box_t::contains(const blt::vec2& point) const
+ {
+ return point >= m_min && point <= m_max;
+ }
+
+ blt::vec2 bounding_box_t::get_center() const
+ {
+ const auto center = get_size() / 2.0f;
+ return m_min + center;
+ }
+
+ blt::vec2 bounding_box_t::get_size() const
+ {
+ return m_max - m_min;
+ }
+
+ bool bounding_box_t::intersects(const bounding_box_t& other) const
+ {
+ return other.m_min <= m_max && other.m_max >= m_min;
+ }
+}
diff --git a/src/enemies.cpp b/src/enemies.cpp
index 85b2d1e..5b2769f 100644
--- a/src/enemies.cpp
+++ b/src/enemies.cpp
@@ -17,8 +17,8 @@
*/
#include
-td::enemy_t::enemy_t(std::string texture_name, std::vector children, const damage_type_t damage_resistence, const blt::i32 health,
- const blt::i32 damage, const float speed): m_texture_name(std::move(texture_name)), m_children(std::move(children)),
+td::enemy_t::enemy_t(std::string texture_name, std::vector children, const damage_type_t damage_resistence, const float health,
+ const float damage, const float speed): m_texture_name(std::move(texture_name)), m_children(std::move(children)),
m_damage_resistence(damage_resistence), m_health(health), m_damage(damage),
m_speed(speed)
{}
diff --git a/src/map.cpp b/src/map.cpp
index 51f6189..06c0634 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -19,5 +19,39 @@
namespace td
{
+ path_segment_t::path_segment_t(const blt::gfx::curve2d_t& curve): m_bounding_box{get_bounding_box(curve, 32)}, m_curve{curve},
+ m_curve_length{curve.length(32)}
+ {}
+ bounding_box_t path_segment_t::get_bounding_box(const blt::gfx::curve2d_t& curve, const blt::i32 segments)
+ {
+ const auto lines = curve.to_lines(segments);
+ auto min = lines.front().p1;
+ auto max = lines.front().p1;
+ for (const auto& line : lines)
+ {
+ if (line.p1 < min)
+ min = line.p1;
+ if (line.p2 < min)
+ min = line.p2;
+ if (line.p1 > max)
+ max = line.p1;
+ if (line.p2 > max)
+ max = line.p2;
+ }
+ return bounding_box_t{min, max};
+ }
+
+ void map_t::update()
+ {
+
+ }
+
+ blt::gfx::curve2d_mesh_data_t map_t::get_mesh_data(const float thickness) const
+ {
+ blt::gfx::curve2d_mesh_data_t mesh_data;
+ for (const auto& segment : m_path_segments)
+ mesh_data.with(segment.m_curve.to_mesh(32, thickness));
+ return mesh_data;
+ }
}