collision tile
This commit is contained in:
55
source/game/gameplay/tile_collider.hpp
Normal file
55
source/game/gameplay/tile_collider.hpp
Normal 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; }
|
||||
};
|
||||
Reference in New Issue
Block a user