From 8f6b5f7cac044922bb5a94ed9b6fb1d8a1d7cab1 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 6 Apr 2026 17:44:13 +0200 Subject: [PATCH] fix: bug en el editor al crear habitacions noves --- config/assets.yaml | 1 + data/player/player.gif | Bin 583 -> 672 bytes data/player/player.yaml | 2 +- data/room/02.yaml | 2 +- data/room/03.yaml | 6 ++-- data/room/04.yaml | 43 ++++++++++++++++++++++++ source/core/resources/resource_list.cpp | 4 +-- source/game/editor/map_editor.cpp | 8 ++--- source/game/editor/mini_map.hpp | 10 +++--- source/game/entities/player.cpp | 14 ++++++-- 10 files changed, 72 insertions(+), 18 deletions(-) create mode 100644 data/room/04.yaml diff --git a/config/assets.yaml b/config/assets.yaml index 90622c5..6fe37a8 100644 --- a/config/assets.yaml +++ b/config/assets.yaml @@ -69,6 +69,7 @@ assets: - ${PREFIX}/data/room/01.yaml - ${PREFIX}/data/room/02.yaml - ${PREFIX}/data/room/03.yaml + - ${PREFIX}/data/room/04.yaml # TILESETS tilesets: diff --git a/data/player/player.gif b/data/player/player.gif index f9b5306a5a629d5479c574e5e2e6f81cbd55486c..5ec8ae3737b0ff6a6ac009eed52d3bff0849ce66 100644 GIT binary patch delta 437 zcmV;m0ZRVI1fT_w^?v}MU?3Kb1)aB*&TGjc&4AJdP_bPqIj;bRI+rfueNr$wg9ZQzEi+$!a~FV9)CSO9v-&K$;))e%FNNy z&{NLSZOh!;+uhzm;NeQ+*T?3)bKoE6=;`9!?bPM$^vd%d?RVTE{>k;0eef6JT)%%k zzUd=)Pnnz$J?=assOMQbh7spX^ykYO!Gy)uWDMbFO*cJq#@#W=4Om1EkwTdq_Hr3Y zmM7Wxs0nkHoPVl}Q(Opj(Sqo(HA7tlLz+~n5;;kK$qbsbsI8`SnhMPtm21~FRofK( zszj^PvRJ(eZ9%muTP0)H8g0Awtq`|!(QYkjSF2qiV*&6ztGC5p07C^6CERtf5(tZ zpr1*jL#IL>V;&w*t*ov|t3Iu-w6;jFwX#F4zrVA9;=^Nsrpg|Y= zd>qVoupmQ&qQ*cZ*brfph8HVloR~!8Mu$i|h7>7;Bt?TSMv`p!qGiW}E>9M0nNlS} znld?-bV#$N%2ZL9Cjs=dDFmkw3P_JqcxllnQ;R``0$o@XD1f9_m#VDlQ|Sw;JDW}g tIiw}lt3$M=MXHr;TdZ!^!eyKFtWvd5 std::string { // new_room.left_room = "0"; new_room.right_room = "0"; new_room.conveyor_belt_direction = 0; - new_room.tile_map.resize(32 * 16, -1); + new_room.tile_map.resize(Map::WIDTH * Map::HEIGHT, -1); // Conexión recíproca: la nueva room conecta de vuelta a la actual if (direction == "UP") { @@ -1368,11 +1368,11 @@ auto MapEditor::createNewRoom(const std::string& direction) -> std::string { // file << " conveyorBelt: none\n"; file << "\n"; file << "tilemap:\n"; - for (int row = 0; row < 16; ++row) { + for (int row = 0; row < Map::HEIGHT; ++row) { file << " - ["; - for (int col = 0; col < 32; ++col) { + for (int col = 0; col < Map::WIDTH; ++col) { file << "-1"; - if (col < 31) { file << ", "; } + if (col < Map::WIDTH - 1) { file << ", "; } } file << "]\n"; } diff --git a/source/game/editor/mini_map.hpp b/source/game/editor/mini_map.hpp index 68bcfc6..ba56639 100644 --- a/source/game/editor/mini_map.hpp +++ b/source/game/editor/mini_map.hpp @@ -10,6 +10,8 @@ #include // Para unordered_map #include // Para vector +#include "utils/defines.hpp" // Para Map::WIDTH, Map::HEIGHT + class Surface; /** @@ -18,7 +20,7 @@ class Surface; * Genera una vista en miniatura de todas las habitaciones del juego, * posicionadas según sus conexiones. * Cada tile del mapa se representa como 1 pixel del color predominante de ese tile. - * Resultado: cada room = 32x16 pixels. + * Resultado: cada room = Map::WIDTH x Map::HEIGHT pixels. */ class MiniMap { public: @@ -43,7 +45,7 @@ class MiniMap { // Una room renderizada struct RoomMini { - std::shared_ptr surface; // 32x16 pixels + std::shared_ptr surface; // ROOM_W x ROOM_H pixels GridPos pos; // Posición en el grid }; @@ -84,8 +86,8 @@ class MiniMap { float view_start_y_{0.0F}; // Constantes - static constexpr int ROOM_W = 32; // Ancho de una room en pixels del minimapa - static constexpr int ROOM_H = 16; // Alto de una room en pixels del minimapa + static constexpr int ROOM_W = Map::WIDTH; // Ancho de una room en pixels del minimapa (1 pixel por tile) + static constexpr int ROOM_H = Map::HEIGHT; // Alto de una room en pixels del minimapa (1 pixel por tile) static constexpr int BORDER = 1; // Borde alrededor de cada room static constexpr int CELL_W = ROOM_W + (BORDER * 2); // Room + borde static constexpr int CELL_H = ROOM_H + (BORDER * 2); diff --git a/source/game/entities/player.cpp b/source/game/entities/player.cpp index e6307df..4ecd0b7 100644 --- a/source/game/entities/player.cpp +++ b/source/game/entities/player.cpp @@ -691,16 +691,24 @@ void Player::updateVelocity(float delta_time) { if (target > 0.0F) { sprite_->setFlip(Flip::RIGHT); } else if (target < 0.0F) { sprite_->setFlip(Flip::LEFT); } - // En el aire: inercia (interpolación gradual). En suelo/rampa: respuesta inmediata. + // Inercia: + // - En el aire: inercia completa (arranque y frenada graduales) + // - En suelo/rampa: arranque instantáneo, frenada gradual + const float STEP = HORIZONTAL_ACCEL * delta_time; if (state_ == State::ON_AIR) { - const float STEP = HORIZONTAL_ACCEL * delta_time; if (vx_ < target) { vx_ = std::min(vx_ + STEP, target); } else if (vx_ > target) { vx_ = std::max(vx_ - STEP, target); } } else { - vx_ = target; + if (target != 0.0F) { + vx_ = target; // Arranque instantáneo + } else if (vx_ > 0.0F) { + vx_ = std::max(vx_ - STEP, 0.0F); // Frenada gradual + } else if (vx_ < 0.0F) { + vx_ = std::min(vx_ + STEP, 0.0F); // Frenada gradual + } } }