collision tile

This commit is contained in:
2026-04-06 21:51:40 +02:00
parent 98715ef3a7
commit 5393a861d1
11 changed files with 781 additions and 790 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -2,26 +2,24 @@
#include <SDL3/SDL.h>
#include <array> // Para array
#include <limits> // Para numeric_limits
#include <memory> // Para shared_ptr, __shared_ptr_access
#include <memory> // Para shared_ptr
#include <string> // Para string
#include <utility>
#include "core/rendering/sprite/animated_sprite.hpp" // Para SAnimatedSprite
#include "core/rendering/sprite/animated_sprite.hpp" // Para AnimatedSprite
#include "game/gameplay/room.hpp"
#include "game/options.hpp" // Para Cheat, Options, options
#include "utils/defines.hpp" // Para BORDER_TOP, BLOCK
#include "utils/utils.hpp" // Para Color
struct JA_Sound_t; // lines 13-13
#include "game/gameplay/tile_collider.hpp" // Para TileCollider::Tile
#include "game/options.hpp" // Para Cheat, Options
#include "utils/defines.hpp" // Para PlayArea, Tile, Flip
struct JA_Sound_t;
class Player {
public:
// --- Enums y Structs ---
enum class State {
ON_GROUND, // En suelo plano o conveyor belt
ON_SLOPE, // En rampa/pendiente
ON_AIR, // En el aire (saltando, cayendo o caminando al vacío)
ON_GROUND,
ON_SLOPE,
ON_AIR,
};
enum class Direction {
@@ -32,13 +30,13 @@ class Player {
NONE
};
// --- Constantes de física (públicas para permitir cálculos en structs) ---
static constexpr float HORIZONTAL_VELOCITY = 60.0F; // Velocidad horizontal objetivo en pixels/segundo
static constexpr float HORIZONTAL_ACCEL = 500.0F; // Aceleración/deceleración horizontal en pixels/segundo² (inercia ligera)
static constexpr float MAX_VY = 160.0F; // Velocidad vertical máxima en pixels/segundo
static constexpr float JUMP_VELOCITY = -178.5F; // Velocidad inicial del salto en pixels/segundo
static constexpr float GRAVITY_FORCE = 360.0F; // Fuerza de gravedad en pixels/segundo²
static constexpr float LOW_JUMP_GRAVITY_MULT = 3.0F; // Multiplicador de gravedad al soltar el botón de salto (salto variable)
// --- Constantes de física ---
static constexpr float HORIZONTAL_VELOCITY = 60.0F;
static constexpr float HORIZONTAL_ACCEL = 500.0F;
static constexpr float MAX_VY = 160.0F;
static constexpr float JUMP_VELOCITY = -178.5F;
static constexpr float GRAVITY_FORCE = 360.0F;
static constexpr float LOW_JUMP_GRAVITY_MULT = 3.0F;
struct SpawnData {
float x = 0;
@@ -60,130 +58,98 @@ class Player {
explicit Player(const Data& player);
~Player() = default;
// --- Funciones ---
void render(); // Pinta el enemigo en pantalla
void update(float delta_time); // Actualiza las variables del objeto
[[nodiscard]] auto isOnBorder() const -> bool { return border_ != Room::Border::NONE; } // Indica si el jugador esta en uno de los cuatro bordes de la pantalla
[[nodiscard]] auto getBorder() const -> Room::Border { return border_; } // Indica en cual de los cuatro bordes se encuentra
void switchBorders(); // Cambia al jugador de un borde al opuesto. Util para el cambio de pantalla
auto getRect() -> SDL_FRect { return {.x = x_, .y = y_, .w = WIDTH, .h = HEIGHT}; } // Obtiene el rectangulo que delimita al jugador
auto getCollider() -> SDL_FRect& { return collider_box_; } // Obtiene el rectangulo de colision del jugador
auto getSpawnParams() -> SpawnData { return {.x = x_, .y = y_, .vx = vx_, .vy = vy_, .last_grounded_position = last_grounded_position_, .state = state_, .flip = sprite_->getFlip()}; } // Obtiene el estado de reaparición del jugador
void setColor(Uint8 color = 0); // Establece el color del jugador (0 = automático según cheats)
void setSkin(const std::string& skin_name); // Cambia la skin del jugador en caliente ("default" o nombre de enemigo)
static auto skinToAnimationPath(const std::string& skin_name) -> std::string; // Resuelve nombre de skin a fichero de animación
void setRoom(std::shared_ptr<Room> room) { room_ = std::move(room); } // Establece la habitación en la que se encuentra el jugador
//[[nodiscard]] auto isAlive() const -> bool { return is_alive_ || (Options::cheats.invincible == Options::Cheat::State::ENABLED); } // Comprueba si el jugador esta vivo
[[nodiscard]] auto isAlive() const -> bool { return is_alive_; } // Comprueba si el jugador esta vivo
void setPaused(bool value) { is_paused_ = value; } // Pone el jugador en modo pausa
void setIgnoreInput(bool value) { ignore_input_ = value; } // Ignora inputs del jugador (física sigue activa)
// --- Interfaz pública ---
void render();
void update(float delta_time);
[[nodiscard]] auto isOnBorder() const -> bool { return border_ != Room::Border::NONE; }
[[nodiscard]] auto getBorder() const -> Room::Border { return border_; }
void switchBorders();
auto getRect() -> SDL_FRect { return {.x = x_, .y = y_, .w = WIDTH, .h = HEIGHT}; }
auto getCollider() -> SDL_FRect& { return collider_box_; }
auto getSpawnParams() -> SpawnData { return {.x = x_, .y = y_, .vx = vx_, .vy = vy_, .last_grounded_position = last_grounded_position_, .state = state_, .flip = sprite_->getFlip()}; }
void setColor(Uint8 color = 0);
void setSkin(const std::string& skin_name);
static auto skinToAnimationPath(const std::string& skin_name) -> std::string;
void setRoom(std::shared_ptr<Room> room) { room_ = std::move(room); }
[[nodiscard]] auto isAlive() const -> bool { return is_alive_; }
void setPaused(bool value) { is_paused_ = value; }
void setIgnoreInput(bool value) { ignore_input_ = value; }
[[nodiscard]] auto getIgnoreInput() const -> bool { return ignore_input_; }
#ifdef _DEBUG
// --- Funciones de debug ---
void setDebugPosition(float x, float y); // Establece la posición del jugador directamente (debug)
void finalizeDebugTeleport(); // Fija estado ON_GROUND, velocidades a 0, actualiza last_grounded_position_ (debug)
void setDebugPosition(float x, float y);
void finalizeDebugTeleport();
#endif
private:
// --- Constantes ---
static constexpr int WIDTH = 12; // Ancho del jugador
static constexpr int HEIGHT = 24; // Alto del jugador
static constexpr int MAX_FALLING_HEIGHT = Tile::SIZE * 4; // Altura maxima permitida de caída en pixels
static constexpr int WIDTH = 12;
static constexpr int HEIGHT = 24;
// --- Objetos y punteros ---
std::shared_ptr<Room> room_; // Objeto encargado de gestionar cada habitación del juego
std::unique_ptr<AnimatedSprite> sprite_; // Sprite del jugador
std::shared_ptr<Room> room_;
std::unique_ptr<AnimatedSprite> sprite_;
// --- Variables de posición y física ---
float x_ = 0.0F; // Posición del jugador en el eje X
float y_ = 0.0F; // Posición del jugador en el eje Y
float y_prev_ = 0.0F; // Posición Y del frame anterior (para detectar hitos de distancia en sonidos)
float vx_ = 0.0F; // Velocidad/desplazamiento del jugador en el eje X
float vy_ = 0.0F; // Velocidad/desplazamiento del jugador en el eje Y
// --- Posición y física ---
float x_ = 0.0F;
float y_ = 0.0F;
float vx_ = 0.0F;
float vy_ = 0.0F;
Direction wanna_go_ = Direction::NONE;
bool wanna_jump_ = false;
bool wanna_down_ = false;
bool jump_held_ = false; // true mientras la tecla de salto esté pulsada (para detectar flanco)
bool jump_held_ = false;
// --- Variables de estado ---
State state_ = State::ON_GROUND; // Estado en el que se encuentra el jugador. Util apara saber si está saltando o cayendo
State previous_state_ = State::ON_GROUND; // Estado previo en el que se encontraba el jugador
// --- Estado ---
State state_ = State::ON_GROUND;
State previous_state_ = State::ON_GROUND;
// --- Variables de colisión ---
SDL_FRect collider_box_{}; // Caja de colisión con los enemigos u objetos
std::array<SDL_FPoint, 12> collider_points_{}; // Puntos de colisión con el mapa (3 columnas × 4 filas, gap ≤ 8px)
SDL_FPoint under_left_foot_ = {.x = 0.0F, .y = 0.0F}; // El punto bajo la esquina inferior izquierda del jugador
SDL_FPoint under_right_foot_ = {.x = 0.0F, .y = 0.0F}; // El punto bajo la esquina inferior derecha del jugador
const LineDiagonal* current_slope_{nullptr}; // Rampa actual sobe la que está el jugador
// --- Colisión ---
SDL_FRect collider_box_{};
int slope_tile_x_{0};
int slope_tile_y_{0};
TileCollider::Tile slope_type_{TileCollider::Tile::EMPTY};
// --- Variables de juego ---
bool is_alive_ = true; // Indica si el jugador esta vivo o no
bool is_paused_ = false; // Indica si el jugador esta en modo pausa
bool ignore_input_ = false; // Ignora inputs pero mantiene la física activa
bool auto_movement_ = false; // Indica si esta siendo arrastrado por una superficie automatica
Room::Border border_ = Room::Border::TOP; // Indica en cual de los cuatro bordes se encuentra
int last_grounded_position_ = 0; // Ultima posición en Y en la que se estaba en contacto con el suelo (hace doble función: tracking de caída + altura inicial del salto)
bool is_alive_ = true;
bool is_paused_ = false;
bool ignore_input_ = false;
Room::Border border_ = Room::Border::TOP;
int last_grounded_position_ = 0;
// --- Variables de renderizado y sonido ---
Uint8 color_ = 0; // Color del jugador
JA_Sound_t* jump_sound_ = nullptr; // Sonido al iniciar el salto
JA_Sound_t* land_sound_ = nullptr; // Sonido al aterrizar en el suelo
// --- Renderizado y sonido ---
Uint8 color_ = 0;
JA_Sound_t* jump_sound_ = nullptr;
JA_Sound_t* land_sound_ = nullptr;
void handleConveyorBelts();
void handleShouldFall();
void updateState(float delta_time);
// --- Pipeline de update ---
void handleInput();
void updateVelocity(float delta_time);
void applyGravity(float delta_time);
void handleJumpAndDrop();
void moveHorizontal(float delta_time);
void moveVertical(float delta_time);
void followSlope();
void exitSlope();
void detectSlopeEntry();
void checkFalling();
// --- Métodos de actualización por estado ---
void updateOnGround(float delta_time); // Actualización lógica estado ON_GROUND
void updateOnSlope(float delta_time); // Actualización lógica estado ON_SLOPE
void updateOnAir(float delta_time); // Actualización lógica estado ON_AIR
// --- Gestión de estado ---
void transitionToState(State state);
void startJump();
// --- Métodos de movimiento por estado ---
void moveOnGround(float delta_time); // Movimiento físico estado ON_GROUND
void moveOnSlope(float delta_time); // Movimiento físico estado ON_SLOPE
void moveOnAir(float delta_time); // Movimiento físico estado ON_AIR
// --- Geometría y renderizado ---
void syncSpriteAndCollider();
void placeSprite();
void animate(float delta_time);
auto handleBorders() -> Room::Border;
// --- Funciones de inicialización ---
void initSprite(const std::string& animations_path); // Inicializa el sprite del jugador
void initSounds(); // Inicializa los sonidos de salto y caida
void applySpawnValues(const SpawnData& spawn); // Aplica los valores de spawn al jugador
// --- Inicialización ---
void initSprite(const std::string& animations_path);
void initSounds();
void applySpawnValues(const SpawnData& spawn);
// --- Funciones de procesamiento de entrada ---
void handleInput(); // Comprueba las entradas y modifica variables
// --- Funciones de gestión de estado ---
void transitionToState(State state); // Cambia el estado del jugador
void startJump(); // Inicia el salto: velocidad inicial + sonido + transición a ON_AIR
// --- Funciones de física ---
void applyGravity(float delta_time); // Aplica gravedad al jugador
// --- Funciones de movimiento y colisión ---
void move(float delta_time); // Orquesta el movimiento del jugador
auto getProjection(Direction direction, float displacement) -> SDL_FRect; // Devuelve el rectangulo de proyeccion
void applyHorizontalMovement(float delta_time); // Aplica movimiento horizontal con colisión de muros
auto handleLandingFromAir(float displacement, const SDL_FRect& projection) -> bool; // Detecta aterrizaje en superficies y rampas
// --- Funciones de detección de superficies ---
auto isOnFloor() -> bool; // Comprueba si el jugador tiene suelo debajo de los pies
auto isOnTopSurface() -> bool; // Comprueba si el jugador está sobre una superficie
auto isOnConveyorBelt() -> bool; // Comprueba si el jugador esta sobre una cinta transportadora
auto isOnSlope() -> bool; // Comprueba si el jugador está sobre una rampa
auto isLeftSlope() -> bool; // Comprueba si current_slope_ es una rampa izquierda (ascendente a la izquierda)
void updateCurrentSlope(); // Actualiza current_slope_ con la rampa correcta y muestra debug info
// --- Funciones de actualización de geometría ---
void syncSpriteAndCollider(); // Actualiza collider_box y collision points
void updateColliderPoints(); // Actualiza los puntos de colisión
void updateFeet(); // Actualiza los puntos de los pies
void placeSprite(); // Coloca el sprite en la posición del jugador
// --- Funciones de finalización ---
void animate(float delta_time); // Establece la animación del jugador
auto handleBorders() -> Room::Border; // Comprueba si se halla en alguno de los cuatro bordes
auto handleKillingTiles() -> bool; // Comprueba que el jugador no toque ningun tile de los que matan
void updateVelocity(float delta_time); // Calcula la velocidad en x con inercia ligera
void markAsDead(); // Marca al jugador como muerto
};
// --- Utilidad ---
void markAsDead();
};

View File

@@ -10,7 +10,8 @@
// Constructor
CollisionMap::CollisionMap(std::vector<int> collision_tile_map, int conveyor_belt_direction)
: collision_tile_map_(std::move(collision_tile_map)),
conveyor_belt_direction_(conveyor_belt_direction) {
conveyor_belt_direction_(conveyor_belt_direction),
tile_collider_(collision_tile_map_) {
// Inicializa todas las superficies de colisión
initializeSurfaces();
}
@@ -41,13 +42,20 @@ auto CollisionMap::getTile(int index) const -> Tile {
}
switch (collision_tile_map_[index]) {
case 1: return Tile::WALL;
case 2: return Tile::PASSABLE;
case 3: return Tile::SLOPE_L;
case 4: return Tile::SLOPE_R;
case 5: return Tile::KILL;
case 6: return Tile::ANIMATED;
default: return Tile::EMPTY;
case 1:
return Tile::WALL;
case 2:
return Tile::PASSABLE;
case 3:
return Tile::SLOPE_L;
case 4:
return Tile::SLOPE_R;
case 5:
return Tile::KILL;
case 6:
return Tile::ANIMATED;
default:
return Tile::EMPTY;
}
}

View File

@@ -4,8 +4,9 @@
#include <vector> // Para vector
#include "utils/defines.hpp" // Para Tile::SIZE, Map::WIDTH, Map::HEIGHT
#include "utils/utils.hpp" // Para LineHorizontal, LineDiagonal, LineVertical
#include "game/gameplay/tile_collider.hpp" // Para TileCollider
#include "utils/defines.hpp" // Para Tile::SIZE, Map::WIDTH, Map::HEIGHT
#include "utils/utils.hpp" // Para LineHorizontal, LineDiagonal, LineVertical
/**
* @brief Mapa de colisiones de una habitación
@@ -71,6 +72,7 @@ class CollisionMap {
// --- Getters ---
[[nodiscard]] auto getConveyorBeltDirection() const -> int { return conveyor_belt_direction_; }
[[nodiscard]] auto getTileCollider() const -> const TileCollider& { return tile_collider_; }
// Getters para debug visualization
[[nodiscard]] auto getBottomFloors() const -> const std::vector<LineHorizontal>& { return bottom_floors_; }
@@ -90,6 +92,7 @@ class CollisionMap {
// --- Datos de la habitación ---
std::vector<int> collision_tile_map_; // Mapa de colisiones por tile
int conveyor_belt_direction_; // Dirección de conveyor belts
TileCollider tile_collider_; // Sistema de colisión por tiles
// --- Geometría de colisión ---
std::vector<LineHorizontal> bottom_floors_; // Superficies inferiores (suelos)

View File

@@ -161,6 +161,10 @@ void Room::setPaused(bool value) {
item_manager_->setPaused(value);
}
auto Room::getTileCollider() const -> const TileCollider& {
return collision_map_->getTileCollider();
}
// Devuelve la cadena del fichero de la habitación contigua segun el borde
auto Room::getRoom(Border border) -> std::string { // NOLINT(readability-convert-member-functions-to-static)
switch (border) {

View File

@@ -16,6 +16,7 @@ class Surface; // lines 13-13
class EnemyManager;
class ItemManager;
class CollisionMap;
class TileCollider;
class TilemapRenderer;
class Room {
@@ -102,6 +103,7 @@ class Room {
[[nodiscard]] auto getSlopeAtPoint(const SDL_FPoint& p) const -> const LineDiagonal*; // Obtiene puntero a slope en un punto
void setPaused(bool value); // Pone el mapa en modo pausa
[[nodiscard]] auto getConveyorBeltDirection() const -> int { return conveyor_belt_direction_; } // Obten la direccion de las superficies automaticas
[[nodiscard]] auto getTileCollider() const -> const TileCollider&;
// Método de carga de archivos YAML (delegado a RoomLoader)
static auto loadYAML(const std::string& file_path, bool verbose = false) -> Data; // Carga habitación desde archivo YAML unificado

View File

@@ -0,0 +1,182 @@
#include "game/gameplay/tile_collider.hpp"
#include <algorithm> // Para std::min, std::max
#include <cmath> // Para std::ceil
#include "utils/defines.hpp"
TileCollider::TileCollider(const std::vector<int>& collision_tile_map)
: tile_map_(collision_tile_map) {}
// --- Queries básicas ---
auto TileCollider::getTileAt(int tile_x, int tile_y) const -> Tile {
if (tile_x < 0 || tile_x >= MW || tile_y < 0 || tile_y >= MH) {
return Tile::EMPTY;
}
int value = tile_map_[tile_y * MW + tile_x];
if (value >= 0 && value <= 4) {
return static_cast<Tile>(value);
}
return Tile::EMPTY;
}
auto TileCollider::isSolid(int tile_x, int tile_y) const -> bool {
return getTileAt(tile_x, tile_y) == Tile::WALL;
}
auto TileCollider::getSlopeY(int tile_x, int tile_y, float px) const -> float {
float tile_bottom = static_cast<float>((tile_y + 1) * TS - 1);
float x_in_tile = px - static_cast<float>(tile_x * TS);
x_in_tile = std::clamp(x_in_tile, 0.0F, static_cast<float>(TS - 1));
auto tile = getTileAt(tile_x, tile_y);
if (tile == Tile::SLOPE_L) {
// \ descendente de izquierda a derecha
return tile_bottom - (static_cast<float>(TS - 1) - x_in_tile);
}
if (tile == Tile::SLOPE_R) {
// / descendente de derecha a izquierda
return tile_bottom - x_in_tile;
}
return tile_bottom;
}
// --- Colisión con paredes ---
auto TileCollider::checkWallLeft(float x, float y, float w, float h) const -> float {
(void)w;
int col = toTile(static_cast<int>(x) - 1);
int top_row = toTile(static_cast<int>(y));
int bot_row = toTile(static_cast<int>(y + h - 2));
for (int row = top_row; row <= bot_row; ++row) {
if (isSolid(col, row)) {
return static_cast<float>((col + 1) * TS);
}
}
return Collision::NONE;
}
auto TileCollider::checkWallRight(float x, float y, float w, float h) const -> float {
int col = toTile(static_cast<int>(x + w));
int top_row = toTile(static_cast<int>(y));
int bot_row = toTile(static_cast<int>(y + h - 2));
for (int row = top_row; row <= bot_row; ++row) {
if (isSolid(col, row)) {
return static_cast<float>(col * TS);
}
}
return Collision::NONE;
}
// --- Colisión con techo ---
auto TileCollider::checkCeiling(float x, float y, float w) const -> float {
int top_row = toTile(static_cast<int>(y));
int left_col = toTile(static_cast<int>(x));
int right_col = toTile(static_cast<int>(x + w - 1));
for (int col = left_col; col <= right_col; ++col) {
if (isSolid(col, top_row)) {
return static_cast<float>((top_row + 1) * TS);
}
}
return Collision::NONE;
}
// --- Colisión con suelo (landing) ---
auto TileCollider::checkFloor(float x, float foot_y_current, float w, float foot_y_new) const -> FloorHit {
int start_row = toTile(static_cast<int>(foot_y_current));
int end_row = toTile(static_cast<int>(foot_y_new));
int left_col = toTile(static_cast<int>(x));
int right_col = toTile(static_cast<int>(x + w - 1));
FloorHit best;
for (int row = start_row; row <= end_row; ++row) {
for (int col = left_col; col <= right_col; ++col) {
auto tile = getTileAt(col, row);
float floor_y = Collision::NONE;
if (tile == Tile::WALL) {
floor_y = static_cast<float>(row * TS);
} else if (tile == Tile::PASSABLE) {
float tile_top = static_cast<float>(row * TS);
// Solo cuenta como suelo si los pies estaban por encima antes del movimiento
if (foot_y_current <= tile_top) {
floor_y = tile_top;
}
} else if (tile == Tile::SLOPE_L || tile == Tile::SLOPE_R) {
float check_x = (tile == Tile::SLOPE_L) ? x : x + w - 1;
float slope_y = getSlopeY(col, row, check_x);
if (foot_y_new >= slope_y && foot_y_current <= slope_y + TS) {
floor_y = slope_y;
}
}
if (floor_y != Collision::NONE && (best.y == Collision::NONE || floor_y < best.y)) {
best = {floor_y, tile, col, row};
}
}
}
return best;
}
// --- Detección de suelo debajo ---
auto TileCollider::hasGroundBelow(float x, float foot_y, float w) const -> bool {
int row = toTile(static_cast<int>(foot_y));
int left_col = toTile(static_cast<int>(x));
int right_col = toTile(static_cast<int>(x + w - 1));
for (int col = left_col; col <= right_col; ++col) {
auto tile = getTileAt(col, row);
if (tile == Tile::WALL || tile == Tile::PASSABLE) {
return true;
}
if (tile == Tile::SLOPE_L || tile == Tile::SLOPE_R) {
float check_x = (tile == Tile::SLOPE_L) ? x : x + w - 1;
float slope_y = getSlopeY(col, row, check_x);
if (slope_y <= foot_y + 1) {
return true;
}
}
}
return false;
}
// --- Detección de slope debajo (transición ground→slope) ---
auto TileCollider::checkSlopeBelow(float x, float foot_y, float w) const -> SlopeInfo {
int foot_row = toTile(static_cast<int>(foot_y));
int left_col = toTile(static_cast<int>(x));
int right_col = toTile(static_cast<int>(x + w - 1));
// Comprobar la fila de los pies Y la fila de arriba
// (la slope entry puede estar un tile arriba del nivel de la plataforma)
for (int row = foot_row - 1; row <= foot_row; ++row) {
for (int col = left_col; col <= right_col; ++col) {
auto tile = getTileAt(col, row);
if (tile == Tile::SLOPE_L) {
float foot_x = (col == left_col) ? x : x + w - 1;
float slope_y = getSlopeY(col, row, foot_x);
if (slope_y <= foot_y && slope_y >= foot_y - TS) {
return {true, Tile::SLOPE_L, col, row, slope_y};
}
}
if (tile == Tile::SLOPE_R) {
float foot_x = (col == right_col) ? x + w - 1 : x;
float slope_y = getSlopeY(col, row, foot_x);
if (slope_y <= foot_y && slope_y >= foot_y - TS) {
return {true, Tile::SLOPE_R, col, row, slope_y};
}
}
}
}
return {};
}

View File

@@ -0,0 +1,55 @@
#pragma once
#include <vector>
#include "utils/defines.hpp"
class TileCollider {
public:
enum class Tile : int {
EMPTY = 0,
WALL = 1,
PASSABLE = 2,
SLOPE_L = 3,
SLOPE_R = 4
};
struct FloorHit {
float y{-1};
Tile type{Tile::EMPTY};
int tile_x{0};
int tile_y{0};
};
struct SlopeInfo {
bool on_slope{false};
Tile type{Tile::EMPTY};
int tile_x{0};
int tile_y{0};
float surface_y{0};
};
explicit TileCollider(const std::vector<int>& collision_tile_map);
// Queries básicas
[[nodiscard]] auto getTileAt(int tile_x, int tile_y) const -> Tile;
[[nodiscard]] auto isSolid(int tile_x, int tile_y) const -> bool;
[[nodiscard]] auto getSlopeY(int tile_x, int tile_y, float px) const -> float;
// Colisión para el Player
[[nodiscard]] auto checkWallLeft(float x, float y, float w, float h) const -> float;
[[nodiscard]] auto checkWallRight(float x, float y, float w, float h) const -> float;
[[nodiscard]] auto checkCeiling(float x, float y, float w) const -> float;
[[nodiscard]] auto checkFloor(float x, float foot_y_current, float w, float foot_y_new) const -> FloorHit;
[[nodiscard]] auto hasGroundBelow(float x, float foot_y, float w) const -> bool;
[[nodiscard]] auto checkSlopeBelow(float x, float foot_y, float w) const -> SlopeInfo;
private:
static constexpr int TS = ::Tile::SIZE;
static constexpr int MW = ::Map::WIDTH;
static constexpr int MH = ::Map::HEIGHT;
const std::vector<int>& tile_map_;
[[nodiscard]] static auto toTile(int px) -> int { return px / TS; }
};