4 merdes fetes en la feina pr avorriment

This commit is contained in:
2025-11-03 14:12:17 +01:00
parent d4030ec1bc
commit 66a580aff6
5 changed files with 87 additions and 152 deletions

View File

@@ -91,7 +91,7 @@ void Player::handleInput(float delta_time) {
// Ya que se coloca el estado STANDING al cambiar de pantalla
if (isOnFloor() || isOnAutoSurface()) {
setState(State::JUMPING);
transitionToState(State::JUMPING);
vy_ = JUMP_VELOCITY;
last_grounded_position_ = static_cast<int>(y_);
}
@@ -136,7 +136,7 @@ void Player::handleState(float delta_time) {
// Si no tiene suelo debajo y no está en rampa descendente -> FALLING
if (!isOnFloor() && !isOnAutoSurface() && !isOnDownSlope()) {
last_grounded_position_ = static_cast<int>(y_); // Guarda Y actual al SALIR de STANDING
setState(State::FALLING); // setState() establece vx_=0, vy_=MAX_VY
transitionToState(State::FALLING); // setState() establece vx_=0, vy_=MAX_VY
playFallSound();
}
} else if (state_ == State::JUMPING) {
@@ -149,12 +149,12 @@ void Player::switchBorders() {
switch (border_) {
case Room::Border::TOP:
y_ = PLAY_AREA_BOTTOM - HEIGHT - TILE_SIZE;
setState(State::STANDING);
transitionToState(State::STANDING);
break;
case Room::Border::BOTTOM:
y_ = PLAY_AREA_TOP;
setState(State::STANDING);
transitionToState(State::STANDING);
break;
case Room::Border::RIGHT:
@@ -278,7 +278,7 @@ void Player::moveVerticalUp(float delta_time) {
// Si hay colisión lo mueve hasta donde no colisiona
// Regla: Si está JUMPING y tropieza contra el techo -> FALLING
y_ = POS + 1;
setState(State::FALLING);
transitionToState(State::FALLING);
}
}
@@ -305,7 +305,7 @@ void Player::moveVerticalDown(float delta_time) {
is_alive_ = false; // Muere si cae más de 32 píxeles
}
setState(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;
@@ -329,7 +329,7 @@ void Player::moveVerticalDown(float delta_time) {
is_alive_ = false; // Muere si cae más de 32 píxeles
}
setState(State::STANDING);
transitionToState(State::STANDING);
last_grounded_position_ = static_cast<int>(y_); // Actualizar AL ENTRAR en STANDING
} else {
// No está saltando y no hay colisón con una rampa
@@ -358,7 +358,7 @@ void Player::move(float delta_time) {
// Si ha salido del suelo, el jugador cae
if (state_ == State::STANDING && !isOnFloor()) {
setState(State::FALLING);
transitionToState(State::FALLING);
auto_movement_ = false;
}
@@ -392,7 +392,7 @@ void Player::handleJumpEnd() {
// Si el jugador vuelve EXACTAMENTE a la altura inicial, debe CONTINUAR en JUMPING
// Solo cuando la SUPERA (desciende más allá) cambia a FALLING
if (state_ == State::JUMPING && vy_ > 0.0F && static_cast<int>(y_) > last_grounded_position_) {
setState(State::FALLING);
transitionToState(State::FALLING);
}
}
@@ -551,7 +551,7 @@ void Player::updateFeet() {
}
// Cambia el estado del jugador
void Player::setState(State value) {
void Player::transitionToState(State value) {
previous_state_ = state_;
state_ = value;

View File

@@ -68,7 +68,7 @@ class Player {
// --- Funciones ---
void render(); // Pinta el enemigo en pantalla
void update(float delta_time); // Actualiza las variables del objeto
[[nodiscard]] auto getOnBorder() const -> bool { return is_on_border_; } // Indica si el jugador esta en uno de los cuatro bordes de la pantalla
[[nodiscard]] auto isOnBorder() const -> bool { return is_on_border_; } // Indica si el jugador esta en uno de los cuatro bordes de la pantalla
[[nodiscard]] auto getBorder() const -> Room::Border { return border_; } // Indica en cual de los cuatro bordes se encuentra
void switchBorders(); // Cambia al jugador de un borde al opuesto. Util para el cambio de pantalla
auto getRect() -> SDL_FRect { return {x_, y_, WIDTH, HEIGHT}; } // Obtiene el rectangulo que delimita al jugador
@@ -137,8 +137,8 @@ class Player {
void handleInput(float delta_time); // Comprueba las entradas y modifica variables
// --- Funciones de gestión de estado ---
void handleState(float delta_time); // Comprueba el estado del jugador y actualiza variables
void setState(State value); // Cambia el estado del jugador
void handleState(float delta_time); // Comprueba el estado del jugador y actualiza variables
void transitionToState(State value); // Cambia el estado del jugador
// --- Funciones de física ---
void applyGravity(float delta_time); // Aplica gravedad al jugador

View File

@@ -307,7 +307,7 @@ auto Game::changeRoom(const std::string& room_path) -> bool {
// Comprueba si el jugador esta en el borde de la pantalla
void Game::checkPlayerIsOnBorder() {
if (player_->getOnBorder()) {
if (player_->isOnBorder()) {
const std::string ROOM_NAME = room_->getRoom(player_->getBorder());
if (changeRoom(ROOM_NAME)) {
player_->switchBorders();

View File

@@ -54,17 +54,17 @@ class Logo {
float state_time_ = 0.0F; // Tiempo acumulado en el estado actual
// --- Funciones ---
void update(); // Actualiza las variables
void render(); // Dibuja en pantalla
static void handleEvents(); // Comprueba el manejador de eventos
static void handleInput(); // Comprueba las entradas
void updateJAILGAMES(float delta_time); // Gestiona el logo de JAILGAME (time-based)
void updateTextureColors(); // Gestiona el color de las texturas
void updateState(float delta_time); // Actualiza el estado actual
void transitionToState(State new_state); // Transiciona a un nuevo estado
[[nodiscard]] auto getColorIndex(float progress) const -> int; // Calcula el índice de color según el progreso (0.0-1.0)
void update(); // Actualiza las variables
void render(); // Dibuja en pantalla
static void handleEvents(); // Comprueba el manejador de eventos
static void handleInput(); // Comprueba las entradas
void updateJAILGAMES(float delta_time); // Gestiona el logo de JAILGAME (time-based)
void updateTextureColors(); // Gestiona el color de las texturas
void updateState(float delta_time); // Actualiza el estado actual
void transitionToState(State new_state); // Transiciona a un nuevo estado
[[nodiscard]] auto getColorIndex(float progress) const -> int; // Calcula el índice de color según el progreso (0.0-1.0)
[[nodiscard]] auto allJailgamesLinesInPosition() const -> bool; // Verifica si todas las líneas están en su posición destino
static void endSection(); // Termina la sección
void initColors(); // Inicializa el vector de colores
void initSprites(); // Crea los sprites de cada linea
static void endSection(); // Termina la sección
void initColors(); // Inicializa el vector de colores
void initSprites(); // Crea los sprites de cada linea
};