This commit is contained in:
2025-10-27 18:35:53 +01:00
parent b1dca32a5b
commit 3179a08dac
63 changed files with 686 additions and 693 deletions

View File

@@ -32,10 +32,10 @@ Player::Player(const PlayerData& player)
feet_.resize(feet_.size() + 2, {0, 0});
#ifdef _DEBUG
debug_rect_x_ = {0, 0, 0, 0};
debug_rect_y_ = {0, 0, 0, 0};
debug_rect_x_ = {.x = 0, .y = 0, .w = 0, .h = 0};
debug_rect_y_ = {.x = 0, .y = 0, .w = 0, .h = 0};
debug_color_ = static_cast<Uint8>(PaletteColor::GREEN);
debug_point_ = {0, 0};
debug_point_ = {.x = 0, .y = 0};
#endif
}
@@ -241,7 +241,7 @@ void Player::moveHorizontalLeft() {
// Si ha tocado alguna rampa mientras camina (sin saltar), asciende
if (state_ != PlayerState::JUMPING) {
const LineVertical LEFT_SIDE = {static_cast<int>(x_), static_cast<int>(y_) + static_cast<int>(HEIGHT) - 2, static_cast<int>(y_) + static_cast<int>(HEIGHT) - 1}; // Comprueba solo los dos pixels de abajo
const LineVertical LEFT_SIDE = {.x = static_cast<int>(x_), .y1 = static_cast<int>(y_) + static_cast<int>(HEIGHT) - 2, .y2 = static_cast<int>(y_) + static_cast<int>(HEIGHT) - 1}; // Comprueba solo los dos pixels de abajo
const int LY = room_->checkLeftSlopes(&LEFT_SIDE);
if (LY > -1) {
y_ = LY - HEIGHT;
@@ -261,7 +261,7 @@ void Player::moveHorizontalRight() {
proj.x = x_ + WIDTH;
proj.y = y_;
proj.h = HEIGHT;
proj.w = ceil(vx_); // Para evitar que tenga un ancho de 0 pixels
proj.w = std::ceil(vx_); // Para evitar que tenga un ancho de 0 pixels
#ifdef _DEBUG
debug_rect_x_ = proj;
@@ -281,7 +281,7 @@ void Player::moveHorizontalRight() {
// Si ha tocado alguna rampa mientras camina (sin saltar), asciende
if (state_ != PlayerState::JUMPING) {
const LineVertical RIGHT_SIDE = {static_cast<int>(x_) + static_cast<int>(WIDTH) - 1, static_cast<int>(y_) + static_cast<int>(HEIGHT) - 2, static_cast<int>(y_) + static_cast<int>(HEIGHT) - 1}; // Comprueba solo los dos pixels de abajo
const LineVertical RIGHT_SIDE = {.x = static_cast<int>(x_) + static_cast<int>(WIDTH) - 1, .y1 = static_cast<int>(y_) + static_cast<int>(HEIGHT) - 2, .y2 = static_cast<int>(y_) + static_cast<int>(HEIGHT) - 1}; // Comprueba solo los dos pixels de abajo
const int RY = room_->checkRightSlopes(&RIGHT_SIDE);
if (RY > -1) {
y_ = RY - HEIGHT;
@@ -327,7 +327,7 @@ void Player::moveVerticalDown() {
SDL_FRect proj;
proj.x = x_;
proj.y = y_ + HEIGHT;
proj.h = ceil(vy_); // Para evitar que tenga una altura de 0 pixels
proj.h = std::ceil(vy_); // Para evitar que tenga una altura de 0 pixels
proj.w = WIDTH;
#ifdef _DEBUG
@@ -347,8 +347,8 @@ void Player::moveVerticalDown() {
// Si no hay colisión con los muros, comprueba la colisión con las rampas
if (state_ != PlayerState::JUMPING) { // Las rampas no se miran si se está saltando
auto rect = toSDLRect(proj);
const LineVertical LEFT_SIDE = {rect.x, rect.y, rect.y + rect.h - 1};
const LineVertical RIGHT_SIDE = {rect.x + rect.w - 1, rect.y, rect.y + rect.h - 1};
const LineVertical LEFT_SIDE = {.x = rect.x, .y1 = rect.y, .y2 = rect.y + rect.h - 1};
const LineVertical RIGHT_SIDE = {.x = rect.x + rect.w - 1, .y1 = rect.y, .y2 = rect.y + rect.h - 1};
const float POINT = std::max(room_->checkRightSlopes(&RIGHT_SIDE), room_->checkLeftSlopes(&LEFT_SIDE));
if (POINT > -1) {
// No está saltando y hay colisión con una rampa
@@ -357,7 +357,7 @@ void Player::moveVerticalDown() {
setState(PlayerState::STANDING);
#ifdef _DEBUG
debug_color_ = static_cast<Uint8>(PaletteColor::YELLOW);
debug_point_ = {x_ + (WIDTH / 2), POINT};
debug_point_ = {.x = x_ + (WIDTH / 2), .y = POINT};
#endif
} else {
// No está saltando y no hay colisón con una rampa
@@ -377,7 +377,7 @@ void Player::moveVerticalDown() {
// Recalcula la posición del jugador y su animación
void Player::move() {
last_position_ = {x_, y_}; // Guarda la posicion actual antes de modificarla
last_position_ = {.x = x_, .y = y_}; // Guarda la posicion actual antes de modificarla
applyGravity(); // Aplica gravedad al jugador
checkState(); // Comprueba el estado del jugador
@@ -463,7 +463,7 @@ void Player::playFallSound() {
}
// Comprueba si el jugador tiene suelo debajo de los pies
bool Player::isOnFloor() {
auto Player::isOnFloor() -> bool {
bool on_floor = false;
bool on_slope_l = false;
bool on_slope_r = false;
@@ -498,7 +498,7 @@ bool Player::isOnFloor() {
}
// Comprueba si el jugador esta sobre una superficie automática
bool Player::isOnAutoSurface() {
auto Player::isOnAutoSurface() -> bool {
bool on_auto_surface = false;
updateFeet();
@@ -518,7 +518,7 @@ bool Player::isOnAutoSurface() {
}
// Comprueba si el jugador está sobre una rampa hacia abajo
bool Player::isOnDownSlope() {
auto Player::isOnDownSlope() -> bool {
bool on_slope = false;
updateFeet();
@@ -542,7 +542,7 @@ bool Player::isOnDownSlope() {
}
// Comprueba que el jugador no toque ningun tile de los que matan
bool Player::checkKillingTiles() {
auto Player::checkKillingTiles() -> bool {
// Actualiza los puntos de colisión
updateColliderPoints();
@@ -571,25 +571,25 @@ void Player::setColor() {
// Actualiza los puntos de colisión
void Player::updateColliderPoints() {
const SDL_FRect RECT = getRect();
collider_points_[0] = {RECT.x, RECT.y};
collider_points_[1] = {RECT.x + 7, RECT.y};
collider_points_[2] = {RECT.x + 7, RECT.y + 7};
collider_points_[3] = {RECT.x, RECT.y + 7};
collider_points_[4] = {RECT.x, RECT.y + 8};
collider_points_[5] = {RECT.x + 7, RECT.y + 8};
collider_points_[6] = {RECT.x + 7, RECT.y + 15};
collider_points_[7] = {RECT.x, RECT.y + 15};
collider_points_[0] = {.x = RECT.x, .y = RECT.y};
collider_points_[1] = {.x = RECT.x + 7, .y = RECT.y};
collider_points_[2] = {.x = RECT.x + 7, .y = RECT.y + 7};
collider_points_[3] = {.x = RECT.x, .y = RECT.y + 7};
collider_points_[4] = {.x = RECT.x, .y = RECT.y + 8};
collider_points_[5] = {.x = RECT.x + 7, .y = RECT.y + 8};
collider_points_[6] = {.x = RECT.x + 7, .y = RECT.y + 15};
collider_points_[7] = {.x = RECT.x, .y = RECT.y + 15};
}
// Actualiza los puntos de los pies
void Player::updateFeet() {
const SDL_FPoint P = {x_, y_};
under_feet_[0] = {P.x, P.y + HEIGHT};
under_feet_[1] = {P.x + 7, P.y + HEIGHT};
under_feet_[0] = {.x = P.x, .y = P.y + HEIGHT};
under_feet_[1] = {.x = P.x + 7, .y = P.y + HEIGHT};
feet_[0] = {P.x, P.y + HEIGHT - 1};
feet_[1] = {P.x + 7, P.y + HEIGHT - 1};
feet_[0] = {.x = P.x, .y = P.y + HEIGHT - 1};
feet_[1] = {.x = P.x + 7, .y = P.y + HEIGHT - 1};
}
// Cambia el estado del jugador