treballant en el extendedMap per a les colisións fora de pantalla
This commit is contained in:
@@ -1,20 +1,19 @@
|
||||
#include "game/gameplay/tile_collider.hpp"
|
||||
|
||||
#include <algorithm> // Para std::min, std::max
|
||||
#include <cmath> // Para std::ceil
|
||||
#include <algorithm> // Para std::min, std::max, std::clamp
|
||||
|
||||
#include "utils/defines.hpp"
|
||||
|
||||
TileCollider::TileCollider(const std::vector<int>& collision_tile_map)
|
||||
: tile_map_(collision_tile_map) {}
|
||||
TileCollider::TileCollider(const std::vector<int>& extended_tile_map, int width, int height, int border_px)
|
||||
: width_(width), height_(height), border_px_(border_px), tile_map_(extended_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) {
|
||||
if (tile_x < 0 || tile_x >= width_ || tile_y < 0 || tile_y >= height_) {
|
||||
return Tile::EMPTY;
|
||||
}
|
||||
int value = tile_map_[(tile_y * MW) + tile_x];
|
||||
int value = tile_map_[(tile_y * width_) + tile_x];
|
||||
if (value >= 0 && value <= 5) {
|
||||
return static_cast<Tile>(value);
|
||||
}
|
||||
@@ -30,8 +29,8 @@ auto TileCollider::isSolid(int tile_x, int tile_y) const -> bool {
|
||||
// SLOPE_L (\): alto a la izquierda, bajo a la derecha. surface = bottom - (7 - x_in_tile)
|
||||
// SLOPE_R (/): alto a la derecha, bajo a la izquierda. surface = bottom - x_in_tile
|
||||
auto TileCollider::getSlopeY(int tile_x, int tile_y, float px) const -> float {
|
||||
auto tile_bottom = static_cast<float>(((tile_y + 1) * TS) - 1);
|
||||
float x_in_tile = px - static_cast<float>(tile_x * TS);
|
||||
float tile_bottom = toPixel(tile_y + 1) - 1;
|
||||
float x_in_tile = px - toPixel(tile_x);
|
||||
x_in_tile = std::clamp(x_in_tile, 0.0F, static_cast<float>(TS - 1));
|
||||
|
||||
auto tile = getTileAt(tile_x, tile_y);
|
||||
@@ -54,7 +53,7 @@ auto TileCollider::checkWallLeft(float x, float y, float w, float h) const -> fl
|
||||
|
||||
for (int row = top_row; row <= bot_row; ++row) {
|
||||
if (isSolid(col, row)) {
|
||||
return static_cast<float>((col + 1) * TS);
|
||||
return toPixel(col + 1);
|
||||
}
|
||||
}
|
||||
return Collision::NONE;
|
||||
@@ -67,7 +66,7 @@ auto TileCollider::checkWallRight(float x, float y, float w, float h) const -> f
|
||||
|
||||
for (int row = top_row; row <= bot_row; ++row) {
|
||||
if (isSolid(col, row)) {
|
||||
return static_cast<float>(col * TS);
|
||||
return toPixel(col);
|
||||
}
|
||||
}
|
||||
return Collision::NONE;
|
||||
@@ -84,7 +83,7 @@ auto TileCollider::checkCeiling(float x, float y, float w) const -> float {
|
||||
auto tile = getTileAt(col, top_row);
|
||||
// Slopes actúan como techo (no se atraviesan desde abajo)
|
||||
if (tile == Tile::WALL || tile == Tile::SLOPE_L || tile == Tile::SLOPE_R) {
|
||||
return static_cast<float>((top_row + 1) * TS);
|
||||
return toPixel(top_row + 1);
|
||||
}
|
||||
}
|
||||
return Collision::NONE;
|
||||
@@ -93,7 +92,7 @@ auto TileCollider::checkCeiling(float x, float y, float w) const -> float {
|
||||
// --- Colisión con suelo (landing) ---
|
||||
|
||||
// Busca suelo entre foot_y_current y foot_y_new (rango de caída del frame).
|
||||
// WALL: siempre bloquea.
|
||||
// WALL: bloquea si los pies estaban por encima (como PASSABLE).
|
||||
// PASSABLE: solo si los pies estaban por encima del borde superior del tile.
|
||||
// SLOPE: siempre bloquea (las slopes son sólidas, como muros en diagonal).
|
||||
// NOLINTNEXTLINE(readability-function-cognitive-complexity)
|
||||
@@ -111,9 +110,12 @@ auto TileCollider::checkFloor(float x, float foot_y_current, float w, float foot
|
||||
float floor_y = Collision::NONE;
|
||||
|
||||
if (tile == Tile::WALL) {
|
||||
floor_y = static_cast<float>(row * TS);
|
||||
float tile_top = toPixel(row);
|
||||
if (foot_y_current <= tile_top) {
|
||||
floor_y = tile_top;
|
||||
}
|
||||
} else if (tile == Tile::PASSABLE) {
|
||||
auto tile_top = static_cast<float>(row * TS);
|
||||
float tile_top = toPixel(row);
|
||||
// Solo cuenta como suelo si los pies estaban por encima antes del movimiento
|
||||
if (foot_y_current <= tile_top) {
|
||||
floor_y = tile_top;
|
||||
|
||||
Reference in New Issue
Block a user