style: corregides les capçaleres de game/entities

This commit is contained in:
2025-10-29 09:21:05 +01:00
parent acdad8295a
commit cd836862c0
11 changed files with 270 additions and 360 deletions

View File

@@ -15,12 +15,12 @@
#include "utils/defines.hpp" // Para RoomBorder::BOTTOM, RoomBorder::LEFT, RoomBorder::RIGHT
// Constructor
Player::Player(const PlayerData& player)
Player::Player(const Data& player)
: room_(player.room) {
// Inicializa algunas variables
initSprite(player.texture_path, player.animations_path);
setColor();
applySpawnValues(player.spawn);
applySpawnValues(player.spawn_data);
placeSprite();
initSounds();
@@ -51,12 +51,12 @@ void Player::render() {
// Actualiza las variables del objeto
void Player::update(float delta_time) {
if (!is_paused_) {
checkInput(delta_time); // Comprueba las entradas y modifica variables
move(delta_time); // Recalcula la posición del jugador
animate(delta_time); // Establece la animación del jugador
checkBorders(); // Comprueba si está situado en alguno de los cuatro bordes de la habitación
checkJumpEnd(); // Comprueba si ha finalizado el salto al alcanzar la altura de inicio
checkKillingTiles(); // Comprueba que el jugador no toque ningun tile de los que matan}
checkInput(delta_time); // Comprueba las entradas y modifica variables
move(delta_time); // Recalcula la posición del jugador
animate(delta_time); // Establece la animación del jugador
checkBorders(); // Comprueba si está situado en alguno de los cuatro bordes de la habitación
checkJumpEnd(); // Comprueba si ha finalizado el salto al alcanzar la altura de inicio
checkKillingTiles(); // Comprueba que el jugador no toque ningun tile de los que matan}
}
}
@@ -65,7 +65,7 @@ void Player::checkInput(float delta_time) {
(void)delta_time; // No usado en este método, pero mantenido para consistencia
// Solo comprueba las entradas de dirección cuando está sobre una superficie
if (state_ != PlayerState::STANDING) {
if (state_ != State::STANDING) {
return;
}
@@ -106,7 +106,7 @@ void Player::checkInput(float delta_time) {
// Ya que se coloca el estado s_standing al cambiar de pantalla
if (isOnFloor() || isOnAutoSurface()) {
setState(PlayerState::JUMPING);
setState(State::JUMPING);
vy_ = JUMP_VELOCITY;
jump_init_pos_ = y_;
jumping_time_ = 0.0F;
@@ -144,24 +144,24 @@ void Player::checkBorders() {
// Comprueba el estado del jugador
void Player::checkState(float delta_time) {
// Actualiza las variables en función del estado
if (state_ == PlayerState::FALLING) {
if (state_ == State::FALLING) {
vx_ = 0.0F;
vy_ = MAX_VY;
falling_time_ += delta_time;
playFallSound();
}
else if (state_ == PlayerState::STANDING) {
else if (state_ == State::STANDING) {
// Calcula la distancia de caída en pixels (velocidad * tiempo)
const float FALLING_DISTANCE = MAX_VY * falling_time_;
if (previous_state_ == PlayerState::FALLING && FALLING_DISTANCE > MAX_FALLING_HEIGHT) { // Si cae de muy alto, el jugador muere
if (previous_state_ == State::FALLING && FALLING_DISTANCE > MAX_FALLING_HEIGHT) { // Si cae de muy alto, el jugador muere
is_alive_ = false;
}
vy_ = 0.0F;
jumping_time_ = 0.0F;
falling_time_ = 0.0F;
if (!isOnFloor() && !isOnAutoSurface() && !isOnDownSlope()) {
setState(PlayerState::FALLING);
setState(State::FALLING);
vx_ = 0.0F;
vy_ = MAX_VY;
falling_time_ += delta_time;
@@ -169,7 +169,7 @@ void Player::checkState(float delta_time) {
}
}
else if (state_ == PlayerState::JUMPING) {
else if (state_ == State::JUMPING) {
falling_time_ = 0.0F;
jumping_time_ += delta_time;
playJumpSound();
@@ -181,12 +181,12 @@ void Player::switchBorders() {
switch (border_) {
case RoomBorder::TOP:
y_ = PLAY_AREA_BOTTOM - HEIGHT - BLOCK;
setState(PlayerState::STANDING);
setState(State::STANDING);
break;
case RoomBorder::BOTTOM:
y_ = PLAY_AREA_TOP;
setState(PlayerState::STANDING);
setState(State::STANDING);
break;
case RoomBorder::RIGHT:
@@ -210,7 +210,7 @@ void Player::switchBorders() {
void Player::applyGravity(float delta_time) {
// La gravedad solo se aplica cuando el jugador esta saltando
// Nunca mientras cae o esta de pie
if (state_ == PlayerState::JUMPING) {
if (state_ == State::JUMPING) {
vy_ += GRAVITY_FORCE * delta_time;
vy_ = std::min(vy_, MAX_VY);
}
@@ -243,7 +243,7 @@ void Player::moveHorizontalLeft(float delta_time) {
}
// Si ha tocado alguna rampa mientras camina (sin saltar), asciende
if (state_ != PlayerState::JUMPING) {
if (state_ != State::JUMPING) {
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) {
@@ -252,7 +252,7 @@ void Player::moveHorizontalLeft(float delta_time) {
}
// Si está bajando la rampa, recoloca al jugador
if (isOnDownSlope() && state_ != PlayerState::JUMPING) {
if (isOnDownSlope() && state_ != State::JUMPING) {
y_ += 1;
}
}
@@ -284,7 +284,7 @@ void Player::moveHorizontalRight(float delta_time) {
}
// Si ha tocado alguna rampa mientras camina (sin saltar), asciende
if (state_ != PlayerState::JUMPING) {
if (state_ != State::JUMPING) {
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) {
@@ -293,7 +293,7 @@ void Player::moveHorizontalRight(float delta_time) {
}
// Si está bajando la rampa, recoloca al jugador
if (isOnDownSlope() && state_ != PlayerState::JUMPING) {
if (isOnDownSlope() && state_ != State::JUMPING) {
y_ += 1;
}
}
@@ -322,7 +322,7 @@ void Player::moveVerticalUp(float delta_time) {
} else {
// Si hay colisión lo mueve hasta donde no colisiona y entra en caída
y_ = POS + 1;
setState(PlayerState::FALLING);
setState(State::FALLING);
}
}
@@ -345,13 +345,13 @@ void Player::moveVerticalDown(float delta_time) {
if (POS > -1) {
// Si hay colisión lo mueve hasta donde no colisiona y pasa a estar sobre la superficie
y_ = POS - HEIGHT;
setState(PlayerState::STANDING);
setState(State::STANDING);
// Deja de estar enganchado a la superficie automatica
auto_movement_ = false;
} else {
// 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
if (state_ != State::JUMPING) { // Las rampas no se miran si se está saltando
auto rect = toSDLRect(proj);
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};
@@ -360,7 +360,7 @@ void Player::moveVerticalDown(float delta_time) {
// No está saltando y hay colisión con una rampa
// Calcula la nueva posición
y_ = POINT - HEIGHT;
setState(PlayerState::STANDING);
setState(State::STANDING);
#ifdef _DEBUG
debug_color_ = static_cast<Uint8>(PaletteColor::YELLOW);
debug_point_ = {.x = x_ + (WIDTH / 2), .y = POINT};
@@ -384,8 +384,8 @@ void Player::moveVerticalDown(float delta_time) {
// Recalcula la posición del jugador y su animación
void Player::move(float delta_time) {
last_position_ = {.x = x_, .y = y_}; // Guarda la posicion actual antes de modificarla
applyGravity(delta_time); // Aplica gravedad al jugador
checkState(delta_time); // Comprueba el estado del jugador
applyGravity(delta_time); // Aplica gravedad al jugador
checkState(delta_time); // Comprueba el estado del jugador
#ifdef _DEBUG
debug_color_ = static_cast<Uint8>(PaletteColor::GREEN);
@@ -399,13 +399,13 @@ void Player::move(float delta_time) {
}
// Si ha salido del suelo, el jugador cae
if (state_ == PlayerState::STANDING && !isOnFloor()) {
setState(PlayerState::FALLING);
if (state_ == State::STANDING && !isOnFloor()) {
setState(State::FALLING);
auto_movement_ = false;
}
// Si ha salido de una superficie automatica, detiene el movimiento automatico
if (state_ == PlayerState::STANDING && isOnFloor() && !isOnAutoSurface()) {
if (state_ == State::STANDING && isOnFloor() && !isOnAutoSurface()) {
auto_movement_ = false;
}
@@ -434,11 +434,11 @@ void Player::animate(float delta_time) {
// Comprueba si ha finalizado el salto al alcanzar la altura de inicio
void Player::checkJumpEnd() {
if (state_ == PlayerState::JUMPING) {
if (state_ == State::JUMPING) {
if (vy_ > 0) {
if (y_ >= jump_init_pos_) {
// Si alcanza la altura de salto inicial, pasa al estado de caída
setState(PlayerState::FALLING);
setState(State::FALLING);
vy_ = MAX_VY;
jumping_time_ = 0.0F;
}
@@ -606,7 +606,7 @@ void Player::updateFeet() {
}
// Cambia el estado del jugador
void Player::setState(PlayerState value) {
void Player::setState(State value) {
previous_state_ = state_;
state_ = value;
@@ -630,7 +630,7 @@ void Player::initSounds() {
}
// Aplica los valores de spawn al jugador
void Player::applySpawnValues(const PlayerSpawn& spawn) {
void Player::applySpawnValues(const SpawnData& spawn) {
x_ = spawn.x;
y_ = spawn.y;
vx_ = spawn.vx;