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

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 zindex and stuff

Christian Immanuel · 2025-12-18 13:26 · ab3bb11f31ab8824cadb5e23fee391e0c880b8c6

 src/bird/bird.cpp            |  5 ++---
 src/building/building.hpp    |  2 +-
 src/game/game.hpp            |  2 ++
 src/game/state_menu_main.cpp |  4 +++-
 src/game/state_menu_main.hpp |  3 ++-
 src/game/state_playing.cpp   | 35 +++++++++++++++++---------------
 src/inventory/inventory.cpp  |  2 +-
 src/map/map.cpp              | 48 ++++++++++++++++++--------------------------
 src/map/tile.cpp             |  2 +-
 src/objects/object.cpp       | 28 +++++++++++++++++---------
 10 files changed, 69 insertions(+), 62 deletions(-)

diff --git a/src/bird/bird.cpp b/src/bird/bird.cpp
index 8a9de8a..5ffb3e8 100644
--- a/src/bird/bird.cpp
+++ b/src/bird/bird.cpp
@@ -48,8 +48,7 @@ void Bird::Update(double delta_s, const SDL_FPoint& player_pos) {
     // Make decisions when idle on ground
     //if (landing_cooldown <= 0.0 && state == BirdState::IDLE && on_ground && decision_timer >= 2.0) {
     if ( decision_timer <= 0 &&
-         state != BirdState::FLYING &&
-         state != BirdState::WALKING) {
+         state != BirdState::FLYING) {
         Decide(player_pos);
     }
 
@@ -385,7 +384,7 @@ void Bird::Decide(const SDL_FPoint& player_pos) {
         set_State(BirdState::EATING, duration);
     }
     else if (choice < 50) {
-        set_State(BirdState::WALKING, duration);
+        set_State(BirdState::WALKING, duration+1);
         pick_GroundTarget(player_pos);
     }
     else if (choice < 75) {
diff --git a/src/building/building.hpp b/src/building/building.hpp
index 9b4b4fc..330d3c1 100644
--- a/src/building/building.hpp
+++ b/src/building/building.hpp
@@ -13,7 +13,7 @@
 #include "inventory/inventory.hpp"
 
 
-enum class BuildingStatus {
+enum class BuildingStatus : uint32_t {
     CONSTRUCTING,
     CONSTRUCTED,
     DECONSTRUCT
diff --git a/src/game/game.hpp b/src/game/game.hpp
index 00256c1..3bf2450 100644
--- a/src/game/game.hpp
+++ b/src/game/game.hpp
@@ -32,6 +32,8 @@ public:
     SDL_Window*   window   = nullptr;
     SDL_Renderer* renderer = nullptr;
 
+    bool is_cheating = false;
+
     std::unique_ptr<StatePlaying> state_playing;
     GameState*    state_current = nullptr;
     GameState_e   state_current_e = GameState_e::STATE_MENU_MAIN;
diff --git a/src/game/state_menu_main.cpp b/src/game/state_menu_main.cpp
index bfe8e3c..7d842b8 100644
--- a/src/game/state_menu_main.cpp
+++ b/src/game/state_menu_main.cpp
@@ -20,6 +20,7 @@ bool StateMenuMain::Init(Game* game) {
     buttons.push_back({ MenuState::LOAD,  "Load Game", {300, 260, 200, 50}, false});
     buttons.push_back({ MenuState::NEW,   "New Game",  {300, 200, 200, 50}, false});
     buttons.push_back({ MenuState::QUIT,  "Quit",      {300, 320, 200, 50}, false});
+    buttons.push_back({ MenuState::NEW_CHEAT,   "New Cheat",  {300, 200, 200, 50}, false});
     return true;
 }
 
@@ -28,8 +29,9 @@ void runState(MenuState state, Game* game) {
         case MenuState::CONTI: game->set_State(GameState_e::STATE_PLAYING, NewGameState_e::NONE); break;
         case MenuState::SAVE:  game->Save(game->active_game_dir); break;
         case MenuState::LOAD:  game->set_State(GameState_e::STATE_PLAYING, NewGameState_e::LOAD); break;
-        case MenuState::NEW:   game->set_State(GameState_e::STATE_PLAYING, NewGameState_e::NEW); break;
+        case MenuState::NEW:   game->is_cheating = false; game->set_State(GameState_e::STATE_PLAYING, NewGameState_e::NEW); break;
         case MenuState::QUIT:  game->running = false; break;
+        case MenuState::NEW_CHEAT:   game->is_cheating = true; game->set_State(GameState_e::STATE_PLAYING, NewGameState_e::NEW); break;
     }
 
 }
diff --git a/src/game/state_menu_main.hpp b/src/game/state_menu_main.hpp
index 4ffceab..fe82513 100644
--- a/src/game/state_menu_main.hpp
+++ b/src/game/state_menu_main.hpp
@@ -11,7 +11,8 @@ enum class MenuState {
     SAVE,
     LOAD,
     NEW,
-    QUIT
+    QUIT,
+    NEW_CHEAT
 };
 
 struct MenuButton {
diff --git a/src/game/state_playing.cpp b/src/game/state_playing.cpp
index ab7cf88..37b71e5 100644
--- a/src/game/state_playing.cpp
+++ b/src/game/state_playing.cpp
@@ -25,6 +25,7 @@ bool StatePlaying::Init(Game* game) {
 
     player = std::make_unique<Character>();
     player->Init(game->renderer);
+    std::cout << "JOOOOOO\n";
     player->researched_items[static_cast<size_t>(ItemType::BUILDING_TOOL)] = true;
 
     // INIT Weapons
@@ -47,22 +48,24 @@ bool StatePlaying::Init(Game* game) {
 
 
     // START CHEAT
-    player->inventory->add_Resource(ResourceType::WOOD, 120, player->messages.get());
-    player->inventory->add_Resource(ResourceType::STONE, 120, player->messages.get());
-    player->inventory->add_Resource(ResourceType::CLAY, 120, player->messages.get());
-    player->inventory->add_Resource(ResourceType::IRON, 120, player->messages.get());
-    player->set_ResourceDiscovery(ResourceType::WOOD);
-    player->set_ResourceDiscovery(ResourceType::STONE);
-    player->set_ResourceDiscovery(ResourceType::CLAY);
-    player->set_ResourceDiscovery(ResourceType::IRON);
-    player->researched_items[static_cast<size_t>(ItemType::SWORD_WOOD)] = true;
-    player->researched_items[static_cast<size_t>(ItemType::CULTIVATOR)] = true;
-    player->researched_buildings[static_cast<size_t>(BuildingType::CRAFTING_WOOD_1)] = true;
-    player->set_BuildingDiscovery();
-    player->inventory->add_Item(ItemType::SWORD_WOOD, player->messages.get());
-    player->inventory->add_Item(ItemType::BUILDING_TOOL, player->messages.get());
-    player->inventory->add_Item(ItemType::CULTIVATOR, player->messages.get());
-    player->inventory->add_Vegetable(VegetableData::Type::CARROT, 4, player->messages.get());
+    if (game->is_cheating) {
+        player->inventory->add_Resource(ResourceType::WOOD, 120, player->messages.get());
+        player->inventory->add_Resource(ResourceType::STONE, 120, player->messages.get());
+        player->inventory->add_Resource(ResourceType::CLAY, 120, player->messages.get());
+        player->inventory->add_Resource(ResourceType::IRON, 120, player->messages.get());
+        player->set_ResourceDiscovery(ResourceType::WOOD);
+        player->set_ResourceDiscovery(ResourceType::STONE);
+        player->set_ResourceDiscovery(ResourceType::CLAY);
+        player->set_ResourceDiscovery(ResourceType::IRON);
+        player->researched_items[static_cast<size_t>(ItemType::SWORD_WOOD)] = true;
+        player->researched_items[static_cast<size_t>(ItemType::CULTIVATOR)] = true;
+        player->researched_buildings[static_cast<size_t>(BuildingType::CRAFTING_WOOD_1)] = true;
+        player->set_BuildingDiscovery();
+        player->inventory->add_Item(ItemType::SWORD_WOOD, player->messages.get());
+        player->inventory->add_Item(ItemType::BUILDING_TOOL, player->messages.get());
+        player->inventory->add_Item(ItemType::CULTIVATOR, player->messages.get());
+        player->inventory->add_Vegetable(VegetableData::Type::CARROT, 4, player->messages.get());
+    }
     // END CHEAT
 
 
diff --git a/src/inventory/inventory.cpp b/src/inventory/inventory.cpp
index 292f9d5..1768ed0 100644
--- a/src/inventory/inventory.cpp
+++ b/src/inventory/inventory.cpp
@@ -31,7 +31,7 @@ bool Inventory::clicked_button_craft = false;
 int  Inventory::selected_hotbar      = 0;
 int  Inventory::selected_hotbar_last = 0;
 
-Equipement    Inventory::hotbar[HOTBAR_SLOTS];
+Equipement     Inventory::hotbar[HOTBAR_SLOTS];
 InventoryItem* Inventory::hotbar_hands = nullptr;
 
 ItemType Inventory::selected_build_item = ItemType::NONE;
diff --git a/src/map/map.cpp b/src/map/map.cpp
index f22ddd6..287b9cb 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -850,8 +850,8 @@ namespace Map {
 #endif
                 //if (o.position.x != 0 || o.position.y != o.position.h-1) continue;
                 // real object 0,0 start in map pixel
-                float m_xf = xf - o.position.x*static_cast<float>(Tile::tile_size); 
-                float m_yf = yf - o.position.y*static_cast<float>(Tile::tile_size); 
+                float m_xf = xf - o.position.x*size; 
+                float m_yf = yf - o.position.y*size; 
 
                 float width  = static_cast<int>(object->dimension.x) * size;
                 float height = static_cast<int>(object->dimension.y) * size;
@@ -867,7 +867,7 @@ namespace Map {
 
                 if (!isInView(obj_bb.x, obj_bb.y, obj_bb.w, obj_bb.h, win_size))
                     continue;
-                if (!o.draw_from_this_tile) continue;
+                //if (!o.draw_from_this_tile) continue;
 
                 size_t j = 0;
                 //std::cout << "PS "<< o.position.x<< " " <<o.position.y <<std::endl;
@@ -899,48 +899,34 @@ namespace Map {
                     }
                     j++;
                 }
-                SDL_FRect char_r = {character_collider_x,
-                                            character_collider_y,
-                                            player.collider.w,
-                                            player.collider.h};
-                SDL_FRect object_rect = {m_xf, m_yf, static_cast<float>(object->dimension.x), static_cast<float>(object->dimension.y)};
-                bool is_char_obj_intersec = SDL_HasRectIntersectionFloat(&object_rect, &char_r);
-                if ( character_collider_x >= m_xf &&
-                     character_collider_y >= m_yf &&
-                     character_collider_x + player.collider.w <= m_point.x &&
-                     character_collider_y <= m_point.y &&
-                     object->z_index > 0) {
-                    std::cout << "ID " << object->z_index << std::endl;
-
-                    player_behind = true;
+
+
+
+                    player_behind = false;
                     if ( object->is_InFrontOf({m_xf, m_yf},
                                            {character_collider_x,
                                             character_collider_y,
                                             player.collider.w,
                                             player.collider.h})) {
+                        player_behind = true;
                         if (!character_drawn) {
+                            std::cout << "DRAW BEHIND\n";
                             player.Draw(renderer);
                             character_drawn = true;
                         }
-                    } else
-                        player_behind = false;
+                    }
+                    std::cout <<  player_behind << std::endl;
+                    std::cout << "CHA: " << character_collider_x << " " << character_collider_y << " " << player.collider.w << " " << player.collider.h << std::endl;
+                    std::cout << "OJJ: " << m_xf << " " << m_yf << " " << m_point.x << " " << m_point.y << std::endl;
 
-                }
 
 
                 // START OBJECT DRAW
-                object->Draw(renderer, {m_xf, m_yf}, player_behind);
+                if (o.draw_from_this_tile)
+                    object->Draw(renderer, {m_xf, m_yf}, player_behind);
                 // END OBJECT DRAW
 
             }
-            if ( !character_drawn &&
-                 player.collider_world.x >= xf &&
-                 player.collider_world.x <= xy_point.x &&
-                 player.collider_world.y >= yf &&
-                 player.collider_world.y <= xy_point.y) {
-                player.Draw(renderer);
-                character_drawn = true;
-            }
             size_t j = 0;
             for (Enemy* enemy : Enemy::enemies) {
                 if ( !enemies_drawn[j] &&
@@ -965,6 +951,10 @@ namespace Map {
                 bird->drawn = true;
             }
         }
+        if ( !character_drawn ) {
+            player.Draw(renderer);
+            character_drawn = true;
+        }
         for (Bird* bird : Bird::birds) {
             if (bird->drawn)
                 continue;
diff --git a/src/map/tile.cpp b/src/map/tile.cpp
index a19a7fb..90080f5 100644
--- a/src/map/tile.cpp
+++ b/src/map/tile.cpp
@@ -1255,7 +1255,7 @@ namespace Tile {
                                 o.draw_from_this_tile = true;
                             draw_is_set = true;
                         }
-                        if (!shall_set_on_tile) continue;
+                        //if (!shall_set_on_tile) continue;
                         
                         // make sure we dont get dublicates
                         if (check_existence) {
diff --git a/src/objects/object.cpp b/src/objects/object.cpp
index 3fdad44..7b24036 100644
--- a/src/objects/object.cpp
+++ b/src/objects/object.cpp
@@ -74,22 +74,29 @@ Object::is_InFrontOf(SDL_FPoint world_position, SDL_FRect rect) {
     const int rect_x = rect.x / Tile::tile_collider_size;
     const int rect_y = rect.y / Tile::tile_collider_size;
     const int rect_w = (rect.w + Tile::tile_collider_size - 1) / Tile::tile_collider_size;
+    const int rect_h = (rect.h + Tile::tile_collider_size - 1) / Tile::tile_collider_size;
 
-    //std::cout << "OB " << obj_x << " " << obj_y << " " << obj_w << " " << obj_h << std::endl;
-    //std::cout << "RE " << rect_x << " " << rect_y << " " << rect_w << std::endl;
+    std::cout << "WP: " << world_position.x << " " << world_position.y << std::endl;
+    std::cout << "OB " << obj_x << " " << obj_y << " " << obj_w << " " << obj_h << std::endl;
+    std::cout << "RE " << rect_x << " " << rect_y << " " << rect_w << std::endl;
     const int row_width = obj_w;
 
+    // object is left or right of rect
     if (rect_x + rect_w <= obj_x || rect_x >= obj_x + obj_w)
-        return true;
+        return false;
 
     int start_x = std::max(rect_x, obj_x) - obj_x;
     int end_x   = std::min(rect_x + rect_w, obj_x + obj_w) - obj_x;
 
-    if (rect_y < obj_y)
+    // is above object
+    if (rect_y+rect_h < obj_y)
         return true;
+    // is below object
+    if (obj_y + obj_h <= rect_y)
+        return false;
 
+    //
     int rect_row = rect_y - obj_y;
-
     if (rect_row >= obj_h)
         return true;
 
@@ -107,7 +114,7 @@ Object::is_InFrontOf(SDL_FPoint world_position, SDL_FRect rect) {
                     //std::cout << "ABOVE \n";
                     anywhere_above = true;
                     if (x > start_x && x < end_x) {
-                        //std::cout << "SUPABOVE \n";
+                        std::cout << "SUPABOVE \n";
                         //collission_above = true;
                         return false;
                     }
@@ -123,12 +130,15 @@ Object::is_InFrontOf(SDL_FPoint world_position, SDL_FRect rect) {
         }
     }
     if ( !has_collision ) {
+        std::cout << "NO COLL\n";
         SDL_FRect temp_rect = { world_position.x, world_position.y, static_cast<float>(dimension.x*Tile::tile_size), static_cast<float>(dimension.y*Tile::tile_size) };
-        std::cout << "COLL " << SDL_HasRectIntersectionFloat(&temp_rect, &rect) <<  " " << world_position.x << " " << world_position.y << " " << rect.x << " " << rect.y <<std::endl;
-        std::cout << "WIDH " << dimension.x *Tile::tile_size<< " " << dimension.y *Tile::tile_size<< " RE " << rect.w << " " << rect.h << std::endl;
-        return SDL_HasRectIntersectionFloat(&temp_rect, &rect);
+        //std::cout << "COLL " << SDL_HasRectIntersectionFloat(&temp_rect, &rect) <<  " " << world_position.x << " " << world_position.y << " " << rect.x << " " << rect.y <<std::endl;
+        //std::cout << "WIDH " << dimension.x *Tile::tile_size<< " " << dimension.y *Tile::tile_size<< " RE " << rect.w << " " << rect.h << std::endl;
+        if (z_index <= 0 ) return false;
+        return !SDL_HasRectIntersectionFloat(&temp_rect, &rect);
     }
 
+    std::cout << "COL " << collission_below << " " << anywhere_below << " " << anywhere_above << std::endl;
     if ((collission_below || anywhere_below) && !anywhere_above)
         return true;
     if (!anywhere_above && !collission_below)