Nimbin[12]?SDL & Graphics / mapcreator / commits / 8c11056

mapcreator git · master

SDL3 2.5D game and engine using assets, with map editor

sdl3 c++ game engine map-editor cmake · first commit 2025-10-31 · last commit 2026-09-07 (1 month ago) · synced 3 days ago · upstream: git.ide3.de/hsnr/sdl-spieleentwicklung/map_creator

C++ 99.3%
git clone https://git.christianimmanuel.de/sdl-graphics/mapcreator.gitwget https://git.christianimmanuel.de/sdl-graphics/mapcreator/archive/mapcreator.tar.gz

Fix enemy staying idle

Christian Immanuel · 2026-02-16 17:03 · 8c11056f43a14759af3c1e61d544d57f5c96118c

 src/character/enemy.cpp | 17 +++++++++++------
 src/character/enemy.hpp |  2 ++
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/character/enemy.cpp b/src/character/enemy.cpp
index ab3bc0d..c420dc5 100644
--- a/src/character/enemy.cpp
+++ b/src/character/enemy.cpp
@@ -25,12 +25,15 @@ bool Enemy::stop_threads = false;
 int Enemy::jobs_remaining = 0;
 std::condition_variable Enemy::jobs_done_cv;
 
+int Enemy::id_next = 1;
+
 Enemy::Enemy(WeaponType weapon_type, WeaponMaterial weapon_material, SDL_FPoint position, EnemyStats status)
     : weapon(weapon_type, weapon_material) {
         x = position.x;
         y = position.y;
         stats = status;
 
+        id = id_next++;
 
         speed = 40.0f;
         run = 1.4f;
@@ -316,7 +319,6 @@ static inline double ms_since(Uint64 start) {
 */
 
 int EnemyWorkerThread(void*) {
-    std::cout << "WORK!\n";
     while (true) {
         std::unique_lock<std::mutex> lock(Enemy::queue_mutex);
         Enemy::queue_cv.wait(lock, [] {
@@ -748,8 +750,8 @@ void Enemy::move_Path() {
         moving_logic.moving_distance.y += std::abs(dy);
         moving_logic.path_blocked = 0.0;
     } else {
-        float dx = next_position.x - collider_world.x;
-        float dy = next_position.y - collider_world.y;
+        float dx = test.x - collider_world.x;
+        float dy = test.y - collider_world.y;
         float len = std::sqrt(dx * dx + dy * dy);
         dx /= len;
         dy /= len;
@@ -990,16 +992,16 @@ Enemy::Update(Character& player) {
     // DECIDE // REDECIDE
     if ( moving_logic.move_type == EnemyMovingType::NONE || (
           moving_logic.move_type == EnemyMovingType::IDLE &&
-          moving_logic.duration <= 0 && !moving_logic.avoid_blockage)) {
+          moving_logic.duration <= 0)) {
         Decide(player);
         handle_Animation();
-        //std::cout << "MVT1 " << (int)moving_logic.move_type << std::endl;
+        std::cout << "MVT1 " << id << " "  << (int)moving_logic.move_type << std::endl;
         return;
     } else
     if (moving_logic.move_type == EnemyMovingType::IDLE) {
-        std::cout << "moving_logic.duration" << moving_logic.duration << std::endl;
         moving_logic.duration -= Default::delta_time;
         handle_Animation();
+        std::cout << "IDLE? " << id << std::endl;
         return;
     } else
     if (moving_logic.move_type == EnemyMovingType::WALK) {
@@ -1008,11 +1010,14 @@ Enemy::Update(Character& player) {
              moving_logic.moving_distance.y >= moving_logic.max_distance ) {
             moving_logic.move_type = EnemyMovingType::NONE;
             handle_Animation();
+            std::cout << "BLOCKED? " << id << std::endl;
             return;
         }
     }
 
 
+    std::cout << "ID: " << id << std::endl;
+
     float  d_x  = moving_logic.position.x - collider_world.x;
     float  d_y  = moving_logic.position.y - collider_world.y;
     /*
diff --git a/src/character/enemy.hpp b/src/character/enemy.hpp
index 21c763a..cdd3a60 100644
--- a/src/character/enemy.hpp
+++ b/src/character/enemy.hpp
@@ -87,6 +87,8 @@ struct WorkerData {
 };
 
 class Enemy {
+    static int id_next;
+           int id;
     float  speed;
     float  run; // multiplier
     bool   flip;