diff --git a/.idea/editor.xml b/.idea/editor.xml
index d04f5f3..7dc090d 100644
--- a/.idea/editor.xml
+++ b/.idea/editor.xml
@@ -45,252 +45,482 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 72dcc3e..bb2012f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -51,7 +51,7 @@ macro(blt_add_project name source type)
project(tower-defense)
endmacro()
-project(tower-defense VERSION 0.0.21)
+project(tower-defense VERSION 0.0.22)
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
diff --git a/include/enemies.h b/include/enemies.h
index 206f65a..5ffd4ff 100644
--- a/include/enemies.h
+++ b/include/enemies.h
@@ -107,13 +107,13 @@ namespace td
return *this;
}
- enemy_t& set_m_damage(const float m_damage)
+ enemy_t& set_damage(const float m_damage)
{
this->m_damage = m_damage;
return *this;
}
- enemy_t& set_m_speed(const float m_speed)
+ enemy_t& set_speed(const float m_speed)
{
this->m_speed = m_speed;
return *this;
@@ -131,6 +131,11 @@ namespace td
class enemy_database_t
{
public:
+ enemy_database_t()
+ {
+ register_entities();
+ }
+
void add_enemy(enemy_id_t enemy_id, const enemy_t& enemy)
{
const auto index = static_cast(enemy_id);
diff --git a/include/map.h b/include/map.h
index 5ad324b..9623c70 100644
--- a/include/map.h
+++ b/include/map.h
@@ -74,7 +74,12 @@ namespace td
m_database{&database}
{}
- void draw();
+ void spawn(const enemy_id_t id)
+ {
+ m_path_segments.front().add_enemy(enemy_instance_t{id, m_database->get(id).get_health()});
+ }
+
+ void draw(blt::gfx::batch_renderer_2d& renderer);
float update();
diff --git a/lib/blt-with-graphics b/lib/blt-with-graphics
index 64223a0..bf3a7fe 160000
--- a/lib/blt-with-graphics
+++ b/lib/blt-with-graphics
@@ -1 +1 @@
-Subproject commit 64223a0cfd2fb2da0e2d02017b6cd7ccc3d7e8f0
+Subproject commit bf3a7fefd89d1c423f0b7016dab3f4659f5f132d
diff --git a/src/enemies.cpp b/src/enemies.cpp
index 5b2769f..83a2739 100644
--- a/src/enemies.cpp
+++ b/src/enemies.cpp
@@ -29,5 +29,5 @@ td::enemy_t::enemy_t(std::string texture_name, std::vector children)
void td::enemy_database_t::register_entities()
{
- add_enemy(enemy_id_t::TEST, enemy_t{"test", {}});
+ add_enemy(enemy_id_t::TEST, enemy_t{"test", {}}.set_speed(10));
}
diff --git a/src/main.cpp b/src/main.cpp
index 0799ee6..7ff7e37 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -16,8 +16,19 @@ float dir = 1;
blt::gfx::curve2d_t curve{blt::vec2{250, 250}, blt::vec2{350, 500}, blt::vec2{650, 500}, blt::vec2{750, 250}};
blt::gfx::curve2d_mesh_data_t mesh;
+using curve_t = blt::gfx::curve2d_t;
+using vec2 = blt::vec2f;
+curve_t c1{{0, 100}, {200, 100}};
+curve_t c2{{200, 100}, {300, 100}, {300, 300}};
+curve_t c3{{300, 300}, {300, 400}, {400, 400}};
+curve_t c4{{400, 400}, {500, 400}, {500, 500}};
+
+td::enemy_database_t database;
+td::map_t map{std::vector{td::path_segment_t{c1}, td::path_segment_t{c2}, td::path_segment_t{c3}, td::path_segment_t{c4}}, database};
+
void init(const blt::gfx::window_data&)
{
+ blt::gfx::setWindowSize(1440, 720);
using namespace blt::gfx;
resources.setPrefixDirectory("../");
@@ -40,11 +51,15 @@ void update(const blt::gfx::window_data& data)
camera.update_view(global_matrices);
global_matrices.update();
+ map.update();
+ map.draw(renderer_2d);
+
t += 0.01f * dir;
if (t >= 1)
{
t = 1;
dir = -1;
+ map.spawn(td::enemy_id_t::TEST);
} else if (t <= 0)
{
t = 0;
@@ -71,5 +86,5 @@ void destroy(const blt::gfx::window_data&)
int main()
{
- blt::gfx::init(blt::gfx::window_data{"My Sexy Window", init, update, destroy}.setSyncInterval(1).setWidth(1440).setHeight(720));
+ blt::gfx::init(blt::gfx::window_data{"My Sexy Window", init, update, destroy}.setSyncInterval(1));
}
diff --git a/src/map.cpp b/src/map.cpp
index 5088912..34ee474 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -52,6 +52,8 @@ namespace td
const auto length = segment.m_curve_length;
for (const auto [j, enemy] : blt::enumerate(segment.m_enemies))
{
+ if (!enemy.is_alive)
+ continue;
const auto& enemy_info = m_database->get(enemy.id);
const auto movement = (enemy_info.get_speed() / length) * PATH_SPEED_MULTIPLIER;
enemy.percent_along_path += movement;
@@ -61,8 +63,11 @@ namespace td
segment.m_empty_indices.emplace_back(j);
if (i != m_path_segments.size() - 1)
{
-
- }
+ auto& next_segment = m_path_segments[i + 1];
+ enemy_instance_t moved_enemy{enemy.id, enemy.health_left};
+ next_segment.add_enemy(moved_enemy);
+ } else
+ damage += enemy_info.get_damage();
}
}
}
@@ -70,6 +75,24 @@ namespace td
return damage;
}
+ void map_t::draw(blt::gfx::batch_renderer_2d& renderer)
+ {
+ // TODO: this is currently for debug
+ const auto mesh_data = get_mesh_data(10);
+ renderer.drawCurve(mesh_data, blt::make_color(0, 1, 0));
+ for (const auto& segment : m_path_segments)
+ {
+ for (const auto& enemy : segment.m_enemies)
+ {
+ if (!enemy.is_alive)
+ continue;
+ const auto point = segment.m_curve.get_point(enemy.percent_along_path);
+ constexpr blt::vec2f size{10, 10};
+ renderer.drawRectangle(blt::gfx::rectangle2d_t{point, size}, blt::make_color(1, 0, 0), 1);
+ }
+ }
+ }
+
blt::gfx::curve2d_mesh_data_t map_t::get_mesh_data(const float thickness) const
{
blt::gfx::curve2d_mesh_data_t mesh_data;