forked from jaildesigner-jailgames/jaildoctors_dilemma
linter
This commit is contained in:
@@ -55,14 +55,14 @@ void Player::update(float delta_time) {
|
||||
// Comprueba las entradas y modifica variables
|
||||
void Player::handleInput() {
|
||||
if (Input::get()->checkAction(InputAction::LEFT)) {
|
||||
wannaGo = Direction::LEFT;
|
||||
wanna_go_ = Direction::LEFT;
|
||||
} else if (Input::get()->checkAction(InputAction::RIGHT)) {
|
||||
wannaGo = Direction::RIGHT;
|
||||
wanna_go_ = Direction::RIGHT;
|
||||
} else {
|
||||
wannaGo = Direction::NONE;
|
||||
wanna_go_ = Direction::NONE;
|
||||
}
|
||||
|
||||
wannaJump = Input::get()->checkAction(InputAction::JUMP);
|
||||
wanna_jump_ = Input::get()->checkAction(InputAction::JUMP);
|
||||
}
|
||||
|
||||
// La lógica de movimiento está distribuida en move
|
||||
@@ -89,7 +89,7 @@ void Player::move(float delta_time) {
|
||||
}
|
||||
|
||||
void Player::handleConveyorBelts() {
|
||||
if (!auto_movement_ and isOnConveyorBelt() and wannaGo == Direction::NONE) {
|
||||
if (!auto_movement_ and isOnConveyorBelt() and wanna_go_ == Direction::NONE) {
|
||||
auto_movement_ = true;
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ void Player::updateOnGround(float delta_time) {
|
||||
handleShouldFall(); // Verifica si debe caer (no tiene suelo)
|
||||
|
||||
// Verifica si el jugador quiere saltar
|
||||
if (wannaJump) { transitionToState(State::JUMPING); }
|
||||
if (wanna_jump_) { transitionToState(State::JUMPING); }
|
||||
}
|
||||
|
||||
// Actualización lógica del estado ON_SLOPE
|
||||
@@ -182,7 +182,7 @@ void Player::updateOnSlope(float delta_time) {
|
||||
// todas las condiciones de salida de la rampa (out of bounds, transición a superficie plana)
|
||||
|
||||
// Verifica si el jugador quiere saltar
|
||||
if (wannaJump) { transitionToState(State::JUMPING); }
|
||||
if (wanna_jump_) { transitionToState(State::JUMPING); }
|
||||
}
|
||||
|
||||
// Actualización lógica del estado JUMPING
|
||||
@@ -200,7 +200,7 @@ void Player::updateFalling(float delta_time) {
|
||||
|
||||
// Movimiento físico del estado ON_GROUND
|
||||
void Player::moveOnGround(float delta_time) {
|
||||
// Determinama cuál debe ser la velocidad a partir de automovement o de wannaGo
|
||||
// Determinama cuál debe ser la velocidad a partir de automovement o de wanna_go_
|
||||
updateVelocity();
|
||||
|
||||
if (vx_ == 0.0F) { return; }
|
||||
@@ -229,7 +229,7 @@ void Player::moveOnGround(float delta_time) {
|
||||
|
||||
// Movimiento físico del estado ON_SLOPE
|
||||
void Player::moveOnSlope(float delta_time) {
|
||||
// Determinama cuál debe ser la velocidad a partir de automovement o de wannaGo
|
||||
// Determinama cuál debe ser la velocidad a partir de automovement o de wanna_go_
|
||||
updateVelocity();
|
||||
|
||||
if (vx_ == 0.0F) { return; }
|
||||
@@ -636,35 +636,35 @@ void Player::initSounds() {
|
||||
|
||||
// Implementación de JumpSoundController::start
|
||||
void Player::JumpSoundController::start() {
|
||||
current_index_ = 0;
|
||||
elapsed_time_ = 0.0F;
|
||||
active_ = true;
|
||||
current_index = 0;
|
||||
elapsed_time = 0.0F;
|
||||
active = true;
|
||||
}
|
||||
|
||||
// Implementación de JumpSoundController::reset
|
||||
void Player::JumpSoundController::reset() {
|
||||
active_ = false;
|
||||
current_index_ = 0;
|
||||
elapsed_time_ = 0.0F;
|
||||
active = false;
|
||||
current_index = 0;
|
||||
elapsed_time = 0.0F;
|
||||
}
|
||||
|
||||
// Implementación de JumpSoundController::shouldPlay
|
||||
auto Player::JumpSoundController::shouldPlay(float delta_time, size_t& out_index) -> bool {
|
||||
if (!active_) {
|
||||
if (!active) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Acumula el tiempo transcurrido durante el salto
|
||||
elapsed_time_ += delta_time;
|
||||
elapsed_time += delta_time;
|
||||
|
||||
// Calcula qué sonido debería estar sonando según el tiempo
|
||||
size_t target_index = FIRST_SOUND + static_cast<size_t>(elapsed_time_ / SECONDS_PER_SOUND);
|
||||
size_t target_index = FIRST_SOUND + static_cast<size_t>(elapsed_time / SECONDS_PER_SOUND);
|
||||
target_index = std::min(target_index, LAST_SOUND);
|
||||
|
||||
// Reproduce si hemos avanzado a un nuevo sonido
|
||||
if (target_index > current_index_) {
|
||||
current_index_ = target_index;
|
||||
out_index = current_index_;
|
||||
if (target_index > current_index) {
|
||||
current_index = target_index;
|
||||
out_index = current_index;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -673,42 +673,42 @@ auto Player::JumpSoundController::shouldPlay(float delta_time, size_t& out_index
|
||||
|
||||
// Implementación de FallSoundController::start
|
||||
void Player::FallSoundController::start(float start_y) {
|
||||
current_index_ = 0;
|
||||
distance_traveled_ = 0.0F;
|
||||
last_y_ = start_y;
|
||||
active_ = true;
|
||||
current_index = 0;
|
||||
distance_traveled = 0.0F;
|
||||
last_y = start_y;
|
||||
active = true;
|
||||
}
|
||||
|
||||
// Implementación de FallSoundController::reset
|
||||
void Player::FallSoundController::reset() {
|
||||
active_ = false;
|
||||
current_index_ = 0;
|
||||
distance_traveled_ = 0.0F;
|
||||
active = false;
|
||||
current_index = 0;
|
||||
distance_traveled = 0.0F;
|
||||
}
|
||||
|
||||
// Implementación de FallSoundController::shouldPlay
|
||||
auto Player::FallSoundController::shouldPlay(float delta_time, float current_y, size_t& out_index) -> bool {
|
||||
(void)delta_time; // No usado actualmente, pero recibido por consistencia
|
||||
|
||||
if (!active_) {
|
||||
if (!active) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Acumula la distancia recorrida (solo hacia abajo)
|
||||
if (current_y > last_y_) {
|
||||
distance_traveled_ += (current_y - last_y_);
|
||||
if (current_y > last_y) {
|
||||
distance_traveled += (current_y - last_y);
|
||||
}
|
||||
last_y_ = current_y;
|
||||
last_y = current_y;
|
||||
|
||||
// Calcula qué sonido debería estar sonando según el intervalo
|
||||
size_t target_index = FIRST_SOUND + static_cast<size_t>(distance_traveled_ / PIXELS_PER_SOUND);
|
||||
size_t target_index = FIRST_SOUND + static_cast<size_t>(distance_traveled / PIXELS_PER_SOUND);
|
||||
|
||||
// El sonido a reproducir se limita a LAST_SOUND (13), pero el índice interno sigue creciendo
|
||||
size_t sound_to_play = std::min(target_index, LAST_SOUND);
|
||||
|
||||
// Reproduce si hemos avanzado a un nuevo índice (permite repetición de sonido 13)
|
||||
if (target_index > current_index_) {
|
||||
current_index_ = target_index; // Guardamos el índice real (puede ser > LAST_SOUND)
|
||||
if (target_index > current_index) {
|
||||
current_index = target_index; // Guardamos el índice real (puede ser > LAST_SOUND)
|
||||
out_index = sound_to_play; // Pero reproducimos LAST_SOUND cuando corresponde
|
||||
return true;
|
||||
}
|
||||
@@ -768,7 +768,7 @@ void Player::updateVelocity() {
|
||||
sprite_->setFlip(vx_ < 0.0F ? Flip::LEFT : Flip::RIGHT);
|
||||
} else {
|
||||
// El jugador tiene el control
|
||||
switch (wannaGo) {
|
||||
switch (wanna_go_) {
|
||||
case Direction::LEFT:
|
||||
vx_ = -HORIZONTAL_VELOCITY;
|
||||
sprite_->setFlip(Flip::LEFT);
|
||||
|
||||
@@ -61,13 +61,13 @@ class Player {
|
||||
static constexpr size_t LAST_SOUND = 17; // Último sonido a reproducir (índice 17)
|
||||
static constexpr float SECONDS_PER_SOUND = JUMP_DURATION / (LAST_SOUND - FIRST_SOUND + 1);
|
||||
|
||||
size_t current_index_ = 0; // Índice del sonido actual
|
||||
float elapsed_time_ = 0.0F; // Tiempo transcurrido durante el salto
|
||||
bool active_ = false; // Indica si el controlador está activo
|
||||
size_t current_index = 0; // Índice del sonido actual
|
||||
float elapsed_time = 0.0F; // Tiempo transcurrido durante el salto
|
||||
bool active = false; // Indica si el controlador está activo
|
||||
|
||||
void start(); // Inicia el controlador
|
||||
void reset(); // Resetea el controlador
|
||||
bool shouldPlay(float delta_time, size_t& out_index); // Comprueba si debe reproducir un sonido
|
||||
auto shouldPlay(float delta_time, size_t& out_index) -> bool; // Comprueba si debe reproducir un sonido
|
||||
};
|
||||
|
||||
struct FallSoundController {
|
||||
@@ -75,14 +75,14 @@ class Player {
|
||||
static constexpr size_t FIRST_SOUND = 1; // Primer sonido a reproducir (índice 1)
|
||||
static constexpr size_t LAST_SOUND = 13; // Último sonido a reproducir (índice 13)
|
||||
|
||||
size_t current_index_ = 0; // Índice del sonido actual
|
||||
float distance_traveled_ = 0.0F; // Distancia acumulada durante la caída
|
||||
float last_y_ = 0.0F; // Última posición Y registrada
|
||||
bool active_ = false; // Indica si el controlador está activo
|
||||
size_t current_index = 0; // Índice del sonido actual
|
||||
float distance_traveled = 0.0F; // Distancia acumulada durante la caída
|
||||
float last_y = 0.0F; // Última posición Y registrada
|
||||
bool active = false; // Indica si el controlador está activo
|
||||
|
||||
void start(float start_y); // Inicia el controlador
|
||||
void reset(); // Resetea el controlador
|
||||
bool shouldPlay(float delta_time, float current_y, size_t& out_index); // Comprueba si debe reproducir un sonido
|
||||
auto shouldPlay(float delta_time, float current_y, size_t& out_index) -> bool; // Comprueba si debe reproducir un sonido
|
||||
};
|
||||
|
||||
// --- Constructor y Destructor ---
|
||||
@@ -97,7 +97,7 @@ class Player {
|
||||
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
|
||||
auto getCollider() -> SDL_FRect& { return collider_box_; } // Obtiene el rectangulo de colision del jugador
|
||||
auto getSpawnParams() -> SpawnData { return {x_, y_, vx_, vy_, last_grounded_position_, state_, sprite_->getFlip()}; } // Obtiene el estado de reaparición del jugador
|
||||
auto getSpawnParams() -> SpawnData { return {.x = x_, .y = y_, .vx = vx_, .vy = vy_, .last_grounded_position = last_grounded_position_, .state = state_, .flip = sprite_->getFlip()}; } // Obtiene el estado de reaparición del jugador
|
||||
void setColor(); // Establece el color del jugador
|
||||
void setRoom(std::shared_ptr<Room> room) { room_ = std::move(room); } // Establece la habitación en la que se encuentra el jugador
|
||||
[[nodiscard]] auto isAlive() const -> bool { return is_alive_; } // Comprueba si el jugador esta vivo
|
||||
@@ -120,8 +120,8 @@ class Player {
|
||||
float vx_ = 0.0F; // Velocidad/desplazamiento del jugador en el eje X
|
||||
float vy_ = 0.0F; // Velocidad/desplazamiento del jugador en el eje Y
|
||||
|
||||
Direction wannaGo = Direction::NONE;
|
||||
bool wannaJump = false;
|
||||
Direction wanna_go_ = Direction::NONE;
|
||||
bool wanna_jump_ = false;
|
||||
|
||||
// --- Variables de estado ---
|
||||
State state_ = State::ON_GROUND; // Estado en el que se encuentra el jugador. Util apara saber si está saltando o cayendo
|
||||
|
||||
Reference in New Issue
Block a user