posss.. mes merdes que no van a cap lloc
This commit is contained in:
@@ -334,7 +334,7 @@ auto Director::run() -> int {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SceneManager::Scene::LOADING_SCREEN:
|
case SceneManager::Scene::LOADING_SCREEN:
|
||||||
runLogo();
|
runLoadingScreen();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SceneManager::Scene::TITLE:
|
case SceneManager::Scene::TITLE:
|
||||||
|
|||||||
@@ -63,19 +63,18 @@ void Player::move(float delta_time) {
|
|||||||
|
|
||||||
void Player::handleHorizontalMovement(float delta_time) {
|
void Player::handleHorizontalMovement(float delta_time) {
|
||||||
if (state_ == State::STANDING) {
|
if (state_ == State::STANDING) {
|
||||||
// 1. Primero, determinamos cuál debe ser la velocidad (vx_)
|
// Determinama cuál debe ser la velocidad a partir de automovement o de wannaGo
|
||||||
updateVelocity();
|
updateVelocity();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Ahora, aplicamos el movimiento y el flip basado en la velocidad resultante
|
// Aplica el movimiento y el flip basado en la velocidad resultante
|
||||||
if (vx_ < 0.0F) {
|
if (vx_ < 0.0F) {
|
||||||
moveHorizontal(delta_time, -1);
|
moveHorizontal(delta_time, Direction::LEFT);
|
||||||
sprite_->setFlip(SDL_FLIP_HORIZONTAL);
|
sprite_->setFlip(SDL_FLIP_HORIZONTAL);
|
||||||
} else if (vx_ > 0.0F) {
|
} else if (vx_ > 0.0F) {
|
||||||
moveHorizontal(delta_time, 1);
|
moveHorizontal(delta_time, Direction::RIGHT);
|
||||||
sprite_->setFlip(SDL_FLIP_NONE);
|
sprite_->setFlip(SDL_FLIP_NONE);
|
||||||
}
|
}
|
||||||
// Si vx_ es 0.0F, no se llama a moveHorizontal, lo cual es correcto.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::handleVerticalMovement(float delta_time) {
|
void Player::handleVerticalMovement(float delta_time) {
|
||||||
@@ -95,9 +94,6 @@ void Player::handleVerticalMovement(float delta_time) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::moveAndCollide(float delta_time) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void Player::handleConveyorBelts() {
|
void Player::handleConveyorBelts() {
|
||||||
if (!auto_movement_ and isOnConveyorBelt() and wannaGo == Direction::STAY) {
|
if (!auto_movement_ and isOnConveyorBelt() and wannaGo == Direction::STAY) {
|
||||||
auto_movement_ = true;
|
auto_movement_ = true;
|
||||||
@@ -200,9 +196,7 @@ void Player::handleState(float delta_time) {
|
|||||||
} else if (state_ == State::STANDING) {
|
} else if (state_ == State::STANDING) {
|
||||||
// Si no tiene suelo debajo y no está en rampa descendente -> FALLING
|
// Si no tiene suelo debajo y no está en rampa descendente -> FALLING
|
||||||
if (!isOnFloor() && !isOnConveyorBelt() && !isOnDownSlope()) {
|
if (!isOnFloor() && !isOnConveyorBelt() && !isOnDownSlope()) {
|
||||||
last_grounded_position_ = static_cast<int>(y_); // Guarda Y actual al SALIR de STANDING
|
|
||||||
transitionToState(State::FALLING); // setState() establece vx_=0, vy_=MAX_VY
|
transitionToState(State::FALLING); // setState() establece vx_=0, vy_=MAX_VY
|
||||||
playFallSound(delta_time);
|
|
||||||
}
|
}
|
||||||
} else if (state_ == State::JUMPING) {
|
} else if (state_ == State::JUMPING) {
|
||||||
playJumpSound(delta_time);
|
playJumpSound(delta_time);
|
||||||
@@ -251,8 +245,7 @@ void Player::applyGravity(float delta_time) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Maneja el movimiento sobre rampas
|
// Maneja el movimiento sobre rampas
|
||||||
// direction: -1 para izquierda, 1 para derecha
|
void Player::handleSlopeMovement(Direction direction) {
|
||||||
void Player::handleSlopeMovement(int direction) {
|
|
||||||
// No procesa rampas durante el salto (permite atravesarlas cuando salta con movimiento horizontal)
|
// No procesa rampas durante el salto (permite atravesarlas cuando salta con movimiento horizontal)
|
||||||
// Pero SÍ procesa en STANDING y FALLING (para pegarse a las rampas)
|
// Pero SÍ procesa en STANDING y FALLING (para pegarse a las rampas)
|
||||||
if (state_ == State::JUMPING) {
|
if (state_ == State::JUMPING) {
|
||||||
@@ -267,16 +260,16 @@ void Player::handleSlopeMovement(int direction) {
|
|||||||
|
|
||||||
// Regla: Si está STANDING y tropieza lateralmente con una Slope, se pega a la slope
|
// Regla: Si está STANDING y tropieza lateralmente con una Slope, se pega a la slope
|
||||||
// Comprueba si hay rampa en contacto lateral (solo los dos pixels inferiores)
|
// Comprueba si hay rampa en contacto lateral (solo los dos pixels inferiores)
|
||||||
const int SIDE_X = direction < 0 ? static_cast<int>(x_) : static_cast<int>(x_) + WIDTH - 1;
|
const int SIDE_X = direction == Direction::LEFT ? static_cast<int>(x_) : static_cast<int>(x_) + WIDTH - 1;
|
||||||
const LineVertical SIDE = {
|
const LineVertical SIDE = {
|
||||||
.x = SIDE_X,
|
.x = SIDE_X,
|
||||||
.y1 = static_cast<int>(y_) + HEIGHT - 2,
|
.y1 = static_cast<int>(y_) + HEIGHT - 2,
|
||||||
.y2 = static_cast<int>(y_) + HEIGHT - 1};
|
.y2 = static_cast<int>(y_) + HEIGHT - 1};
|
||||||
|
|
||||||
// Comprueba la rampa correspondiente según la dirección
|
// Comprueba la rampa correspondiente según la dirección
|
||||||
const int SLOPE_Y = direction < 0 ? room_->checkLeftSlopes(&SIDE) : room_->checkRightSlopes(&SIDE);
|
const int SLOPE_Y = direction == Direction::LEFT ? room_->checkLeftSlopes(SIDE) : room_->checkRightSlopes(SIDE);
|
||||||
|
|
||||||
if (SLOPE_Y > -1) {
|
if (SLOPE_Y != Collision::NONE) {
|
||||||
// Hay rampa: sube al jugador para pegarlo a la rampa
|
// Hay rampa: sube al jugador para pegarlo a la rampa
|
||||||
|
|
||||||
// --- INICIO DE LA CORRECCIÓN ---
|
// --- INICIO DE LA CORRECCIÓN ---
|
||||||
@@ -300,38 +293,44 @@ void Player::handleSlopeMovement(int direction) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Maneja el movimiento horizontal
|
// Maneja el movimiento horizontal
|
||||||
// direction: -1 para izquierda, 1 para derecha
|
void Player::moveHorizontal(float delta_time, Direction direction) {
|
||||||
void Player::moveHorizontal(float delta_time, int direction) {
|
|
||||||
const float DISPLACEMENT = vx_ * delta_time;
|
const float DISPLACEMENT = vx_ * delta_time;
|
||||||
|
|
||||||
// Crea el rectangulo de proyección en el eje X para ver si colisiona
|
// Crea el rectangulo de proyección en el eje X para ver si colisiona
|
||||||
SDL_FRect proj;
|
SDL_FRect proj;
|
||||||
if (direction < 0) {
|
switch (direction) {
|
||||||
|
case Direction::LEFT:
|
||||||
// Movimiento a la izquierda
|
// Movimiento a la izquierda
|
||||||
proj = {
|
proj = {
|
||||||
.x = x_ + DISPLACEMENT,
|
.x = x_ + DISPLACEMENT,
|
||||||
.y = y_,
|
.y = y_,
|
||||||
.w = std::ceil(std::fabs(DISPLACEMENT)),
|
.w = std::ceil(std::fabs(DISPLACEMENT)),
|
||||||
.h = HEIGHT};
|
.h = HEIGHT};
|
||||||
} else {
|
break;
|
||||||
|
|
||||||
|
case Direction::RIGHT:
|
||||||
// Movimiento a la derecha
|
// Movimiento a la derecha
|
||||||
proj = {
|
proj = {
|
||||||
.x = x_ + WIDTH,
|
.x = x_ + WIDTH,
|
||||||
.y = y_,
|
.y = y_,
|
||||||
.w = std::ceil(DISPLACEMENT),
|
.w = std::ceil(DISPLACEMENT),
|
||||||
.h = HEIGHT};
|
.h = HEIGHT};
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba la colisión con las superficies
|
// Comprueba la colisión con las superficies
|
||||||
const int POS = direction < 0 ? room_->checkRightSurfaces(&proj) : room_->checkLeftSurfaces(&proj);
|
const int POS = direction == Direction::LEFT ? room_->checkRightSurfaces(proj) : room_->checkLeftSurfaces(proj);
|
||||||
|
|
||||||
// Calcula la nueva posición
|
// Calcula la nueva posición
|
||||||
if (POS == -1) {
|
if (POS == Collision::NONE) {
|
||||||
// No hay colisión: mueve al jugador
|
// No hay colisión: mueve al jugador
|
||||||
x_ += DISPLACEMENT;
|
x_ += DISPLACEMENT;
|
||||||
} else {
|
} else {
|
||||||
// Hay colisión: reposiciona al jugador en el punto de colisión
|
// Hay colisión: reposiciona al jugador en el punto de colisión
|
||||||
x_ = direction < 0 ? POS + 1 : POS - WIDTH;
|
x_ = direction == Direction::LEFT ? POS + 1 : POS - WIDTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maneja el movimiento sobre rampas
|
// Maneja el movimiento sobre rampas
|
||||||
@@ -350,10 +349,10 @@ void Player::moveVerticalUp(float delta_time) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Comprueba la colisión
|
// Comprueba la colisión
|
||||||
const int POS = room_->checkBottomSurfaces(&proj);
|
const int POS = room_->checkBottomSurfaces(proj);
|
||||||
|
|
||||||
// Calcula la nueva posición
|
// Calcula la nueva posición
|
||||||
if (POS == -1) {
|
if (POS == Collision::NONE) {
|
||||||
// Si no hay colisión
|
// Si no hay colisión
|
||||||
y_ += DISPLACEMENT;
|
y_ += DISPLACEMENT;
|
||||||
} else {
|
} else {
|
||||||
@@ -376,21 +375,11 @@ void Player::moveVerticalDown(float delta_time) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Comprueba la colisión con las superficies normales y las automáticas
|
// Comprueba la colisión con las superficies normales y las automáticas
|
||||||
const float POS = std::max(room_->checkTopSurfaces(&proj), room_->checkAutoSurfaces(&proj));
|
const float POS = std::max(room_->checkTopSurfaces(proj), room_->checkAutoSurfaces(proj));
|
||||||
if (POS > -1) {
|
if (POS != Collision::NONE) {
|
||||||
// Si hay colisión lo mueve hasta donde no colisiona y pasa a estar sobre la superficie
|
// Si hay colisión lo mueve hasta donde no colisiona y pasa a estar sobre la superficie
|
||||||
y_ = POS - HEIGHT;
|
y_ = POS - HEIGHT;
|
||||||
|
|
||||||
// VERIFICAR MUERTE ANTES de cambiar de estado (PLAYER_MECHANICS.md línea 1268-1274)
|
|
||||||
const int FALL_DISTANCE = static_cast<int>(y_) - last_grounded_position_;
|
|
||||||
if (previous_state_ == State::FALLING && FALL_DISTANCE > MAX_FALLING_HEIGHT) {
|
|
||||||
is_alive_ = false; // Muere si cae más de 32 píxeles
|
|
||||||
}
|
|
||||||
|
|
||||||
transitionToState(State::STANDING);
|
transitionToState(State::STANDING);
|
||||||
last_grounded_position_ = static_cast<int>(y_); // Actualizar AL ENTRAR en STANDING
|
|
||||||
// Deja de estar enganchado a la superficie automatica
|
|
||||||
auto_movement_ = false;
|
|
||||||
} else {
|
} else {
|
||||||
// Si no hay colisión con los muros, comprueba la colisión con las rampas
|
// Si no hay colisión con los muros, comprueba la colisión con las rampas
|
||||||
// CORRECCIÓN: FALLING siempre se pega a rampas, JUMPING se pega solo si vx_ == 0
|
// CORRECCIÓN: FALLING siempre se pega a rampas, JUMPING se pega solo si vx_ == 0
|
||||||
@@ -399,20 +388,12 @@ void Player::moveVerticalDown(float delta_time) {
|
|||||||
auto rect = toSDLRect(proj);
|
auto rect = toSDLRect(proj);
|
||||||
const LineVertical LEFT_SIDE = {.x = rect.x, .y1 = rect.y, .y2 = rect.y + rect.h};
|
const LineVertical LEFT_SIDE = {.x = rect.x, .y1 = rect.y, .y2 = rect.y + rect.h};
|
||||||
const LineVertical RIGHT_SIDE = {.x = rect.x + rect.w - 1, .y1 = rect.y, .y2 = rect.y + rect.h};
|
const LineVertical RIGHT_SIDE = {.x = rect.x + rect.w - 1, .y1 = rect.y, .y2 = rect.y + rect.h};
|
||||||
const float POINT = std::max(room_->checkRightSlopes(&RIGHT_SIDE), room_->checkLeftSlopes(&LEFT_SIDE));
|
const float POINT = std::max(room_->checkRightSlopes(RIGHT_SIDE), room_->checkLeftSlopes(LEFT_SIDE));
|
||||||
if (POINT > -1) {
|
if (POINT != Collision::NONE) {
|
||||||
// No está saltando y hay colisión con una rampa
|
// No está saltando y hay colisión con una rampa
|
||||||
// Calcula la nueva posición
|
// Calcula la nueva posición
|
||||||
y_ = POINT - HEIGHT;
|
y_ = POINT - HEIGHT;
|
||||||
|
|
||||||
// VERIFICAR MUERTE ANTES de cambiar de estado (PLAYER_MECHANICS.md línea 1268-1274)
|
|
||||||
const int FALL_DISTANCE = static_cast<int>(y_) - last_grounded_position_;
|
|
||||||
if (previous_state_ == State::FALLING && FALL_DISTANCE > MAX_FALLING_HEIGHT) {
|
|
||||||
is_alive_ = false; // Muere si cae más de 32 píxeles
|
|
||||||
}
|
|
||||||
|
|
||||||
transitionToState(State::STANDING);
|
transitionToState(State::STANDING);
|
||||||
last_grounded_position_ = static_cast<int>(y_); // Actualizar AL ENTRAR en STANDING
|
|
||||||
} else {
|
} else {
|
||||||
// No está saltando y no hay colisón con una rampa
|
// No está saltando y no hay colisón con una rampa
|
||||||
// Calcula la nueva posición
|
// Calcula la nueva posición
|
||||||
@@ -452,7 +433,6 @@ void Player::playJumpSound(float delta_time) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Calcula y reproduce el sonido de caída basado en distancia vertical recorrida
|
// Calcula y reproduce el sonido de caída basado en distancia vertical recorrida
|
||||||
void Player::playFallSound(float delta_time) {
|
void Player::playFallSound(float delta_time) {
|
||||||
size_t sound_index;
|
size_t sound_index;
|
||||||
@@ -466,18 +446,19 @@ void Player::playFallSound(float delta_time) {
|
|||||||
// Comprueba si el jugador tiene suelo debajo de los pies
|
// Comprueba si el jugador tiene suelo debajo de los pies
|
||||||
auto Player::isOnFloor() -> bool {
|
auto Player::isOnFloor() -> bool {
|
||||||
bool on_floor = false;
|
bool on_floor = false;
|
||||||
|
|
||||||
updateFeet();
|
updateFeet();
|
||||||
|
|
||||||
// Comprueba las superficies
|
// Comprueba las superficies
|
||||||
for (auto f : under_feet_) {
|
on_floor |= room_->checkTopSurfaces(under_left_foot_);
|
||||||
on_floor |= room_->checkTopSurfaces(&f);
|
on_floor |= room_->checkTopSurfaces(under_right_foot_);
|
||||||
on_floor |= room_->checkConveyorBelts(&f);
|
|
||||||
}
|
// Comprueba las cintas transportadoras
|
||||||
|
on_floor |= room_->checkConveyorBelts(under_left_foot_);
|
||||||
|
on_floor |= room_->checkConveyorBelts(under_right_foot_);
|
||||||
|
|
||||||
// Comprueba las rampas
|
// Comprueba las rampas
|
||||||
auto on_slope_l = room_->checkLeftSlopes(under_feet_.data());
|
auto on_slope_l = room_->checkLeftSlopes(under_left_foot_);
|
||||||
auto on_slope_r = room_->checkRightSlopes(&under_feet_[1]);
|
auto on_slope_r = room_->checkRightSlopes(under_right_foot_);
|
||||||
|
|
||||||
return on_floor || on_slope_l || on_slope_r;
|
return on_floor || on_slope_l || on_slope_r;
|
||||||
}
|
}
|
||||||
@@ -485,13 +466,11 @@ auto Player::isOnFloor() -> bool {
|
|||||||
// Comprueba si el jugador esta sobre una superficie automática
|
// Comprueba si el jugador esta sobre una superficie automática
|
||||||
auto Player::isOnConveyorBelt() -> bool {
|
auto Player::isOnConveyorBelt() -> bool {
|
||||||
bool on_conveyor_belt = false;
|
bool on_conveyor_belt = false;
|
||||||
|
|
||||||
updateFeet();
|
updateFeet();
|
||||||
|
|
||||||
// Comprueba las superficies
|
// Comprueba las superficies
|
||||||
for (auto f : under_feet_) {
|
on_conveyor_belt |= room_->checkConveyorBelts(under_left_foot_);
|
||||||
on_conveyor_belt |= room_->checkConveyorBelts(&f);
|
on_conveyor_belt |= room_->checkConveyorBelts(under_right_foot_);
|
||||||
}
|
|
||||||
|
|
||||||
return on_conveyor_belt;
|
return on_conveyor_belt;
|
||||||
}
|
}
|
||||||
@@ -499,19 +478,18 @@ auto Player::isOnConveyorBelt() -> bool {
|
|||||||
// Comprueba si el jugador está sobre una rampa hacia abajo
|
// Comprueba si el jugador está sobre una rampa hacia abajo
|
||||||
auto Player::isOnDownSlope() -> bool {
|
auto Player::isOnDownSlope() -> bool {
|
||||||
bool on_slope = false;
|
bool on_slope = false;
|
||||||
|
|
||||||
updateFeet();
|
updateFeet();
|
||||||
|
|
||||||
// Cuando el jugador baja una escalera, se queda volando
|
// Cuando el jugador baja una escalera, se queda volando
|
||||||
// Hay que mirar otro pixel más por debajo
|
// Hay que mirar otro pixel más por debajo
|
||||||
SDL_FPoint foot0 = under_feet_[0];
|
SDL_FPoint left_foot = under_left_foot_;
|
||||||
SDL_FPoint foot1 = under_feet_[1];
|
SDL_FPoint right_foot = under_right_foot_;
|
||||||
foot0.y += 1.0F;
|
left_foot.y += 1.0F;
|
||||||
foot1.y += 1.0F;
|
right_foot.y += 1.0F;
|
||||||
|
|
||||||
// Comprueba las rampas
|
// Comprueba las rampas
|
||||||
on_slope |= room_->checkLeftSlopes(&foot0);
|
on_slope |= room_->checkLeftSlopes(left_foot);
|
||||||
on_slope |= room_->checkRightSlopes(&foot1);
|
on_slope |= room_->checkRightSlopes(right_foot);
|
||||||
|
|
||||||
return on_slope;
|
return on_slope;
|
||||||
}
|
}
|
||||||
@@ -555,13 +533,12 @@ void Player::updateColliderPoints() {
|
|||||||
|
|
||||||
// Actualiza los puntos de los pies
|
// Actualiza los puntos de los pies
|
||||||
void Player::updateFeet() {
|
void Player::updateFeet() {
|
||||||
const SDL_FPoint P = {x_, y_};
|
under_left_foot_ = {
|
||||||
|
.x = x_,
|
||||||
under_feet_[0] = {.x = P.x, .y = P.y + HEIGHT};
|
.y = y_ + HEIGHT};
|
||||||
under_feet_[1] = {.x = P.x + 7, .y = P.y + HEIGHT};
|
under_right_foot_ = {
|
||||||
|
.x = x_ + WIDTH - 1,
|
||||||
feet_[0] = {.x = P.x, .y = P.y + HEIGHT - 1};
|
.y = y_ + HEIGHT};
|
||||||
feet_[1] = {.x = P.x + 7, .y = P.y + HEIGHT - 1};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa los sonidos de salto y caida
|
// Inicializa los sonidos de salto y caida
|
||||||
@@ -658,7 +635,6 @@ auto Player::FallSoundController::shouldPlay(float delta_time, float current_y,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Aplica los valores de spawn al jugador
|
// Aplica los valores de spawn al jugador
|
||||||
void Player::applySpawnValues(const SpawnData& spawn) {
|
void Player::applySpawnValues(const SpawnData& spawn) {
|
||||||
x_ = spawn.x;
|
x_ = spawn.x;
|
||||||
|
|||||||
@@ -149,8 +149,8 @@ class Player {
|
|||||||
// --- Variables de colisión ---
|
// --- Variables de colisión ---
|
||||||
SDL_FRect collider_box_; // Caja de colisión con los enemigos u objetos
|
SDL_FRect collider_box_; // Caja de colisión con los enemigos u objetos
|
||||||
std::array<SDL_FPoint, 8> collider_points_{}; // Puntos de colisión con el mapa
|
std::array<SDL_FPoint, 8> collider_points_{}; // Puntos de colisión con el mapa
|
||||||
std::array<SDL_FPoint, 2> under_feet_{}; // Contiene los puntos que hay bajo cada pie del jugador
|
SDL_FPoint under_left_foot_ = {0.0F, 0.0F}; // El punto bajo la esquina inferior izquierda del jugador
|
||||||
std::array<SDL_FPoint, 2> feet_{}; // Contiene los puntos que hay en el pie del jugador
|
SDL_FPoint under_right_foot_ = {0.0F, 0.0F}; // El punto bajo la esquina inferior derecha del jugador
|
||||||
|
|
||||||
// --- Variables de juego ---
|
// --- Variables de juego ---
|
||||||
bool is_on_border_ = false; // Indica si el jugador esta en uno de los cuatro bordes de la pantalla
|
bool is_on_border_ = false; // Indica si el jugador esta en uno de los cuatro bordes de la pantalla
|
||||||
@@ -173,7 +173,6 @@ class Player {
|
|||||||
void handleConveyorBelts();
|
void handleConveyorBelts();
|
||||||
void handleShouldFall();
|
void handleShouldFall();
|
||||||
void updateState(float delta_time);
|
void updateState(float delta_time);
|
||||||
void moveAndCollide(float delta_time);
|
|
||||||
|
|
||||||
// --- Funciones de inicialización ---
|
// --- Funciones de inicialización ---
|
||||||
void initSprite(const std::string& animations_path); // Inicializa el sprite del jugador
|
void initSprite(const std::string& animations_path); // Inicializa el sprite del jugador
|
||||||
@@ -192,10 +191,10 @@ class Player {
|
|||||||
|
|
||||||
// --- Funciones de movimiento y colisión ---
|
// --- Funciones de movimiento y colisión ---
|
||||||
void move(float delta_time); // Orquesta el movimiento del jugador
|
void move(float delta_time); // Orquesta el movimiento del jugador
|
||||||
void moveHorizontal(float delta_time, int direction); // Maneja el movimiento horizontal (-1: izq, 1: der)
|
void moveHorizontal(float delta_time, Direction direction); // Maneja el movimiento horizontal (-1: izq, 1: der)
|
||||||
void moveVerticalUp(float delta_time); // Maneja el movimiento vertical hacia arriba
|
void moveVerticalUp(float delta_time); // Maneja el movimiento vertical hacia arriba
|
||||||
void moveVerticalDown(float delta_time); // Maneja el movimiento vertical hacia abajo
|
void moveVerticalDown(float delta_time); // Maneja el movimiento vertical hacia abajo
|
||||||
void handleSlopeMovement(int direction); // Maneja el movimiento sobre rampas
|
void handleSlopeMovement(Direction direction); // Maneja el movimiento sobre rampas
|
||||||
|
|
||||||
// --- Funciones de detección de superficies ---
|
// --- Funciones de detección de superficies ---
|
||||||
auto isOnFloor() -> bool; // Comprueba si el jugador tiene suelo debajo de los pies
|
auto isOnFloor() -> bool; // Comprueba si el jugador tiene suelo debajo de los pies
|
||||||
|
|||||||
@@ -681,109 +681,109 @@ void Room::renderAnimatedTiles() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las colisiones
|
// Comprueba las colisiones
|
||||||
auto Room::checkRightSurfaces(SDL_FRect* rect) -> int {
|
auto Room::checkRightSurfaces(SDL_FRect& rect) -> int {
|
||||||
for (const auto& s : right_walls_) {
|
for (const auto& s : right_walls_) {
|
||||||
if (checkCollision(s, *rect)) {
|
if (checkCollision(s, rect)) {
|
||||||
return s.x;
|
return s.x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return Collision::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las colisiones
|
// Comprueba las colisiones
|
||||||
auto Room::checkLeftSurfaces(SDL_FRect* rect) -> int {
|
auto Room::checkLeftSurfaces(SDL_FRect& rect) -> int {
|
||||||
for (const auto& s : left_walls_) {
|
for (const auto& s : left_walls_) {
|
||||||
if (checkCollision(s, *rect)) {
|
if (checkCollision(s, rect)) {
|
||||||
return s.x;
|
return s.x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return Collision::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las colisiones
|
// Comprueba las colisiones
|
||||||
auto Room::checkTopSurfaces(SDL_FRect* rect) -> int {
|
auto Room::checkTopSurfaces(SDL_FRect& rect) -> int {
|
||||||
for (const auto& s : top_floors_) {
|
for (const auto& s : top_floors_) {
|
||||||
if (checkCollision(s, *rect)) {
|
if (checkCollision(s, rect)) {
|
||||||
return s.y;
|
return s.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return Collision::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las colisiones
|
// Comprueba las colisiones
|
||||||
auto Room::checkBottomSurfaces(SDL_FRect* rect) -> int {
|
auto Room::checkBottomSurfaces(SDL_FRect& rect) -> int {
|
||||||
for (const auto& s : bottom_floors_) {
|
for (const auto& s : bottom_floors_) {
|
||||||
if (checkCollision(s, *rect)) {
|
if (checkCollision(s, rect)) {
|
||||||
return s.y;
|
return s.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return Collision::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las colisiones
|
// Comprueba las colisiones
|
||||||
auto Room::checkAutoSurfaces(SDL_FRect* rect) -> int {
|
auto Room::checkAutoSurfaces(SDL_FRect& rect) -> int {
|
||||||
for (const auto& s : conveyor_belt_floors_) {
|
for (const auto& s : conveyor_belt_floors_) {
|
||||||
if (checkCollision(s, *rect)) {
|
if (checkCollision(s, rect)) {
|
||||||
return s.y;
|
return s.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return Collision::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las colisiones
|
// Comprueba las colisiones
|
||||||
auto Room::checkTopSurfaces(SDL_FPoint* p) -> bool {
|
auto Room::checkTopSurfaces(SDL_FPoint& p) -> bool {
|
||||||
return std::ranges::any_of(top_floors_, [&](const auto& s) {
|
return std::ranges::any_of(top_floors_, [&](const auto& s) {
|
||||||
return checkCollision(s, *p);
|
return checkCollision(s, p);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las colisiones
|
// Comprueba las colisiones
|
||||||
auto Room::checkConveyorBelts(SDL_FPoint* p) -> bool {
|
auto Room::checkConveyorBelts(SDL_FPoint& p) -> bool {
|
||||||
return std::ranges::any_of(conveyor_belt_floors_, [&](const auto& s) {
|
return std::ranges::any_of(conveyor_belt_floors_, [&](const auto& s) {
|
||||||
return checkCollision(s, *p);
|
return checkCollision(s, p);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las colisiones
|
// Comprueba las colisiones
|
||||||
auto Room::checkLeftSlopes(const LineVertical* line) -> int {
|
auto Room::checkLeftSlopes(const LineVertical& line) -> int {
|
||||||
for (const auto& slope : left_slopes_) {
|
for (const auto& slope : left_slopes_) {
|
||||||
const auto P = checkCollision(slope, *line);
|
const auto P = checkCollision(slope, line);
|
||||||
if (P.x != -1) {
|
if (P.x != -1) {
|
||||||
return P.y;
|
return P.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return Collision::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las colisiones
|
// Comprueba las colisiones
|
||||||
auto Room::checkLeftSlopes(SDL_FPoint* p) -> bool {
|
auto Room::checkLeftSlopes(SDL_FPoint& p) -> bool {
|
||||||
return std::ranges::any_of(left_slopes_, [&](const auto& slope) {
|
return std::ranges::any_of(left_slopes_, [&](const auto& slope) {
|
||||||
return checkCollision(*p, slope);
|
return checkCollision(p, slope);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las colisiones
|
// Comprueba las colisiones
|
||||||
auto Room::checkRightSlopes(const LineVertical* line) -> int {
|
auto Room::checkRightSlopes(const LineVertical& line) -> int {
|
||||||
for (const auto& slope : right_slopes_) {
|
for (const auto& slope : right_slopes_) {
|
||||||
const auto P = checkCollision(slope, *line);
|
const auto P = checkCollision(slope, line);
|
||||||
if (P.x != -1) {
|
if (P.x != -1) {
|
||||||
return P.y;
|
return P.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return Collision::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las colisiones
|
// Comprueba las colisiones
|
||||||
auto Room::checkRightSlopes(SDL_FPoint* p) -> bool {
|
auto Room::checkRightSlopes(SDL_FPoint& p) -> bool {
|
||||||
return std::ranges::any_of(right_slopes_, [&](const auto& slope) {
|
return std::ranges::any_of(right_slopes_, [&](const auto& slope) {
|
||||||
return checkCollision(*p, slope);
|
return checkCollision(p, slope);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,17 +78,17 @@ class Room {
|
|||||||
auto itemCollision(SDL_FRect& rect) -> bool; // Indica si hay colision con un objeto a partir de un rectangulo
|
auto itemCollision(SDL_FRect& rect) -> bool; // Indica si hay colision con un objeto a partir de un rectangulo
|
||||||
static auto getTileSize() -> int { return TILE_SIZE; } // Obten el tamaño del tile
|
static auto getTileSize() -> int { return TILE_SIZE; } // Obten el tamaño del tile
|
||||||
static auto getSlopeHeight(SDL_FPoint p, Tile slope) -> int; // Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile
|
static auto getSlopeHeight(SDL_FPoint p, Tile slope) -> int; // Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile
|
||||||
auto checkRightSurfaces(SDL_FRect* rect) -> int; // Comprueba las colisiones
|
auto checkRightSurfaces(SDL_FRect& rect) -> int; // Comprueba las colisiones
|
||||||
auto checkLeftSurfaces(SDL_FRect* rect) -> int; // Comprueba las colisiones
|
auto checkLeftSurfaces(SDL_FRect& rect) -> int; // Comprueba las colisiones
|
||||||
auto checkTopSurfaces(SDL_FRect* rect) -> int; // Comprueba las colisiones
|
auto checkTopSurfaces(SDL_FRect& rect) -> int; // Comprueba las colisiones
|
||||||
auto checkBottomSurfaces(SDL_FRect* rect) -> int; // Comprueba las colisiones
|
auto checkBottomSurfaces(SDL_FRect& rect) -> int; // Comprueba las colisiones
|
||||||
auto checkAutoSurfaces(SDL_FRect* rect) -> int; // Comprueba las colisiones
|
auto checkAutoSurfaces(SDL_FRect& rect) -> int; // Comprueba las colisiones
|
||||||
auto checkTopSurfaces(SDL_FPoint* p) -> bool; // Comprueba las colisiones
|
auto checkTopSurfaces(SDL_FPoint& p) -> bool; // Comprueba las colisiones
|
||||||
auto checkConveyorBelts(SDL_FPoint* p) -> bool; // Comprueba las colisiones
|
auto checkConveyorBelts(SDL_FPoint& p) -> bool; // Comprueba las colisiones
|
||||||
auto checkLeftSlopes(const LineVertical* line) -> int; // Comprueba las colisiones
|
auto checkLeftSlopes(const LineVertical& line) -> int; // Comprueba las colisiones
|
||||||
auto checkLeftSlopes(SDL_FPoint* p) -> bool; // Comprueba las colisiones
|
auto checkLeftSlopes(SDL_FPoint& p) -> bool; // Comprueba las colisiones
|
||||||
auto checkRightSlopes(const LineVertical* line) -> int; // Comprueba las colisiones
|
auto checkRightSlopes(const LineVertical& line) -> int; // Comprueba las colisiones
|
||||||
auto checkRightSlopes(SDL_FPoint* p) -> bool; // Comprueba las colisiones
|
auto checkRightSlopes(SDL_FPoint& p) -> bool; // Comprueba las colisiones
|
||||||
void setPaused(bool value) { is_paused_ = value; }; // Pone el mapa en modo pausa
|
void setPaused(bool value) { is_paused_ = 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 getConveyorBeltDirection() const -> int { return conveyor_belt_direction_; } // Obten la direccion de las superficies automaticas
|
||||||
static auto loadRoomFile(const std::string& file_path, bool verbose = false) -> Data; // Carga las variables desde un fichero de mapa
|
static auto loadRoomFile(const std::string& file_path, bool verbose = false) -> Data; // Carga las variables desde un fichero de mapa
|
||||||
|
|||||||
@@ -42,3 +42,8 @@ constexpr int GAMECANVAS_THIRD_QUARTER_X = (GAMECANVAS_WIDTH / 4) * 3;
|
|||||||
constexpr int GAMECANVAS_CENTER_Y = GAMECANVAS_HEIGHT / 2;
|
constexpr int GAMECANVAS_CENTER_Y = GAMECANVAS_HEIGHT / 2;
|
||||||
constexpr int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4;
|
constexpr int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4;
|
||||||
constexpr int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
|
constexpr int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
|
||||||
|
|
||||||
|
namespace Collision
|
||||||
|
{
|
||||||
|
constexpr int NONE = -1;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user