Files
projecte_2026/source/game/gameplay/tile_collider.hpp

60 lines
1.9 KiB
C++

#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;
// Devuelve true si el jugador está parcialmente dentro de algún tile de slope
// (algún pie está por debajo de la superficie de un slope que solapa)
[[nodiscard]] auto isInsideAnySlope(float x, float foot_y, float w) const -> bool;
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; }
};