Nimbin[12]?SDL & Graphics / mapcreator / commits / 886e56d

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

Fixes i think

Christian Immanuel · 2026-02-20 15:47 · 886e56d108f2a6ce747dcf4df51726c07c841638

 src/character/character.cpp | 48 ++++++++++++++++++++++++++-------------------
 src/character/character.hpp |  2 +-
 src/inventory/inventory.cpp |  4 ++--
 3 files changed, 31 insertions(+), 23 deletions(-)

diff --git a/src/character/character.cpp b/src/character/character.cpp
index 69f3da7..932150b 100644
--- a/src/character/character.cpp
+++ b/src/character/character.cpp
@@ -499,7 +499,7 @@ Character::find_ClosestObject(SDL_Point* tile_found, ObjectCategory category) {
 }
 
 void
-Character::collect_Start(TileObject* map_object_p, SDL_Point tile_point) {
+Character::collect_Start(TileObject* map_object_p) {
 
     if (!map_object_p) {
         std::cout << "No item!\n";
@@ -521,6 +521,9 @@ Character::collect_Start(TileObject* map_object_p, SDL_Point tile_point) {
         collect_Stop();
         return;
     }
+
+    std::cout << "CH " << collider_world.x << " " << collider_world.y << std::endl;
+    std::cout << "OB " << (object->world_tile_position.x+object->dimension.x/2)*16 << " " << (object->world_tile_position.y+object->dimension.y)*16-8 << std::endl;
     collecting_logic.duration_max = 3;
     // COLLECT RESOURCE
     if (object->object_type != ObjectType::VEGETABLE) {
@@ -532,28 +535,34 @@ Character::collect_Start(TileObject* map_object_p, SDL_Point tile_point) {
     }
     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 obj_x = (object->world_tile_position.x + object->dimension.x * 0.5f) * 16.0f;
+    float obj_y = (object->world_tile_position.y + object->dimension.y) * 16.0f - 8.0f;
 
-    float dy = (tile_point.y * Tile::tile_size + Tile::tile_size * 0.5f)
-             - (collider_world.y + collider.h * 0.5f);
+    float dx = obj_x - collider_world.x;
+    float dy = obj_y - collider_world.y;
 
-    // Horizontal dominates
-    if (std::fabs(dx) > std::fabs(dy)) {
-        if (dx < 0)
-            direction = WalkDirection::LEFT;
-        else
-            direction = WalkDirection::RIGHT;
-        flip = (dx < 0);
+    float angle = std::atan2(dy, dx);
+
+    const float pi = 3.14159265358979323846f;
+    const float quarter = pi * 0.25f;
+    const float three_quarter = pi * 0.75f;
+
+    if (angle >= -quarter && angle < quarter) {
+        direction = WalkDirection::RIGHT;
+        flip = false;
     }
-    // Vertical dominates
-    else {
-        if (dy > 0)
-            direction = WalkDirection::DOWN;
-        else
-            direction = WalkDirection::UP;
+    else if (angle >= quarter && angle < three_quarter) {
+        direction = WalkDirection::DOWN;
+        flip = false;
+    }
+    else if (angle >= -three_quarter && angle < -quarter) {
+        direction = WalkDirection::UP;
         flip = false;
     }
+    else {
+        direction = WalkDirection::LEFT;
+        flip = true;
+    }
 
     float cl = collecting_logic.duration_max/2;
     if (collecting_logic.duration_max > 3)
@@ -1813,7 +1822,7 @@ Character::handle_Input(Input& input, SDL_Rect win_size) {
         switch (object->category) {
             case ObjectCategory::RESOURCE:
             case ObjectCategory::FARM_CROP:
-                collect_Start(map_object_p, tile_point);
+                collect_Start(map_object_p);
                 std::cout << "STAT: " << (int)status << std::endl;
                 return;
             case ObjectCategory::BUILDING:
@@ -2273,7 +2282,6 @@ Character::set_VegetableDiscovery(VegetableData::Type vegetable) {
     
     discovered_vegetables[id] = true;
     messages->Add(MessageKey::DISCOVERED_VEGETABLE);
-    set_BuildingDiscovery();
 }
 
 
diff --git a/src/character/character.hpp b/src/character/character.hpp
index 040f37a..f79d769 100644
--- a/src/character/character.hpp
+++ b/src/character/character.hpp
@@ -264,7 +264,7 @@ class Character {
     float damage_Get();
 
     TileObject* find_ClosestObject(SDL_Point* tile_found, ObjectCategory category = ObjectCategory::NONE);
-    void collect_Start(TileObject* map_object_p, SDL_Point tile_point);
+    void collect_Start(TileObject* map_object_p);
     void collect_Object();
     void collect_Stop();
 
diff --git a/src/inventory/inventory.cpp b/src/inventory/inventory.cpp
index bbfb1ff..54160e3 100644
--- a/src/inventory/inventory.cpp
+++ b/src/inventory/inventory.cpp
@@ -1021,7 +1021,7 @@ Inventory_s* Inventory::get_SelectedHotbarItem() {
         item = &get_SeedById(hotbar[selected_hotbar].item_id);
 
     if (selected_hotbar == 0 || !item) {
-        std::cout << "Something is broken,... " << selected_hotbar << " " << hotbar[selected_hotbar].item_id << std::endl;
+        // std::cout << "Something is broken,... " << selected_hotbar << " " << hotbar[selected_hotbar].item_id << std::endl;
         return hotbar_hands;
     }
     return item;
@@ -1326,7 +1326,7 @@ bool Inventory::Load(const std::string &path) {
     // hotbar
     for (int i = 0; i < HOTBAR_SLOTS; ++i) {
         file.read(reinterpret_cast<char*>(&hotbar[i].item_id), sizeof(hotbar[i].item_id));
-        std::cout << "READ " << hotbar[i].item_id << std::endl;
+        //std::cout << "READ " << hotbar[i].item_id << std::endl;
         file.read(reinterpret_cast<char*>(&hotbar[i].type), sizeof(hotbar[i].type));
     }