2 Commits

Author SHA1 Message Date
9ebf259525 fix: hack per a poder entrar en huecos de dos tiles d'altura al saltar
fix: calcul incorrecte del offset dels tiles que maten
2026-03-08 14:46:00 +01:00
f2e45940d5 afegit a defaults la habitació i posició inicials (normal i debug) 2026-03-08 10:09:30 +01:00
4 changed files with 38 additions and 11 deletions

View File

@@ -95,4 +95,29 @@ constexpr const char* TEXT = ""; // Texto del modo kiosko por defecto
constexpr bool INFINITE_LIVES = false; // Vidas infinitas en modo kiosko desactivadas por defecto
} // namespace Kiosk
// --- GAME (posición y habitación inicial) ---
namespace Game {
namespace Room {
#ifdef _DEBUG
constexpr const char* INITIAL = "03.yaml"; // Habitación de inicio en debug
#else
constexpr const char* INITIAL = "03.yaml"; // Habitación de inicio en release
#endif
} // namespace Room
namespace Player {
#ifdef _DEBUG
constexpr int SPAWN_X = 26 * Tile::SIZE; // Posición X inicial en debug
constexpr int SPAWN_Y = 13 * Tile::SIZE; // Posición Y inicial en debug
constexpr SDL_FlipMode SPAWN_FLIP = Flip::LEFT; // Orientación inicial en debug
#else
constexpr int SPAWN_X = 25 * Tile::SIZE; // Posición X inicial en release
constexpr int SPAWN_Y = 13 * Tile::SIZE; // Posición Y inicial en release
constexpr SDL_FlipMode SPAWN_FLIP = Flip::LEFT; // Orientación inicial en release
#endif
} // namespace Player
} // namespace Game
} // namespace Defaults

View File

@@ -47,6 +47,7 @@ void Player::update(float delta_time) {
handleInput();
updateState(delta_time);
move(delta_time);
handleKillingTiles(); // Los collider_points_ están actualizados por syncSpriteAndCollider() dentro de move()
animate(delta_time);
border_ = handleBorders();
}
@@ -349,7 +350,10 @@ void Player::moveJumping(float delta_time) {
handleLandingFromAir(DISPLACEMENT_Y, PROJECTION);
} else {
// Comprueba la colisión con las superficies y las cintas transportadoras (sin rampas)
const float POS = std::max(room_->checkTopSurfaces(PROJECTION), room_->checkAutoSurfaces(PROJECTION));
// Extendemos 1px hacia arriba para detectar suelos traversados ligeramente al
// entrar horizontalmente (consecuencia del margen h=HEIGHT-1 en la proyección horizontal)
const SDL_FRect ADJ = {PROJECTION.x, PROJECTION.y - 1.0F, PROJECTION.w, PROJECTION.h + 1.0F};
const float POS = std::max(room_->checkTopSurfaces(ADJ), room_->checkAutoSurfaces(ADJ));
if (POS != Collision::NONE) {
// Si hay colisión lo mueve hasta donde no colisiona y pasa a estar sobre la superficie
y_ = POS - HEIGHT;
@@ -868,14 +872,14 @@ auto Player::getProjection(Direction direction, float displacement) -> SDL_FRect
.x = x_ + displacement,
.y = y_,
.w = std::ceil(std::fabs(displacement)), // Para evitar que tenga una anchura de 0 pixels
.h = HEIGHT};
.h = HEIGHT - 1}; // -1 para dar ventana de 2px en aperturas de altura exacta
case Direction::RIGHT:
return {
.x = x_ + WIDTH,
.y = y_,
.w = std::ceil(displacement), // Para evitar que tenga una anchura de 0 pixels
.h = HEIGHT};
.h = HEIGHT - 1}; // -1 para dar ventana de 2px en aperturas de altura exacta
case Direction::UP:
return {

View File

@@ -29,7 +29,9 @@ void CollisionMap::initializeSurfaces() {
// Devuelve el tipo de tile que hay en ese pixel
auto CollisionMap::getTile(SDL_FPoint point) const -> Tile {
const int POS = ((point.y / TILE_SIZE) * MAP_WIDTH) + (point.x / TILE_SIZE);
const int row = static_cast<int>(point.y / TILE_SIZE);
const int col = static_cast<int>(point.x / TILE_SIZE);
const int POS = row * MAP_WIDTH + col;
return getTile(POS);
}

View File

@@ -26,6 +26,7 @@
#include "game/ui/notifier.hpp" // Para Notifier, NotificationText, CHEEVO_NO...
#include "utils/defines.hpp" // Para Tile::SIZE, PlayArea::HEIGHT, RoomBorder::BOTTOM
#include "utils/utils.hpp" // Para PaletteColor, stringToColor
#include "game/defaults.hpp" // Para Defaults::Game
#ifdef _DEBUG
#include "core/system/debug.hpp" // Para Debug
@@ -38,13 +39,8 @@ Game::Game(Mode mode)
room_tracker_(std::make_shared<RoomTracker>()),
stats_(std::make_shared<Stats>(Resource::List::get()->get("stats.csv"), Resource::List::get()->get("stats_buffer.csv"))),
mode_(mode),
#ifdef _DEBUG
current_room_("03.yaml"),
spawn_data_(Player::SpawnData(25 * Tile::SIZE, 13 * Tile::SIZE, 0, 0, 0, Player::State::ON_GROUND, Flip::LEFT))
#else
current_room_("03.yaml"),
spawn_data_(Player::SpawnData(25 * Tile::SIZE, 13 * Tile::SIZE, 0, 0, 0, Player::State::ON_GROUND, Flip::LEFT))
#endif
current_room_(Defaults::Game::Room::INITIAL),
spawn_data_(Player::SpawnData(Defaults::Game::Player::SPAWN_X, Defaults::Game::Player::SPAWN_Y, 0, 0, 0, Player::State::ON_GROUND, Defaults::Game::Player::SPAWN_FLIP))
{
// Crea objetos e inicializa variables
ItemTracker::init();