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

@@ -1328,7 +1328,7 @@ auto MapEditor::createNewRoom(const std::string& direction) -> 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";
}

View File

@@ -10,6 +10,8 @@
#include <unordered_map> // Para unordered_map
#include <vector> // 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> surface; // 32x16 pixels
std::shared_ptr<Surface> 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);

View File

@@ -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
}
}
}