clang-tidy readability-function-cognitive-complexity
clang-format
This commit is contained in:
@@ -13,7 +13,6 @@ Bullet::Bullet(float x, float y, BulletType bullet_type, bool powered, int owner
|
||||
pos_y_(y),
|
||||
bullet_type_(bullet_type),
|
||||
owner_(owner) {
|
||||
|
||||
vel_x_ = calculateVelocity(bullet_type_);
|
||||
sprite_->setCurrentAnimation(buildAnimationString(bullet_type_, powered));
|
||||
|
||||
@@ -22,7 +21,7 @@ Bullet::Bullet(float x, float y, BulletType bullet_type, bool powered, int owner
|
||||
}
|
||||
|
||||
// Calcula la velocidad horizontal de la bala basada en su tipo
|
||||
float Bullet::calculateVelocity(BulletType bullet_type) {
|
||||
auto Bullet::calculateVelocity(BulletType bullet_type) -> float {
|
||||
switch (bullet_type) {
|
||||
case BulletType::LEFT:
|
||||
return VEL_X_LEFT;
|
||||
@@ -34,7 +33,7 @@ float Bullet::calculateVelocity(BulletType bullet_type) {
|
||||
}
|
||||
|
||||
// Construye el string de animación basado en el tipo de bala y si está potenciada
|
||||
std::string Bullet::buildAnimationString(BulletType bullet_type, bool powered) {
|
||||
auto Bullet::buildAnimationString(BulletType bullet_type, bool powered) -> std::string {
|
||||
std::string animation_string = powered ? "powered_" : "normal_";
|
||||
|
||||
switch (bullet_type) {
|
||||
|
||||
@@ -66,6 +66,6 @@ class Bullet {
|
||||
void shiftColliders(); // Ajusta el círculo de colisión
|
||||
void shiftSprite(); // Ajusta el sprite
|
||||
auto move() -> BulletMoveStatus; // Mueve la bala y devuelve su estado
|
||||
float calculateVelocity(BulletType bullet_type); // Calcula la velocidad horizontal de la bala basada en su tipo
|
||||
std::string buildAnimationString(BulletType bullet_type, bool powered); // Construye el string de animación basado en el tipo de bala y si está potenciada
|
||||
static auto calculateVelocity(BulletType bullet_type) -> float; // Calcula la velocidad horizontal de la bala basada en su tipo
|
||||
static auto buildAnimationString(BulletType bullet_type, bool powered) -> std::string; // Construye el string de animación basado en el tipo de bala y si está potenciada
|
||||
};
|
||||
|
||||
@@ -588,7 +588,7 @@ void Director::reset() {
|
||||
Lang::setLanguage(Options::settings.language);
|
||||
Audio::get()->stopMusic();
|
||||
Audio::get()->stopAllSounds();
|
||||
if (true) {
|
||||
{
|
||||
Resource::get()->reload();
|
||||
}
|
||||
Input::get()->discoverGameControllers();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string> // Para manejar cadenas de texto
|
||||
#include <span>
|
||||
#include <string> // Para manejar cadenas de texto
|
||||
|
||||
namespace Lang {
|
||||
enum class Code : int;
|
||||
@@ -23,7 +23,7 @@ private:
|
||||
|
||||
// --- Inicialización y cierre del sistema ---
|
||||
void init(); // Inicializa la aplicación
|
||||
void close(); // Cierra y libera recursos
|
||||
static void close(); // Cierra y libera recursos
|
||||
|
||||
// --- Configuración inicial ---
|
||||
static void loadParams(); // Carga los parámetros del programa
|
||||
@@ -44,7 +44,7 @@ private:
|
||||
static void runCredits(); // Muestra los créditos del juego
|
||||
static void runHiScoreTable(); // Muestra la tabla de puntuaciones
|
||||
static void runDemoGame(); // Ejecuta el modo demo
|
||||
void reset(); // Reinicia objetos y vuelve a la sección inicial
|
||||
static void reset(); // Reinicia objetos y vuelve a la sección inicial
|
||||
|
||||
// --- Gestión de archivos de idioma ---
|
||||
auto getLangFile(Lang::Code code) -> std::string; // Obtiene un fichero de idioma según el código
|
||||
|
||||
2
source/external/.clang-format
vendored
Normal file
2
source/external/.clang-format
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
DisableFormat: true
|
||||
SortIncludes: Never
|
||||
@@ -184,12 +184,12 @@ auto Item::getCoffeeMachineSpawn(int player_x, int item_width, int area_width, i
|
||||
return rand() % (exclude_left - LEFT_BOUND) + LEFT_BOUND;
|
||||
} // Lado derecho
|
||||
return rand() % (RIGHT_BOUND - exclude_right) + exclude_right;
|
||||
|
||||
}
|
||||
if (can_spawn_left) {
|
||||
// Solo lado izquierdo disponible
|
||||
return rand() % (exclude_left - LEFT_BOUND) + LEFT_BOUND;
|
||||
} else if (can_spawn_right) {
|
||||
}
|
||||
if (can_spawn_right) {
|
||||
// Solo lado derecho disponible
|
||||
return rand() % (RIGHT_BOUND - exclude_right) + exclude_right;
|
||||
} else {
|
||||
|
||||
@@ -56,12 +56,9 @@ void Notifier::update() {
|
||||
clearFinishedNotifications();
|
||||
}
|
||||
|
||||
bool Notifier::shouldProcessNotification(int index) const {
|
||||
auto Notifier::shouldProcessNotification(int index) const -> bool {
|
||||
// Si la notificación anterior está "saliendo", no hagas nada
|
||||
if (index > 0 && notifications_[index - 1].state == NotificationStatus::RISING) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !(index > 0 && notifications_[index - 1].state == NotificationStatus::RISING);
|
||||
}
|
||||
|
||||
void Notifier::processNotification(int index) {
|
||||
@@ -103,11 +100,11 @@ void Notifier::updateNotificationState(int index) {
|
||||
void Notifier::handleRisingState(int index) {
|
||||
auto& notification = notifications_[index];
|
||||
|
||||
const float step = (float)notification.counter / notification.travel_dist;
|
||||
const int alpha = 255 * step;
|
||||
const float STEP = (float)notification.counter / notification.travel_dist;
|
||||
const int ALPHA = 255 * STEP;
|
||||
|
||||
moveNotificationVertically(notification, param.notification.pos_v == NotifyPosition::TOP ? 1 : -1);
|
||||
notification.texture->setAlpha(alpha);
|
||||
notification.texture->setAlpha(ALPHA);
|
||||
|
||||
if (notification.rect.y == notification.y) {
|
||||
transitionToStayState(index);
|
||||
@@ -126,11 +123,11 @@ void Notifier::handleStayState(int index) {
|
||||
void Notifier::handleVanishingState(int index) {
|
||||
auto& notification = notifications_[index];
|
||||
|
||||
const float step = notification.counter / (float)notification.travel_dist;
|
||||
const int alpha = 255 * (1 - step);
|
||||
const float STEP = notification.counter / (float)notification.travel_dist;
|
||||
const int ALPHA = 255 * (1 - STEP);
|
||||
|
||||
moveNotificationVertically(notification, param.notification.pos_v == NotifyPosition::TOP ? -1 : 1);
|
||||
notification.texture->setAlpha(alpha);
|
||||
notification.texture->setAlpha(ALPHA);
|
||||
|
||||
if (notification.rect.y == notification.y - notification.travel_dist) {
|
||||
notification.state = NotificationStatus::FINISHED;
|
||||
|
||||
@@ -77,14 +77,14 @@ class Notifier {
|
||||
// --- Métodos internos ---
|
||||
void clearFinishedNotifications(); // Elimina las notificaciones cuyo estado es FINISHED
|
||||
void clearAllNotifications(); // Elimina todas las notificaciones activas, sin importar el estado
|
||||
bool shouldProcessNotification(int index) const; // Determina si una notificación debe ser procesada (según su estado y posición)
|
||||
[[nodiscard]] auto shouldProcessNotification(int index) const -> bool; // Determina si una notificación debe ser procesada (según su estado y posición)
|
||||
void processNotification(int index); // Procesa una notificación en la posición dada: actualiza su estado y comportamiento visual
|
||||
void playNotificationSoundIfNeeded(const Notification ¬ification); // Reproduce sonido asociado si es necesario (dependiendo del estado o contenido)
|
||||
static void playNotificationSoundIfNeeded(const Notification ¬ification); // Reproduce sonido asociado si es necesario (dependiendo del estado o contenido)
|
||||
void updateNotificationState(int index); // Actualiza el estado interno de una notificación (ej. de RISING a STAY)
|
||||
void handleRisingState(int index); // Lógica de animación para el estado RISING (apareciendo)
|
||||
void handleStayState(int index); // Lógica para mantener una notificación visible en el estado STAY
|
||||
void handleVanishingState(int index); // Lógica de animación para el estado VANISHING (desapareciendo)
|
||||
void moveNotificationVertically(Notification ¬ification, int direction); // Mueve verticalmente una notificación en una dirección dada (útil para animación en apilamiento)
|
||||
static void moveNotificationVertically(Notification ¬ification, int direction); // Mueve verticalmente una notificación en una dirección dada (útil para animación en apilamiento)
|
||||
void transitionToStayState(int index); // Cambia el estado de una notificación de RISING a STAY cuando ha alcanzado su posición final
|
||||
|
||||
// --- Constructor y destructor ---
|
||||
|
||||
@@ -131,7 +131,7 @@ void loadParamsFromFile(const std::string& file_path) {
|
||||
}
|
||||
|
||||
auto setParams(const std::string& var, const std::string& value) -> bool {
|
||||
static const std::unordered_map<std::string, std::function<void(const std::string&)>> intParams = {
|
||||
static const std::unordered_map<std::string, std::function<void(const std::string&)>> INT_PARAMS = {
|
||||
{"game.width", [](const std::string& v) { param.game.width = std::stoi(v); }},
|
||||
{"game.height", [](const std::string& v) { param.game.height = std::stoi(v); }},
|
||||
{"game.item_size", [](const std::string& v) { param.game.item_size = std::stoi(v); }},
|
||||
@@ -159,7 +159,7 @@ auto setParams(const std::string& var, const std::string& value) -> bool {
|
||||
{"title.title_c_c_position", [](const std::string& v) { param.title.title_c_c_position = std::stoi(v); }},
|
||||
{"intro.text_distance_from_bottom", [](const std::string& v) { param.intro.text_distance_from_bottom = std::stoi(v); }}};
|
||||
|
||||
static const std::unordered_map<std::string, std::function<void(const std::string&)>> colorParams = {
|
||||
static const std::unordered_map<std::string, std::function<void(const std::string&)>> COLOR_PARAMS = {
|
||||
{"fade.color", [](const std::string& v) { param.fade.color = Color::fromHex(v); }},
|
||||
{"scoreboard.separator_color", [](const std::string& v) { param.scoreboard.separator_color = Color::fromHex(v); }},
|
||||
{"scoreboard.easy_color", [](const std::string& v) { param.scoreboard.easy_color = Color::fromHex(v); }},
|
||||
@@ -180,7 +180,7 @@ auto setParams(const std::string& var, const std::string& value) -> bool {
|
||||
{"debug.color", [](const std::string& v) { param.debug.color = Color::fromHex(v); }},
|
||||
{"resource.color", [](const std::string& v) { param.resource.color = Color::fromHex(v); }}};
|
||||
|
||||
static const std::unordered_map<std::string, std::function<void(const std::string&)>> boolParams = {
|
||||
static const std::unordered_map<std::string, std::function<void(const std::string&)>> BOOL_PARAMS = {
|
||||
{"game.hit_stop", [](const std::string& v) { param.game.hit_stop = stringToBool(v); }},
|
||||
{"scoreboard.separator_autocolor", [](const std::string& v) { param.scoreboard.separator_autocolor = stringToBool(v); }},
|
||||
{"scoreboard.text_autocolor", [](const std::string& v) { param.scoreboard.text_autocolor = stringToBool(v); }},
|
||||
@@ -188,7 +188,7 @@ auto setParams(const std::string& var, const std::string& value) -> bool {
|
||||
{"notification.sound", [](const std::string& v) { param.notification.sound = stringToBool(v); }},
|
||||
{"service_menu.drop_shadow", [](const std::string& v) { param.service_menu.drop_shadow = stringToBool(v); }}};
|
||||
|
||||
static const std::unordered_map<std::string, std::function<void(const std::string&)>> floatParams = {
|
||||
static const std::unordered_map<std::string, std::function<void(const std::string&)>> FLOAT_PARAMS = {
|
||||
{"balloon.settings[0].vel", [](const std::string& v) { param.balloon.settings.at(0).vel = std::stof(v); }},
|
||||
{"balloon.settings[0].grav", [](const std::string& v) { param.balloon.settings.at(0).grav = std::stof(v); }},
|
||||
{"balloon.settings[1].vel", [](const std::string& v) { param.balloon.settings.at(1).vel = std::stof(v); }},
|
||||
@@ -198,24 +198,24 @@ auto setParams(const std::string& var, const std::string& value) -> bool {
|
||||
{"balloon.settings[3].vel", [](const std::string& v) { param.balloon.settings.at(3).vel = std::stof(v); }},
|
||||
{"balloon.settings[3].grav", [](const std::string& v) { param.balloon.settings.at(3).grav = std::stof(v); }}};
|
||||
|
||||
static const std::unordered_map<std::string, std::function<void(const std::string&)>> stringParams = {
|
||||
static const std::unordered_map<std::string, std::function<void(const std::string&)>> STRING_PARAMS = {
|
||||
{"balloon.color[0]", [](const std::string& v) { param.balloon.color.at(0) = v; }},
|
||||
{"balloon.color[1]", [](const std::string& v) { param.balloon.color.at(1) = v; }},
|
||||
{"balloon.color[2]", [](const std::string& v) { param.balloon.color.at(2) = v; }},
|
||||
{"balloon.color[3]", [](const std::string& v) { param.balloon.color.at(3) = v; }}};
|
||||
|
||||
// Intentar cada mapa de parámetros
|
||||
auto tryMap = [&](const auto& paramMap) -> bool {
|
||||
auto it = paramMap.find(var);
|
||||
if (it != paramMap.end()) {
|
||||
auto try_map = [&](const auto& param_map) -> bool {
|
||||
auto it = param_map.find(var);
|
||||
if (it != param_map.end()) {
|
||||
it->second(value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
if (tryMap(intParams) || tryMap(colorParams) || tryMap(boolParams) ||
|
||||
tryMap(floatParams) || tryMap(stringParams)) {
|
||||
if (try_map(INT_PARAMS) || try_map(COLOR_PARAMS) || try_map(BOOL_PARAMS) ||
|
||||
try_map(FLOAT_PARAMS) || try_map(STRING_PARAMS)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +147,33 @@ void Player::setInputEnteringName(InputAction input) {
|
||||
// Mueve el jugador a la posición y animación que le corresponde
|
||||
void Player::move() {
|
||||
switch (playing_state_) {
|
||||
case PlayerState::PLAYING: {
|
||||
case PlayerState::PLAYING:
|
||||
handlePlayingMovement();
|
||||
break;
|
||||
case PlayerState::ROLLING:
|
||||
handleRollingMovement();
|
||||
break;
|
||||
case PlayerState::TITLE_ANIMATION:
|
||||
handleTitleAnimation();
|
||||
break;
|
||||
case PlayerState::CONTINUE_TIME_OUT:
|
||||
handleContinueTimeOut();
|
||||
break;
|
||||
case PlayerState::LEAVING_SCREEN:
|
||||
handleLeavingScreen();
|
||||
break;
|
||||
case PlayerState::ENTERING_SCREEN:
|
||||
handleEnteringScreen();
|
||||
break;
|
||||
case PlayerState::CREDITS:
|
||||
handleCreditsMovement();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::handlePlayingMovement() {
|
||||
// Mueve el jugador a derecha o izquierda
|
||||
pos_x_ += vel_x_;
|
||||
|
||||
@@ -157,67 +183,61 @@ void Player::move() {
|
||||
pos_x_ = std::clamp(pos_x_, MIN_X, MAX_X);
|
||||
|
||||
shiftSprite();
|
||||
break;
|
||||
}
|
||||
case PlayerState::ROLLING: {
|
||||
// Si el jugador abandona el area de juego por los laterales lo hace rebotar
|
||||
|
||||
void Player::handleRollingMovement() {
|
||||
handleRollingBoundaryCollision();
|
||||
handleRollingGroundCollision();
|
||||
}
|
||||
|
||||
void Player::handleRollingBoundaryCollision() {
|
||||
const int X = player_sprite_->getPosX();
|
||||
const int MIN_X = play_area_.x;
|
||||
const int MAX_X = play_area_.x + play_area_.w - WIDTH;
|
||||
|
||||
if ((X < MIN_X) || (X > MAX_X)) {
|
||||
player_sprite_->setPosX(std::clamp(X, MIN_X, MAX_X));
|
||||
player_sprite_->setVelX(-player_sprite_->getVelX());
|
||||
playSound("jump.wav");
|
||||
}
|
||||
}
|
||||
|
||||
void Player::handleRollingGroundCollision() {
|
||||
if (player_sprite_->getPosY() <= play_area_.h - HEIGHT) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Si el jugador toca el suelo rebota y si tiene poca velocidad, se detiene y cambia de estado
|
||||
if (player_sprite_->getPosY() > play_area_.h - HEIGHT) {
|
||||
if (player_sprite_->getVelY() < 2.0F) {
|
||||
// Si la velocidad de rebote es baja, lo detiene y cambia de estado
|
||||
handleRollingStop();
|
||||
} else {
|
||||
handleRollingBounce();
|
||||
}
|
||||
}
|
||||
|
||||
void Player::handleRollingStop() {
|
||||
const auto NEXT_PLAYER_STATUS = isEligibleForHighScore() ? PlayerState::ENTERING_NAME : PlayerState::CONTINUE;
|
||||
demo_ ? setPlayingState(PlayerState::LYING_ON_THE_FLOOR_FOREVER) : setPlayingState(NEXT_PLAYER_STATUS);
|
||||
|
||||
const auto NEXT_STATE = demo_ ? PlayerState::LYING_ON_THE_FLOOR_FOREVER : NEXT_PLAYER_STATUS;
|
||||
|
||||
setPlayingState(NEXT_STATE);
|
||||
pos_x_ = player_sprite_->getPosX();
|
||||
pos_y_ = default_pos_y_;
|
||||
player_sprite_->clear();
|
||||
shiftSprite();
|
||||
playSound("jump.wav");
|
||||
} else {
|
||||
// Decrementa las velocidades de rebote
|
||||
}
|
||||
|
||||
void Player::handleRollingBounce() {
|
||||
player_sprite_->setPosY(play_area_.h - HEIGHT);
|
||||
player_sprite_->setVelY(player_sprite_->getVelY() * -0.5F);
|
||||
player_sprite_->setVelX(player_sprite_->getVelX() * 0.75F);
|
||||
player_sprite_->setAnimationSpeed(player_sprite_->getAnimationSpeed() * 2);
|
||||
playSound("jump.wav");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerState::TITLE_ANIMATION: {
|
||||
// Si el jugador abandona el area de juego por los laterales lo detiene
|
||||
/*const int X = player_sprite_->getPosX();
|
||||
const int MIN_X = play_area_.x - WIDTH;
|
||||
const int MAX_X = play_area_.x + play_area_.w;
|
||||
if ((X < MIN_X) || (X > MAX_X))
|
||||
{
|
||||
setPlayingState(PlayerState::TITLE_HIDDEN);
|
||||
}
|
||||
|
||||
// Si el jugador toca el suelo rebota lo detiene
|
||||
if (player_sprite_->getPosY() > play_area_.h)
|
||||
{
|
||||
setPlayingState(PlayerState::TITLE_HIDDEN);
|
||||
}*/
|
||||
void Player::handleTitleAnimation() {
|
||||
setInputBasedOnPlayerId();
|
||||
|
||||
switch (id_) {
|
||||
case 1:
|
||||
setInputPlaying(InputAction::LEFT);
|
||||
break;
|
||||
case 2:
|
||||
setInputPlaying(InputAction::RIGHT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
pos_x_ += vel_x_ * 2.0F;
|
||||
const float MIN_X = -WIDTH;
|
||||
const float MAX_X = play_area_.w;
|
||||
@@ -227,31 +247,19 @@ void Player::move() {
|
||||
if (pos_x_ == MIN_X || pos_x_ == MAX_X) {
|
||||
setPlayingState(PlayerState::TITLE_HIDDEN);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerState::CONTINUE_TIME_OUT: {
|
||||
|
||||
void Player::handleContinueTimeOut() {
|
||||
// Si el cadaver desaparece por el suelo, cambia de estado
|
||||
if (player_sprite_->getPosY() > play_area_.h) {
|
||||
setPlayingState(PlayerState::WAITING);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerState::LEAVING_SCREEN: {
|
||||
++step_counter_;
|
||||
if (step_counter_ % 10 == 0) {
|
||||
playSound("walk.wav");
|
||||
}
|
||||
|
||||
switch (id_) {
|
||||
case 1:
|
||||
setInputPlaying(InputAction::LEFT);
|
||||
break;
|
||||
case 2:
|
||||
setInputPlaying(InputAction::RIGHT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
void Player::handleLeavingScreen() {
|
||||
updateStepCounter();
|
||||
setInputBasedOnPlayerId();
|
||||
|
||||
pos_x_ += vel_x_;
|
||||
const float MIN_X = -WIDTH;
|
||||
const float MAX_X = play_area_.w;
|
||||
@@ -261,16 +269,21 @@ void Player::move() {
|
||||
if (pos_x_ == MIN_X || pos_x_ == MAX_X) {
|
||||
setPlayingState(PlayerState::GAME_OVER);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerState::ENTERING_SCREEN: {
|
||||
++step_counter_;
|
||||
if (step_counter_ % 10 == 0) {
|
||||
playSound("walk.wav");
|
||||
}
|
||||
|
||||
switch (id_) {
|
||||
case 1:
|
||||
void Player::handleEnteringScreen() {
|
||||
updateStepCounter();
|
||||
|
||||
if (id_ == 1) {
|
||||
handlePlayer1Entering();
|
||||
} else if (id_ == 2) {
|
||||
handlePlayer2Entering();
|
||||
}
|
||||
|
||||
shiftSprite();
|
||||
}
|
||||
|
||||
void Player::handlePlayer1Entering() {
|
||||
setInputPlaying(InputAction::RIGHT);
|
||||
pos_x_ += vel_x_;
|
||||
if (pos_x_ > default_pos_x_) {
|
||||
@@ -278,8 +291,9 @@ void Player::move() {
|
||||
setPlayingState(PlayerState::PLAYING);
|
||||
setInvulnerable(false);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
}
|
||||
|
||||
void Player::handlePlayer2Entering() {
|
||||
setInputPlaying(InputAction::LEFT);
|
||||
pos_x_ += vel_x_;
|
||||
if (pos_x_ < default_pos_x_) {
|
||||
@@ -287,42 +301,63 @@ void Player::move() {
|
||||
setPlayingState(PlayerState::PLAYING);
|
||||
setInvulnerable(false);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
shiftSprite();
|
||||
break;
|
||||
}
|
||||
case PlayerState::CREDITS: {
|
||||
|
||||
void Player::handleCreditsMovement() {
|
||||
pos_x_ += vel_x_ / 2.0F;
|
||||
|
||||
if (vel_x_ > 0) {
|
||||
// setInputPlaying(InputAction::RIGHT);
|
||||
handleCreditsRightMovement();
|
||||
} else {
|
||||
handleCreditsLeftMovement();
|
||||
}
|
||||
|
||||
updateWalkingStateForCredits();
|
||||
shiftSprite();
|
||||
}
|
||||
|
||||
void Player::handleCreditsRightMovement() {
|
||||
if (pos_x_ > param.game.game_area.rect.w - WIDTH) {
|
||||
pos_x_ = param.game.game_area.rect.w - WIDTH;
|
||||
vel_x_ *= -1;
|
||||
}
|
||||
} else {
|
||||
// setInputPlaying(InputAction::LEFT);
|
||||
}
|
||||
|
||||
void Player::handleCreditsLeftMovement() {
|
||||
if (pos_x_ < param.game.game_area.rect.x) {
|
||||
pos_x_ = param.game.game_area.rect.x;
|
||||
vel_x_ *= -1;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::updateWalkingStateForCredits() {
|
||||
if (pos_x_ > param.game.game_area.center_x - WIDTH / 2) {
|
||||
setWalkingState(PlayerState::WALKING_LEFT);
|
||||
} else {
|
||||
setWalkingState(PlayerState::WALKING_RIGHT);
|
||||
}
|
||||
shiftSprite();
|
||||
break;
|
||||
}
|
||||
|
||||
void Player::setInputBasedOnPlayerId() {
|
||||
switch (id_) {
|
||||
case 1:
|
||||
setInputPlaying(InputAction::LEFT);
|
||||
break;
|
||||
case 2:
|
||||
setInputPlaying(InputAction::RIGHT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::updateStepCounter() {
|
||||
++step_counter_;
|
||||
if (step_counter_ % 10 == 0) {
|
||||
playSound("walk.wav");
|
||||
}
|
||||
}
|
||||
|
||||
// Pinta el jugador en pantalla
|
||||
void Player::render() {
|
||||
if (power_up_ && isPlaying()) {
|
||||
@@ -404,13 +439,54 @@ void Player::setAnimation() {
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updateCooldown() {
|
||||
if (playing_state_ == PlayerState::PLAYING) {
|
||||
if (playing_state_ != PlayerState::PLAYING) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cant_fire_counter_ > 0) {
|
||||
handleFiringCooldown();
|
||||
} else {
|
||||
handleRecoilAndCooling();
|
||||
}
|
||||
}
|
||||
|
||||
void Player::handleFiringCooldown() {
|
||||
cooling_state_counter_ = COOLING_DURATION;
|
||||
|
||||
// La mitad del tiempo que no puede disparar tiene el brazo arriba (PlayerState::FIRING)
|
||||
// y la otra mitad en retroceso (PlayerState::RECOILING)
|
||||
// Transition to recoiling state at halfway point
|
||||
if (cant_fire_counter_ == recoiling_state_duration_ / 2) {
|
||||
transitionToRecoiling();
|
||||
}
|
||||
|
||||
--cant_fire_counter_;
|
||||
if (cant_fire_counter_ == 0) {
|
||||
recoiling_state_counter_ = recoiling_state_duration_;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::handleRecoilAndCooling() {
|
||||
if (recoiling_state_counter_ > 0) {
|
||||
--recoiling_state_counter_;
|
||||
return;
|
||||
}
|
||||
|
||||
handleCoolingState();
|
||||
}
|
||||
|
||||
void Player::handleCoolingState() {
|
||||
if (cooling_state_counter_ > COOLING_COMPLETE) {
|
||||
if (cooling_state_counter_ == COOLING_DURATION) {
|
||||
transitionToCooling();
|
||||
}
|
||||
--cooling_state_counter_;
|
||||
}
|
||||
|
||||
if (cooling_state_counter_ == COOLING_COMPLETE) {
|
||||
completeCooling();
|
||||
}
|
||||
}
|
||||
|
||||
void Player::transitionToRecoiling() {
|
||||
switch (firing_state_) {
|
||||
case PlayerState::FIRING_LEFT:
|
||||
setFiringState(PlayerState::RECOILING_LEFT);
|
||||
@@ -426,16 +502,7 @@ void Player::updateCooldown() {
|
||||
}
|
||||
}
|
||||
|
||||
--cant_fire_counter_;
|
||||
if (cant_fire_counter_ == 0) {
|
||||
recoiling_state_counter_ = recoiling_state_duration_;
|
||||
}
|
||||
} else {
|
||||
if (recoiling_state_counter_ > 0) {
|
||||
--recoiling_state_counter_;
|
||||
} else {
|
||||
if (cooling_state_counter_ > COOLING_COMPLETE) {
|
||||
if (cooling_state_counter_ == COOLING_DURATION) {
|
||||
void Player::transitionToCooling() {
|
||||
switch (firing_state_) {
|
||||
case PlayerState::RECOILING_LEFT:
|
||||
setFiringState(PlayerState::COOLING_LEFT);
|
||||
@@ -451,17 +518,10 @@ void Player::updateCooldown() {
|
||||
}
|
||||
}
|
||||
|
||||
--cooling_state_counter_;
|
||||
}
|
||||
|
||||
if (cooling_state_counter_ == COOLING_COMPLETE) {
|
||||
void Player::completeCooling() {
|
||||
setFiringState(PlayerState::FIRING_NONE);
|
||||
cooling_state_counter_ = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza al jugador a su posicion, animación y controla los contadores
|
||||
void Player::update() {
|
||||
|
||||
@@ -228,4 +228,28 @@ class Player {
|
||||
void playSound(const std::string &name) const; // Hace sonar un sonido
|
||||
[[nodiscard]] auto isRenderable() const -> bool; // Indica si se puede dibujar el objeto
|
||||
void addScoreToScoreBoard() const; // Añade una puntuación a la tabla de records
|
||||
void handleFiringCooldown(); // Gestiona el tiempo de espera después de disparar antes de permitir otro disparo
|
||||
void handleRecoilAndCooling(); // Procesa simultáneamente el retroceso del arma y la transición al estado de enfriamiento si aplica
|
||||
void handleCoolingState(); // Actualiza la lógica interna mientras el sistema está en estado de enfriamiento
|
||||
void transitionToRecoiling(); // Cambia el estado actual al de retroceso después de disparar
|
||||
void transitionToCooling(); // Cambia el estado actual al de enfriamiento (por ejemplo, tras una ráfaga o sobrecalentamiento)
|
||||
void completeCooling(); // Finaliza el proceso de enfriamiento y restablece el estado listo para disparar
|
||||
void handlePlayingMovement(); // Gestiona el movimiento del personaje u objeto durante el estado de juego activo
|
||||
void handleRollingMovement(); // Actualiza la lógica de movimiento de "rodar" (posiblemente tras impacto o acción especial)
|
||||
void handleRollingBoundaryCollision(); // Detecta y maneja colisiones del objeto rodante con los límites de la pantalla
|
||||
void handleRollingGroundCollision(); // Gestiona la interacción del objeto rodante con el suelo (rebotes, frenado, etc.)
|
||||
void handleRollingStop(); // Detiene el movimiento del objeto rodante cuando se cumplen las condiciones necesarias
|
||||
void handleRollingBounce(); // Aplica una lógica de rebote al colisionar con superficies durante el rodamiento
|
||||
void handleTitleAnimation(); // Ejecuta la animación del título en pantalla (ej. entrada, parpadeo o desplazamiento)
|
||||
void handleContinueTimeOut(); // Gestiona el tiempo de espera en la pantalla de "Continuar" y decide si pasar a otro estado
|
||||
void handleLeavingScreen(); // Lógica para salir de la pantalla actual (transición visual o cambio de escena)
|
||||
void handleEnteringScreen(); // Lógica para entrar en una nueva pantalla, posiblemente con animación o retraso
|
||||
void handlePlayer1Entering(); // Controla la animación o posición de entrada del Jugador 1 en pantalla
|
||||
void handlePlayer2Entering(); // Controla la animación o posición de entrada del Jugador 2 en pantalla
|
||||
void handleCreditsMovement(); // Movimiento general en la pantalla de créditos (desplazamiento vertical u horizontal)
|
||||
void handleCreditsRightMovement(); // Lógica específica para mover los créditos hacia la derecha
|
||||
void handleCreditsLeftMovement(); // Lógica específica para mover los créditos hacia la izquierda
|
||||
void updateWalkingStateForCredits(); // Actualiza el estado de caminata de algún personaje u elemento animado en los créditos
|
||||
void setInputBasedOnPlayerId(); // Asocia las entradas de control en función del identificador del jugador (teclas, mando, etc.)
|
||||
void updateStepCounter(); // Incrementa o ajusta el contador de pasos para animaciones o mecánicas relacionadas con movimiento
|
||||
};
|
||||
@@ -160,10 +160,10 @@ void Scoreboard::fillPanelTextures() {
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
}
|
||||
|
||||
void Scoreboard::renderPanelContent(size_t panelIndex) {
|
||||
switch (panel_[panelIndex].mode) {
|
||||
void Scoreboard::renderPanelContent(size_t panel_index) {
|
||||
switch (panel_[panel_index].mode) {
|
||||
case ScoreboardMode::SCORE:
|
||||
renderScoreMode(panelIndex);
|
||||
renderScoreMode(panel_index);
|
||||
break;
|
||||
case ScoreboardMode::DEMO:
|
||||
renderDemoMode();
|
||||
@@ -178,30 +178,30 @@ void Scoreboard::renderPanelContent(size_t panelIndex) {
|
||||
renderStageInfoMode();
|
||||
break;
|
||||
case ScoreboardMode::CONTINUE:
|
||||
renderContinueMode(panelIndex);
|
||||
renderContinueMode(panel_index);
|
||||
break;
|
||||
case ScoreboardMode::ENTER_NAME:
|
||||
renderEnterNameMode(panelIndex);
|
||||
renderEnterNameMode(panel_index);
|
||||
break;
|
||||
case ScoreboardMode::SHOW_NAME:
|
||||
renderShowNameMode(panelIndex);
|
||||
renderShowNameMode(panel_index);
|
||||
break;
|
||||
case ScoreboardMode::GAME_COMPLETED:
|
||||
renderGameCompletedMode(panelIndex);
|
||||
renderGameCompletedMode(panel_index);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Scoreboard::renderScoreMode(size_t panelIndex) {
|
||||
void Scoreboard::renderScoreMode(size_t panel_index) {
|
||||
// SCORE
|
||||
text_scoreboard_->writeDX(TEXT_COLOR | TEXT_CENTER, slot4_1_.x, slot4_1_.y, name_[panelIndex], 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_COLOR | TEXT_CENTER, slot4_2_.x, slot4_2_.y, updateScoreText(score_[panelIndex]), 1, text_color2_);
|
||||
text_scoreboard_->writeDX(TEXT_COLOR | TEXT_CENTER, slot4_1_.x, slot4_1_.y, name_[panel_index], 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_COLOR | TEXT_CENTER, slot4_2_.x, slot4_2_.y, updateScoreText(score_[panel_index]), 1, text_color2_);
|
||||
|
||||
// MULT
|
||||
text_scoreboard_->writeDX(TEXT_COLOR | TEXT_CENTER, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 3"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_COLOR | TEXT_CENTER, slot4_4_.x, slot4_4_.y, "x" + std::to_string(mult_[panelIndex]).substr(0, 3), 1, text_color2_);
|
||||
text_scoreboard_->writeDX(TEXT_COLOR | TEXT_CENTER, slot4_4_.x, slot4_4_.y, "x" + std::to_string(mult_[panel_index]).substr(0, 3), 1, text_color2_);
|
||||
}
|
||||
|
||||
void Scoreboard::renderDemoMode() {
|
||||
@@ -253,74 +253,74 @@ void Scoreboard::renderStageInfoMode() {
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y, NAME + updateScoreText(hi_score_), 1, text_color2_);
|
||||
}
|
||||
|
||||
void Scoreboard::renderContinueMode(size_t panelIndex) {
|
||||
void Scoreboard::renderContinueMode(size_t panel_index) {
|
||||
// SCORE
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y, name_[panelIndex], 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_[panelIndex]), 1, text_color2_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y, name_[panel_index], 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_[panel_index]), 1, text_color2_);
|
||||
|
||||
// CONTINUE
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 10"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y, std::to_string(continue_counter_[panelIndex]), 1, text_color2_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y, std::to_string(continue_counter_[panel_index]), 1, text_color2_);
|
||||
}
|
||||
|
||||
void Scoreboard::renderEnterNameMode(size_t panelIndex) {
|
||||
void Scoreboard::renderEnterNameMode(size_t panel_index) {
|
||||
// SCORE
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y, name_[panelIndex], 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_[panelIndex]), 1, text_color2_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y, name_[panel_index], 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_[panel_index]), 1, text_color2_);
|
||||
|
||||
// ENTER NAME
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 11"), 1, text_color1_);
|
||||
|
||||
renderNameInputField(panelIndex);
|
||||
renderNameInputField(panel_index);
|
||||
}
|
||||
|
||||
void Scoreboard::renderNameInputField(size_t panelIndex) {
|
||||
void Scoreboard::renderNameInputField(size_t panel_index) {
|
||||
SDL_FRect rect = {enter_name_pos_.x, enter_name_pos_.y, 5.0F, 7.0F};
|
||||
|
||||
// Recorre todos los slots de letras del nombre
|
||||
for (size_t j = 0; j < NAME_SIZE; ++j) {
|
||||
// Selecciona el color
|
||||
const Color COLOR = j < selector_pos_[panelIndex] ? text_color2_ : text_color1_;
|
||||
const Color COLOR = j < selector_pos_[panel_index] ? text_color2_ : text_color1_;
|
||||
|
||||
if (j != selector_pos_[panelIndex] || time_counter_ % 3 == 0) {
|
||||
if (j != selector_pos_[panel_index] || time_counter_ % 3 == 0) {
|
||||
// Dibuja la linea
|
||||
if (j >= selector_pos_[panelIndex]) {
|
||||
if (j >= selector_pos_[panel_index]) {
|
||||
SDL_SetRenderDrawColor(renderer_, COLOR.r, COLOR.g, COLOR.b, 255);
|
||||
SDL_RenderLine(renderer_, rect.x, rect.y + rect.h, rect.x + rect.w, rect.y + rect.h);
|
||||
}
|
||||
|
||||
// Dibuja la letra
|
||||
if (j < record_name_[panelIndex].size()) {
|
||||
text_scoreboard_->writeColored(rect.x, rect.y, record_name_[panelIndex].substr(j, 1), COLOR);
|
||||
if (j < record_name_[panel_index].size()) {
|
||||
text_scoreboard_->writeColored(rect.x, rect.y, record_name_[panel_index].substr(j, 1), COLOR);
|
||||
}
|
||||
}
|
||||
rect.x += 7;
|
||||
}
|
||||
}
|
||||
|
||||
void Scoreboard::renderShowNameMode(size_t panelIndex) {
|
||||
void Scoreboard::renderShowNameMode(size_t panel_index) {
|
||||
// SCORE
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y, name_[panelIndex], 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_[panelIndex]), 1, text_color2_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y, name_[panel_index], 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_[panel_index]), 1, text_color2_);
|
||||
|
||||
// NAME
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 11"), 1, text_color1_);
|
||||
|
||||
/* TEXTO CENTRADO */
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y, record_name_[panelIndex], 1, getColorLikeKnightRider(name_colors_, loop_counter_ / 5));
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y, record_name_[panel_index], 1, getColorLikeKnightRider(name_colors_, loop_counter_ / 5));
|
||||
|
||||
/* TEXTO A LA IZQUIERDA */
|
||||
// text_scoreboard_->writeColored(enter_name_pos_.x, enter_name_pos_.y, record_name_[panelIndex], getColorLikeKnightRider(name_colors_, loop_counter_ / 5));
|
||||
}
|
||||
|
||||
void Scoreboard::renderGameCompletedMode(size_t panelIndex) {
|
||||
void Scoreboard::renderGameCompletedMode(size_t panel_index) {
|
||||
// GAME OVER
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y + 4, Lang::getText("[SCOREBOARD] 7"), 1, text_color1_);
|
||||
|
||||
// SCORE
|
||||
if (time_counter_ % 10 < 8) {
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y - 2, Lang::getText("[SCOREBOARD] 14"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y - 2, updateScoreText(score_[panelIndex]), 1, text_color2_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y - 2, updateScoreText(score_[panel_index]), 1, text_color2_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -113,17 +113,17 @@ class Scoreboard {
|
||||
void updateTimeCounter(); // Actualiza el contador
|
||||
void renderSeparator(); // Dibuja la línea que separa la zona de juego del marcador
|
||||
void iniNameColors(); // Inicializa el vector de colores para el nombre
|
||||
void renderPanelContent(size_t panelIndex);
|
||||
void renderScoreMode(size_t panelIndex);
|
||||
void renderPanelContent(size_t panel_index);
|
||||
void renderScoreMode(size_t panel_index);
|
||||
void renderDemoMode();
|
||||
void renderWaitingMode();
|
||||
void renderGameOverMode();
|
||||
void renderStageInfoMode();
|
||||
void renderContinueMode(size_t panelIndex);
|
||||
void renderEnterNameMode(size_t panelIndex);
|
||||
void renderNameInputField(size_t panelIndex);
|
||||
void renderShowNameMode(size_t panelIndex);
|
||||
void renderGameCompletedMode(size_t panelIndex);
|
||||
void renderContinueMode(size_t panel_index);
|
||||
void renderEnterNameMode(size_t panel_index);
|
||||
void renderNameInputField(size_t panel_index);
|
||||
void renderShowNameMode(size_t panel_index);
|
||||
void renderGameCompletedMode(size_t panel_index);
|
||||
|
||||
// --- Constructor y destructor privados (singleton) ---
|
||||
Scoreboard();
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
// Textos
|
||||
constexpr std::string_view TEXT_COPYRIGHT = "@2020,2025 JailDesigner";
|
||||
|
||||
|
||||
// Constructor
|
||||
Credits::Credits()
|
||||
: balloon_manager_(std::make_unique<BalloonManager>()),
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_SetRenderTarget
|
||||
|
||||
#include <array>
|
||||
#include <algorithm> // Para find_if, clamp, find, min
|
||||
#include <array>
|
||||
#include <cstdlib> // Para rand, size_t
|
||||
#include <functional> // Para function
|
||||
#include <iterator> // Para distance, size
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include <SDL3/SDL.h> // Para Uint32
|
||||
|
||||
#include <memory> // Para unique_ptr, shared_ptr
|
||||
#include <vector>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "section.h" // Para Options
|
||||
|
||||
@@ -19,7 +19,6 @@ class TiledBG;
|
||||
// Textos
|
||||
constexpr std::string_view TEXT_COPYRIGHT = "@2020,2025 JailDesigner";
|
||||
|
||||
|
||||
// Parámetros
|
||||
constexpr bool ALLOW_TITLE_ANIMATION_SKIP = false;
|
||||
|
||||
@@ -82,7 +81,7 @@ class Title {
|
||||
void checkEvents(); // Comprueba los eventos
|
||||
void checkInput(); // Comprueba las entradas
|
||||
void resetCounter(); // Reinicia el contador interno
|
||||
void swapControllers(); // Intercambia la asignación de mandos a los jugadores
|
||||
static void swapControllers(); // Intercambia la asignación de mandos a los jugadores
|
||||
static void swapKeyboard(); // Intercambia el teclado de jugador
|
||||
static void showControllers(); // Muestra información sobre los controles y los jugadores
|
||||
void updateFade(); // Actualiza el efecto de fundido (fade in/out)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_FRect, SDL_SetTextureColorMod, SDL_Renderer, SDL_Texture
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "utils.h" // Para Color
|
||||
|
||||
Reference in New Issue
Block a user