migrat Input a la ultima versió

cohesionats tots els metodes update de les escenes
This commit is contained in:
2025-11-01 22:28:51 +01:00
parent 1dd750ba0c
commit 824e7417ad
58 changed files with 26926 additions and 978 deletions

View File

@@ -56,12 +56,12 @@ void Player::checkInput(float delta_time) {
if (!auto_movement_) {
// Comprueba las entradas de desplazamiento lateral solo en el caso de no estar enganchado a una superficie automatica
if (Input::get()->checkInput(InputAction::LEFT)) {
if (Input::get()->checkAction(InputAction::LEFT)) {
vx_ = -HORIZONTAL_VELOCITY;
sprite_->setFlip(SDL_FLIP_HORIZONTAL);
}
else if (Input::get()->checkInput(InputAction::RIGHT)) {
else if (Input::get()->checkAction(InputAction::RIGHT)) {
vx_ = HORIZONTAL_VELOCITY;
sprite_->setFlip(SDL_FLIP_NONE);
}
@@ -84,7 +84,7 @@ void Player::checkInput(float delta_time) {
}
}
if (Input::get()->checkInput(InputAction::JUMP)) {
if (Input::get()->checkAction(InputAction::JUMP)) {
// Solo puede saltar si ademas de estar (state == STANDING)
// Esta sobre el suelo, rampa o suelo que se mueve
// Esto es para evitar el salto desde el vacio al cambiar de pantalla verticalmente
@@ -132,16 +132,14 @@ void Player::checkState(float delta_time) {
// Reproduce sonidos según el estado
if (state_ == State::FALLING) {
playFallSound();
}
else if (state_ == State::STANDING) {
} else if (state_ == State::STANDING) {
// 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
setState(State::FALLING); // setState() establece vx_=0, vy_=MAX_VY
playFallSound();
}
}
else if (state_ == State::JUMPING) {
} else if (state_ == State::JUMPING) {
playJumpSound();
}
}
@@ -208,8 +206,7 @@ void Player::handleSlopeMovement(int direction) {
const LineVertical SIDE = {
.x = SIDE_X,
.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
const int SLOPE_Y = direction < 0 ? room_->checkLeftSlopes(&SIDE) : room_->checkRightSlopes(&SIDE);
@@ -233,16 +230,14 @@ void Player::moveHorizontal(float delta_time, int direction) {
.x = x_ + DISPLACEMENT,
.y = y_,
.w = std::ceil(std::fabs(DISPLACEMENT)),
.h = HEIGHT
};
.h = HEIGHT};
} else {
// Movimiento a la derecha
proj = {
.x = x_ + WIDTH,
.y = y_,
.w = std::ceil(DISPLACEMENT),
.h = HEIGHT
};
.h = HEIGHT};
}
// Comprueba la colisión con las superficies
@@ -351,14 +346,14 @@ void Player::moveVerticalDown(float delta_time) {
// Orquesta el movimiento del jugador
void Player::move(float delta_time) {
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
// Movimiento horizontal
if (vx_ < 0.0F) {
moveHorizontal(delta_time, -1); // Izquierda
} else if (vx_ > 0.0F) {
moveHorizontal(delta_time, 1); // Derecha
moveHorizontal(delta_time, 1); // Derecha
}
// Si ha salido del suelo, el jugador cae
@@ -623,7 +618,7 @@ void Player::initSprite(const std::string& animations_path) {
// Actualiza collider_box y collision points
void Player::updateColliderGeometry() {
placeSprite(); // Coloca el sprite en la posición del jugador
placeSprite(); // Coloca el sprite en la posición del jugador
collider_box_ = getRect(); // Actualiza el rectangulo de colisión
updateColliderPoints(); // Actualiza los puntos de colisión
}