mapcreator git · master
SDL3 2.5D game and engine using assets, with map editor
C++ 99.3%git clone https://git.christianimmanuel.de/sdl-graphics/mapcreator.gitwget https://git.christianimmanuel.de/sdl-graphics/mapcreator/archive/mapcreator.tar.gzAdd dirty cam
src/building/building_data.cpp | 2 +- src/character/character.cpp | 5 +++-- src/character/character.hpp | 2 +- src/character/enemy.cpp | 5 ++--- src/game/game.cpp | 3 +++ src/game/state_playing.cpp | 35 +++++++++++++++++++++++++++++++++++ src/inventory/item.cpp | 2 +- 7 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/building/building_data.cpp b/src/building/building_data.cpp index 71dfd7a..4c8b410 100644 --- a/src/building/building_data.cpp +++ b/src/building/building_data.cpp @@ -392,7 +392,7 @@ namespace BuildingData { MENU_BG_COLOR_B, MENU_BG_COLOR_A ); - SDL_FRect bg = { menu_x, Ui::top_bar_height, MENU_W, MENU_H }; + SDL_FRect bg = { menu_x, 0, MENU_W, MENU_H }; SDL_RenderFillRect(renderer, &bg); // DRAW diff --git a/src/character/character.cpp b/src/character/character.cpp index 11e0da1..900f368 100644 --- a/src/character/character.cpp +++ b/src/character/character.cpp @@ -1282,8 +1282,6 @@ Character::handle_Input(Input& input, SDL_Rect win_size) { SDL_Point tile_point; TileObject* map_object_p = find_ClosestObject(&tile_point, ObjectCategory::NONE); if (!map_object_p) { - std::cout << "Nothing to interact with!\n"; - messages->Add(MessageKey::NOTHING_TO_INTERACT); // check for river for (auto [x,y] : tiles_in_reach) { if (x < 0 || y < 0 || x >= Map::size.x || y >= Map::size.y) { @@ -1300,8 +1298,11 @@ Character::handle_Input(Input& input, SDL_Rect win_size) { std::cout << "River found!\n"; drink_Start(); // character rotate to tile + return; } } + std::cout << "Nothing to interact with!\n"; + messages->Add(MessageKey::NOTHING_TO_INTERACT); return; } diff --git a/src/character/character.hpp b/src/character/character.hpp index f470e82..7c97293 100644 --- a/src/character/character.hpp +++ b/src/character/character.hpp @@ -141,7 +141,6 @@ class Character { float sprint_multiply; bool is_sprinting = false; bool flip = false; - size_t tile_size; // this is the size of the texture float arm_reach_radius = 0; bool is_placing_build = false; @@ -150,6 +149,7 @@ class Character { unclocked__buildings; public: + size_t tile_size; // this is the size of the texture CharacterMenuType active_menu; Inventory_s* selected_item; AnimationData* active_anim = nullptr; diff --git a/src/character/enemy.cpp b/src/character/enemy.cpp index 77a7c98..4a76807 100644 --- a/src/character/enemy.cpp +++ b/src/character/enemy.cpp @@ -39,7 +39,7 @@ Enemy::Enemy(WeaponType weapon_type, WeaponMaterial weapon_material, SDL_FPoint max_death_time = 10.0; - stats = { 4, 4, 1, false, false, 0, 1.8 }; + stats = { 4, 4, 1, false, false, 0, 1.2 }; death_duration = 0; death_duration_max = 0.8; @@ -914,8 +914,7 @@ Enemy::attack_Stop() { void Enemy::getting_Hit(float demage) { - if (status != EnemyStatus::HIT) - set_Status(EnemyStatus::HIT); + // if (status != EnemyStatus::HIT) set_Status(EnemyStatus::HIT); stats.health -= demage; #ifdef DEBUG_BUILD diff --git a/src/game/game.cpp b/src/game/game.cpp index 724bd3d..2b898b2 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -176,6 +176,9 @@ void Game::Run() { void Game::handle_Events() { SDL_Event event; + //SDL_GetWindowSize(window, &win_size.w, &win_size.h); + + Uint32 mouse_buttons = SDL_GetMouseState(&input.mouse_state_raw.x, &input.mouse_state_raw.y); input.mouse_state.x = input.mouse_state_raw.x/Default::game_scale; diff --git a/src/game/state_playing.cpp b/src/game/state_playing.cpp index 92de3ed..033f779 100644 --- a/src/game/state_playing.cpp +++ b/src/game/state_playing.cpp @@ -146,6 +146,36 @@ void StatePlaying::handle_Events(SDL_Event& event, Game* game) { } } +void update_CameraOffset( + const SDL_FPoint& player_world, + const SDL_Rect& win_size +) { + const float inv_scale = 1.0f / Default::game_scale; + + const float logical_w = win_size.w * inv_scale; + const float logical_h = win_size.h * inv_scale; + + const float margin_x = logical_w * 0.25f; + const float margin_y = logical_h * 0.25f; + + const float player_screen_x = player_world.x + Map::offset.x; + const float player_screen_y = player_world.y + Map::offset.y; + + if (player_screen_x < margin_x) { + Map::offset.x = margin_x - player_world.x; + } + else if (player_screen_x > logical_w - margin_x) { + Map::offset.x = (logical_w - margin_x) - player_world.x; + } + + if (player_screen_y < margin_y) { + Map::offset.y = margin_y - player_world.y; + } + else if (player_screen_y > logical_h - margin_y) { + Map::offset.y = (logical_h - margin_y) - player_world.y; + } +} + void StatePlaying::Update(Game* game) { // SET Map offset @@ -185,6 +215,11 @@ void StatePlaying::Update(Game* game) { // clear dead Enemy::remove_Dead(); // END ENEMY HANDLING + + + // CAMERA + update_CameraOffset({player->x+player->tile_size/2, player->y+player->tile_size/2}, game->win_size); + std::cout << "WO: " << game->win_size.w << " " << game->win_size.h << std::endl; } void StatePlaying::Render(Game* game) { diff --git a/src/inventory/item.cpp b/src/inventory/item.cpp index 8ba3cbd..3b89441 100644 --- a/src/inventory/item.cpp +++ b/src/inventory/item.cpp @@ -61,7 +61,7 @@ namespace Item { 1, // base_damage 0, // base_armor 20, // base_health - 1.2, // base_speed + 0.8, // base_speed 1, // dmg_per_level 0, // armor_per_level 5, // health_per_level