Nimbin[12]?SDL & Graphics / mapcreator / commits / a4b9380

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 bug

Christian Immanuel · 2025-12-28 23:38 · a4b9380adeb2ca92f2facbd74ec014d3aa6c19d8

 saves/save.map              | Bin 985016 -> 984232 bytes
 saves/save.tileset_objects  | Bin 27624 -> 27624 bytes
 src/bird/bird.cpp           |   4 +-
 src/character/character.cpp |  89 ++++++++++++++++++++++++--------------------
 src/game/state_playing.cpp  |   1 -
 src/map/map.cpp             |  20 ++++++----
 6 files changed, 62 insertions(+), 52 deletions(-)

diff --git a/saves/save.map b/saves/save.map
index 54f504f..39beda8 100644
Binary files a/saves/save.map and b/saves/save.map differ
diff --git a/saves/save.tileset_objects b/saves/save.tileset_objects
index e622c76..40198ef 100644
Binary files a/saves/save.tileset_objects and b/saves/save.tileset_objects differ
diff --git a/src/bird/bird.cpp b/src/bird/bird.cpp
index fd1c70c..46f8bad 100644
--- a/src/bird/bird.cpp
+++ b/src/bird/bird.cpp
@@ -365,7 +365,6 @@ void Bird::Decide(const SDL_FPoint& player_pos) {
         return;
     }
     if (state == BirdState::START_TO_FLY) {
-        std::cout << "FUU 1 " << std::endl;
         set_State(BirdState::FLYING, 0.0);
         return;
     }
@@ -374,8 +373,9 @@ void Bird::Decide(const SDL_FPoint& player_pos) {
     int   choice   = rand() % 100;
     float duration = rand() %  70 * 0.1f + 1.1f;
 
+    std::cout << choice << std::endl;
+
     if (state == BirdState::STOP_FLYING) {
-        std::cout << "FUU 2 " << std::endl;
         set_State(BirdState::IDLE, duration);
         return;
     }
diff --git a/src/character/character.cpp b/src/character/character.cpp
index 35c4eb5..1f07ebc 100644
--- a/src/character/character.cpp
+++ b/src/character/character.cpp
@@ -453,54 +453,60 @@ Character::collect_Start(TileObject* map_object_p, SDL_Point tile_point) {
     if (!map_object_p) {
         std::cout << "No item!\n";
         collecting_logic.is_collecting = false;
-    } else {
+        return;
+    }
         //Tile::print_TileObject(*map_object_p);
-        Object* object = Object::get_ObjectById(map_object_p->object_id);
+    Object* object = Object::get_ObjectById(map_object_p->object_id);
 
-        set_Status(CharacterStatus::COLLECT);
-        std::cout << "stat: " << (int)status << std::endl;
+    set_Status(CharacterStatus::COLLECT);
+    std::cout << "stat: " << (int)status << std::endl;
 
-        collecting_logic.duration = 0;
-        collecting_logic.object = map_object_p;
-        std::cout << "Item found!\n";
-        if (!map_object_p || (object->category != ObjectCategory::RESOURCE &&
-                             object->category != ObjectCategory::FARM_CROP)) {
-            std::cout << "Invalid object: " << (int)object->category << std::endl;
-            collect_Stop();
-            return;
-        }
-        collecting_logic.duration_max = 3;
-        if (object->object_type != ObjectType::VEGETABLE) {
-            collecting_logic.resource = Tile::get_ResourceFromTileSet(object->tileset_id, object->tileset_object_id);
-            collecting_logic.duration_max = collecting_logic.resource.collecting_duration;
-        } else {
-            collecting_logic.duration_max = static_cast<Vegetable*>(object)->collecting_duration_max;
-        }
-        collecting_logic.is_collecting = true;
+    collecting_logic.duration = 0;
+    collecting_logic.object = map_object_p;
+    std::cout << "Item found!\n";
+    if (!map_object_p || (object->category != ObjectCategory::RESOURCE &&
+                         object->category != ObjectCategory::FARM_CROP)) {
+        std::cout << "Invalid object: " << (int)object->category << std::endl;
+        collect_Stop();
+        return;
+    }
+    collecting_logic.duration_max = 3;
+    if (object->object_type != ObjectType::VEGETABLE) {
+        collecting_logic.resource = Tile::get_ResourceFromTileSet(object->tileset_id, object->tileset_object_id);
+        collecting_logic.duration_max = collecting_logic.resource.collecting_duration;
+    } else {
+        collecting_logic.duration_max = static_cast<Vegetable*>(object)->collecting_duration_max;
+    }
+    collecting_logic.is_collecting = true;
 
-        float dx = (tile_point.x * Tile::tile_size + Tile::tile_size * 0.5f)
-                 - (collider_world.x + collider.w * 0.5f);
+    float dx = (tile_point.x * Tile::tile_size + Tile::tile_size * 0.5f)
+             - (collider_world.x + collider.w * 0.5f);
 
-        float dy = (tile_point.y * Tile::tile_size + Tile::tile_size * 0.5f)
-                 - (collider_world.y + collider.h * 0.5f);
+    float dy = (tile_point.y * Tile::tile_size + Tile::tile_size * 0.5f)
+             - (collider_world.y + collider.h * 0.5f);
 
-        // Horizontal dominates
-        if (std::fabs(dx) > std::fabs(dy)) {
-            if (dx < 0)
-                direction = WalkDirection::LEFT;
-            else
-                direction = WalkDirection::RIGHT;
-            flip = (dx < 0);
-        }
-        // Vertical dominates
-        else {
-            if (dy > 0)
-                direction = WalkDirection::DOWN;
-            else
-                direction = WalkDirection::UP;
-            flip = false;
-        }
+    // Horizontal dominates
+    if (std::fabs(dx) > std::fabs(dy)) {
+        if (dx < 0)
+            direction = WalkDirection::LEFT;
+        else
+            direction = WalkDirection::RIGHT;
+        flip = (dx < 0);
+    }
+    // Vertical dominates
+    else {
+        if (dy > 0)
+            direction = WalkDirection::DOWN;
+        else
+            direction = WalkDirection::UP;
+        flip = false;
     }
+
+    float cl = collecting_logic.duration_max/2;
+    if (collecting_logic.duration_max > 3)
+        cl /= 2;
+    Animation::animation_frame_time = cl / active_anim->frames.size();
+    handle_Animation();
 }
 
 void
@@ -1666,6 +1672,7 @@ void Character::Update() {
         BuildingData::update_ActiveBuildData(collider_world.x, collider_world.y - collider.h);
 
     handle_Move();
+    handle_Animation();
 }
 
 
diff --git a/src/game/state_playing.cpp b/src/game/state_playing.cpp
index 6df48c1..a5a4849 100644
--- a/src/game/state_playing.cpp
+++ b/src/game/state_playing.cpp
@@ -198,7 +198,6 @@ void StatePlaying::Update(Game* game) {
     // CHARACTER
     player->handle_Input(game->input, game->win_size);
     player->Update();
-    player->handle_Animation();
 
     // MESSAGES
     player->messages->Update();
diff --git a/src/map/map.cpp b/src/map/map.cpp
index 717c11b..e4c5aee 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -481,16 +481,16 @@ namespace Map {
 
                 // SET DATA TO REAL OBJECT AND MAP OBJECT
                 SDL_Point wp = {static_cast<int>(x)-obj.position.x, static_cast<int>(y)-obj.position.y};
-                std::vector<Object*> os = Object::get_ObjectsByWorldPosition(wp);
                 Object* o = Object::get_ObjectByWorldPositionAndTilesetObjectID(wp, obj.tileset_info.object_id);
-
+                Object* on = nullptr;
 
                 SDL_Point dim = {obj.position.w, obj.position.h};
 
+
                 switch (category) {
 
                     case ObjectCategory::STATIC: {
-                        o = new Static(
+                        on = new Static(
                                 static_cast<ObjectType>(object_type),
                                 ObjectCategory::STATIC,
                                 tileset_type,
@@ -507,7 +507,7 @@ namespace Map {
                                 obj.tileset_info.set_id,
                                 obj.tileset_info.object_id);
 
-                        o = new Resource(
+                        on = new Resource(
                                 static_cast<ObjectType>(object_type),
                                 ObjectCategory::RESOURCE,
                                 tileset_type,
@@ -558,7 +558,7 @@ namespace Map {
                             frac_b[static_cast<ResourceType>(r)] = v;
                         }
 
-                        o = new Building(
+                        on = new Building(
                                 static_cast<ObjectType>(object_type),
                                 ObjectCategory::BUILDING,
                                 tileset_type,
@@ -569,7 +569,7 @@ namespace Map {
                                 obj.z_index,
                                 bt);
 
-                        Building* b = static_cast<Building*>(o);
+                        Building* b = static_cast<Building*>(on);
                         b->building_status   = status;
                         b->building_time     = time;
                         b->cost_fulfilled    = std::move(cost_f);
@@ -600,7 +600,7 @@ namespace Map {
                         file.read(reinterpret_cast<char*>(&slot), sizeof(slot));
                         v->equipement_slot = static_cast<EquipmentSlot>(slot);
 
-                        o = v;
+                        on = v;
                         break;
                     }
 
@@ -608,7 +608,11 @@ namespace Map {
                         break;
                 }
 
-                if (o) Object::objects.push_back(o);
+
+                if (!o && on) {
+                    Object::objects.push_back(on);
+                    o = on;
+                }
 
                 /*
                 std::cout << "OP: " << obj.position.x << " " << obj.position.y << " ID " << o->id << std::endl;