fix: bug en el editor al crear habitacions noves

This commit is contained in:
2026-04-06 17:44:13 +02:00
parent a52e6c709e
commit 8f6b5f7cac
10 changed files with 72 additions and 18 deletions

View File

@@ -69,6 +69,7 @@ assets:
- ${PREFIX}/data/room/01.yaml - ${PREFIX}/data/room/01.yaml
- ${PREFIX}/data/room/02.yaml - ${PREFIX}/data/room/02.yaml
- ${PREFIX}/data/room/03.yaml - ${PREFIX}/data/room/03.yaml
- ${PREFIX}/data/room/04.yaml
# TILESETS # TILESETS
tilesets: tilesets:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 583 B

After

Width:  |  Height:  |  Size: 672 B

View File

@@ -12,7 +12,7 @@ animations:
- name: default - name: default
speed: 0.07 speed: 0.07
loop: 0 loop: 0
frames: [0, 1, 2, 3] frames: [1, 2, 3, 0]
- name: jump - name: jump
speed: 0 speed: 0

View File

@@ -6,7 +6,7 @@ room:
# Conexiones de la habitación (null = sin conexión) # Conexiones de la habitación (null = sin conexión)
connections: connections:
up: null up: null
down: 04.yaml down: null
left: 01.yaml left: 01.yaml
right: 03.yaml right: 03.yaml

View File

@@ -5,7 +5,7 @@ room:
# Conexiones de la habitación (null = sin conexión) # Conexiones de la habitación (null = sin conexión)
connections: connections:
up: null up: 04.yaml
down: null down: null
left: 02.yaml left: 02.yaml
right: null right: null
@@ -24,7 +24,7 @@ tilemap:
- [48, 50, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 26] - [48, 50, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 26]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 26] - [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 26]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 26] - [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 26]
- [0, 2, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, -1, -1, 504, 6, 7, 7, 7, 7, 7, 24, 26] - [0, 2, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, -1, -1, -1, -1, 504, 6, 7, 7, 7, 7, 7, 24, 26]
- [24, 26, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, -1, -1, -1, -1, -1, -1, 24, 26] - [24, 26, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, -1, -1, -1, -1, -1, -1, 24, 26]
- [24, 26, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, -1, -1, -1, -1, -1, -1, -1, 24, 26] - [24, 26, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, -1, -1, -1, -1, -1, -1, -1, 24, 26]
- [24, 26, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 26] - [24, 26, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 26]
@@ -49,7 +49,7 @@ enemies:
velocity: {x: 24, y: 0} velocity: {x: 24, y: 0}
boundaries: boundaries:
position1: {x: 3, y: 2} position1: {x: 3, y: 2}
position2: {x: 27, y: 2} position2: {x: 11, y: 2}
color: 12 color: 12
# Objetos en esta habitación # Objetos en esta habitación

43
data/room/04.yaml Normal file
View File

@@ -0,0 +1,43 @@
room:
bgColor: 34
border: 0
tileSetFile: standard.gif
# Conexiones de la habitación (null = sin conexión)
connections:
up: null
down: 03.yaml
left: null
right: null
# Colores de los objetos
itemColor1: 0
itemColor2: 0
# Dirección de la cinta transportadora: left, none, right
conveyorBelt: none
# Tilemap: 21 filas x 32 columnas @ 8px/tile
# Índices de tiles (-1 = vacío)
tilemap:
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]

View File

@@ -66,7 +66,7 @@ namespace Resource {
// Construir la ruta con variable ${PREFIX} (invertir la sustitución) // Construir la ruta con variable ${PREFIX} (invertir la sustitución)
std::string var_path = path; std::string var_path = path;
if (!prefix_.empty() && !executable_path_.empty()) { if (!executable_path_.empty()) {
std::string full_prefix = executable_path_ + prefix_; std::string full_prefix = executable_path_ + prefix_;
auto pos = var_path.find(full_prefix); auto pos = var_path.find(full_prefix);
if (pos != std::string::npos) { if (pos != std::string::npos) {
@@ -111,7 +111,7 @@ namespace Resource {
// Construir la ruta con variable ${PREFIX} // Construir la ruta con variable ${PREFIX}
std::string var_path = file_path; std::string var_path = file_path;
if (!prefix_.empty() && !executable_path_.empty()) { if (!executable_path_.empty()) {
std::string full_prefix = executable_path_ + prefix_; std::string full_prefix = executable_path_ + prefix_;
auto pos = var_path.find(full_prefix); auto pos = var_path.find(full_prefix);
if (pos != std::string::npos) { if (pos != std::string::npos) {

View File

@@ -1328,7 +1328,7 @@ auto MapEditor::createNewRoom(const std::string& direction) -> std::string { //
new_room.left_room = "0"; new_room.left_room = "0";
new_room.right_room = "0"; new_room.right_room = "0";
new_room.conveyor_belt_direction = 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 // Conexión recíproca: la nueva room conecta de vuelta a la actual
if (direction == "UP") { if (direction == "UP") {
@@ -1368,11 +1368,11 @@ auto MapEditor::createNewRoom(const std::string& direction) -> std::string { //
file << " conveyorBelt: none\n"; file << " conveyorBelt: none\n";
file << "\n"; file << "\n";
file << "tilemap:\n"; file << "tilemap:\n";
for (int row = 0; row < 16; ++row) { for (int row = 0; row < Map::HEIGHT; ++row) {
file << " - ["; file << " - [";
for (int col = 0; col < 32; ++col) { for (int col = 0; col < Map::WIDTH; ++col) {
file << "-1"; file << "-1";
if (col < 31) { file << ", "; } if (col < Map::WIDTH - 1) { file << ", "; }
} }
file << "]\n"; file << "]\n";
} }

View File

@@ -10,6 +10,8 @@
#include <unordered_map> // Para unordered_map #include <unordered_map> // Para unordered_map
#include <vector> // Para vector #include <vector> // Para vector
#include "utils/defines.hpp" // Para Map::WIDTH, Map::HEIGHT
class Surface; class Surface;
/** /**
@@ -18,7 +20,7 @@ class Surface;
* Genera una vista en miniatura de todas las habitaciones del juego, * Genera una vista en miniatura de todas las habitaciones del juego,
* posicionadas según sus conexiones. * posicionadas según sus conexiones.
* Cada tile del mapa se representa como 1 pixel del color predominante de ese tile. * 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 { class MiniMap {
public: public:
@@ -43,7 +45,7 @@ class MiniMap {
// Una room renderizada // Una room renderizada
struct RoomMini { struct RoomMini {
std::shared_ptr<Surface> surface; // 32x16 pixels std::shared_ptr<Surface> surface; // ROOM_W x ROOM_H pixels
GridPos pos; // Posición en el grid GridPos pos; // Posición en el grid
}; };
@@ -84,8 +86,8 @@ class MiniMap {
float view_start_y_{0.0F}; float view_start_y_{0.0F};
// Constantes // Constantes
static constexpr int ROOM_W = 32; // Ancho 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 = 16; // Alto de una room en pixels del minimapa 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 BORDER = 1; // Borde alrededor de cada room
static constexpr int CELL_W = ROOM_W + (BORDER * 2); // Room + borde static constexpr int CELL_W = ROOM_W + (BORDER * 2); // Room + borde
static constexpr int CELL_H = ROOM_H + (BORDER * 2); static constexpr int CELL_H = ROOM_H + (BORDER * 2);

View File

@@ -691,16 +691,24 @@ void Player::updateVelocity(float delta_time) {
if (target > 0.0F) { sprite_->setFlip(Flip::RIGHT); } if (target > 0.0F) { sprite_->setFlip(Flip::RIGHT); }
else if (target < 0.0F) { sprite_->setFlip(Flip::LEFT); } else if (target < 0.0F) { sprite_->setFlip(Flip::LEFT); }
// En el aire: inercia (interpolación gradual). En suelo/rampa: respuesta inmediata. // Inercia:
if (state_ == State::ON_AIR) { // - En el aire: inercia completa (arranque y frenada graduales)
// - En suelo/rampa: arranque instantáneo, frenada gradual
const float STEP = HORIZONTAL_ACCEL * delta_time; const float STEP = HORIZONTAL_ACCEL * delta_time;
if (state_ == State::ON_AIR) {
if (vx_ < target) { if (vx_ < target) {
vx_ = std::min(vx_ + STEP, target); vx_ = std::min(vx_ + STEP, target);
} else if (vx_ > target) { } else if (vx_ > target) {
vx_ = std::max(vx_ - STEP, target); vx_ = std::max(vx_ - STEP, target);
} }
} else { } 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
}
} }
} }