clang-format
This commit is contained in:
2025-07-23 20:55:50 +02:00
parent d33c1f5dc5
commit ec008ef5dd
61 changed files with 308 additions and 253 deletions

View File

@@ -2,6 +2,7 @@
#include "credits.h"
#include <SDL3/SDL.h> // Para SDL_RenderFillRect, SDL_RenderTexture, SDL_SetRenderTarget, SDL_SetRenderDrawColor, SDL_CreateTexture, SDL_DestroyTexture, SDL_GetTicks, SDL_GetRenderTarget, SDL_PixelFormat, SDL_PollEvent, SDL_RenderClear, SDL_RenderRect, SDL_SetTextureBlendMode, SDL_TextureAccess, SDL_BLENDMODE_BLEND, SDL_Event
#include <algorithm> // Para max, min, clamp
#include <array> // Para array
#include <stdexcept> // Para runtime_error

View File

@@ -1,6 +1,7 @@
#pragma once
#include <SDL3/SDL.h> // Para SDL_FRect, Uint32, SDL_Texture, Uint64
#include <memory> // Para unique_ptr, shared_ptr
#include <vector> // Para vector
@@ -17,7 +18,7 @@ class TiledBG;
class Credits {
public:
// --- Constructores y destructor ---
// --- Constructor y destructor ---
Credits();
~Credits();

View File

@@ -15,6 +15,7 @@
#include "balloon_manager.h" // Para BalloonManager
#include "bullet.h" // Para Bullet, BulletType, BulletMoveStatus
#include "color.h" // Para Color, FLASH_COLOR
#include "difficulty.h" // Para Code
#include "fade.h" // Para Fade, FadeType, FadeMode
#include "global_events.h" // Para check
#include "global_inputs.h" // Para check

View File

@@ -1,15 +1,14 @@
#pragma once
#include <SDL3/SDL.h> // Para SDL_Event, SDL_Renderer, SDL_Texture, Uint64
#include <SDL3/SDL.h> // Para SDL_Event, SDL_Renderer, SDL_Texture, Uint64, Uint8
#include <memory> // Para shared_ptr, unique_ptr
#include <string> // Para string
#include <vector> // Para vector
#include "difficulty.h" // Para Difficulty
#include "item.h" // Para Item, ItemType
#include "manage_hiscore_table.h" // Para HiScoreEntry
#include "options.h" // Para SettingsOptions, settings, DifficultyCode (ptr only)
#include "options.h" // Para SettingsOptions, settings
#include "path_sprite.h" // Para PathSprite, Path
#include "player.h" // Para Player
#include "smart_sprite.h" // Para SmartSprite
@@ -26,6 +25,9 @@ class Screen;
class Tabe;
class Texture;
enum class BulletType : Uint8;
namespace Difficulty {
enum class Code;
} // namespace Difficulty
// Modo demo
constexpr bool GAME_MODE_DEMO_OFF = false;
@@ -37,13 +39,11 @@ constexpr int TOTAL_SCORE_DATA = 3;
// Clase Game
class Game {
public:
// Constructor
// --- Constructor y destructor ---
Game(int player_id, int current_stage, bool demo);
// Destructor
~Game();
// Bucle principal del juego
// --- Bucle principal ---
void run();
private:
@@ -129,13 +129,13 @@ class Game {
Options::settings.hi_score_table[0].name,
Options::settings.hi_score_table[0].score); // Máxima puntuación y nombre de quien la ostenta
Demo demo_; // Variable con todas las variables relacionadas con el modo demo
Demo demo_; // Variable con todas las variables relacionadas con el modo demo
Difficulty::Code difficulty_ = Options::settings.difficulty; // Dificultad del juego
Helper helper_; // Variable para gestionar las ayudas
Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
bool coffee_machine_enabled_ = false; // Indica si hay una máquina de café en el terreno de juego
bool hi_score_achieved_ = false; // Indica si se ha superado la puntuación máxima
bool paused_ = false; // Indica si el juego está pausado (no se deberia de poder utilizar en el modo arcade)
Helper helper_; // Variable para gestionar las ayudas
Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
bool coffee_machine_enabled_ = false; // Indica si hay una máquina de café en el terreno de juego
bool hi_score_achieved_ = false; // Indica si se ha superado la puntuación máxima
bool paused_ = false; // Indica si el juego está pausado (no se deberia de poder utilizar en el modo arcade)
// bool paused_by_service_menu_ = false;
float difficulty_score_multiplier_; // Multiplicador de puntos en función de la dificultad
int counter_ = 0; // Contador para el juego

View File

@@ -1,6 +1,7 @@
#include "hiscore_table.h"
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_SetRenderTarget
#include <algorithm> // Para max
#include <cstdlib> // Para rand, size_t
#include <functional> // Para function

View File

@@ -1,9 +1,10 @@
#pragma once
#include <SDL3/SDL.h> // Para Uint16, SDL_FRect, SDL_Renderer, SDL_Texture, Uint64, Uint8
#include <memory> // Para unique_ptr, shared_ptr
#include <string> // Para string
#include <vector> // Para vector
#include <SDL3/SDL.h> // Para Uint16, SDL_FRect, SDL_Renderer, SDL_Texture, Uint64, Uint8
#include <memory> // Para unique_ptr, shared_ptr
#include <string> // Para string
#include <vector> // Para vector
#include "color.h" // Para Color
#include "path_sprite.h" // Para Path, PathSprite (ptr only)
@@ -26,13 +27,11 @@ enum class FadeMode : Uint8;
// Clase HiScoreTable
class HiScoreTable {
public:
// Constructor
// --- Constructor y destructor ---
HiScoreTable();
// Destructor
~HiScoreTable();
// Bucle principal
// --- Bucle principal ---
void run();
private:

View File

@@ -1,6 +1,7 @@
#pragma once
#include <SDL3/SDL.h> // Para SDL_Texture, Uint32, SDL_Renderer, SDL_FPoint, SDL_FRect, Uint64
#include <memory> // Para unique_ptr, shared_ptr
#include <vector> // Para vector
@@ -39,13 +40,11 @@ struct Line {
// Clase Instructions
class Instructions {
public:
// Constructor
// --- Constructor y destructor ---
Instructions();
// Destructor
~Instructions();
// Bucle principal
// --- Bucle principal ---
void run();
private:

View File

@@ -20,13 +20,11 @@
// Clase Intro
class Intro {
public:
// Constructor
// --- Constructor y destructor ---
Intro();
// Destructor
~Intro() = default;
// Bucle principal
// --- Bucle principal ---
void run();
private:
@@ -72,8 +70,8 @@ class Intro {
void updatePostState(); // Actualiza el estado POST
#ifdef _DEBUG
static void adjustColorComponent(uint8_t& component, bool increase);
void adjustAllColorComponents(Color& color, bool increase);
void handleDebugColorKeys(SDL_Keycode key, Color& color);
static void adjustAllColorComponents(Color& color, bool increase);
static void handleDebugColorKeys(SDL_Keycode key, Color& color);
static void printColorDebugInfo(const Color& color);
#endif

View File

@@ -1,6 +1,7 @@
#include "logo.h"
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_PollEvent, SDL_Event, SDL_FRect
#include <algorithm> // Para max
#include <utility> // Para move

View File

@@ -1,11 +1,12 @@
#pragma once
#include <SDL3/SDL.h> // Para SDL_FPoint, Uint64
#include <memory> // Para unique_ptr, shared_ptr
#include <vector> // Para vector
#include "color.h" // Para Color
#include "sprite.h" // Para Sprite
#include <memory> // Para unique_ptr, shared_ptr
#include <vector> // Para vector
#include "color.h" // Para Color
#include "sprite.h" // Para Sprite
class Texture;
@@ -20,13 +21,11 @@ class Texture;
// --- Clase Logo ---
class Logo {
public:
// Constructor
// --- Constructor y destructor ---
Logo();
// Destructor
~Logo();
// Bucle principal
// --- Bucle principal ---
void run();
private:

View File

@@ -111,31 +111,31 @@ void Title::checkEvents() {
if (event.type == SDL_EVENT_KEY_DOWN) {
handleKeyDownEvent(event);
}
GlobalEvents::check(event);
define_buttons_->checkEvents(event);
}
}
void Title::handleKeyDownEvent(const SDL_Event& event) {
bool isFirstPress = static_cast<int>(event.key.repeat) == 0;
if (isFirstPress) {
bool is_first_press = static_cast<int>(event.key.repeat) == 0;
if (is_first_press) {
handleControlKeys(event.key.key);
}
#ifdef _DEBUG
bool isRepeat = static_cast<int>(event.key.repeat) == 1;
if (isRepeat) {
#ifdef _DEBUG
bool is_repeat = static_cast<int>(event.key.repeat) == 1;
if (is_repeat) {
handleDebugColorKeys(event.key.key);
}
#endif
#endif
}
#ifdef _DEBUG
void Title::handleDebugColorKeys(SDL_Keycode key) {
static Color color_ = param.title.bg_color;
adjustColorComponent(key, color_);
counter_ = 0;
tiled_bg_->setColor(color_);
printColorValue(color_);
@@ -143,15 +143,32 @@ void Title::handleDebugColorKeys(SDL_Keycode key) {
void Title::adjustColorComponent(SDL_Keycode key, Color& color) {
switch (key) {
case SDLK_A: incrementColorComponent(color.r); break;
case SDLK_Z: decrementColorComponent(color.r); break;
case SDLK_S: incrementColorComponent(color.g); break;
case SDLK_X: decrementColorComponent(color.g); break;
case SDLK_D: incrementColorComponent(color.b); break;
case SDLK_C: decrementColorComponent(color.b); break;
case SDLK_F: incrementAllComponents(color); break;
case SDLK_V: decrementAllComponents(color); break;
default: break;
case SDLK_A:
incrementColorComponent(color.r);
break;
case SDLK_Z:
decrementColorComponent(color.r);
break;
case SDLK_S:
incrementColorComponent(color.g);
break;
case SDLK_X:
decrementColorComponent(color.g);
break;
case SDLK_D:
incrementColorComponent(color.b);
break;
case SDLK_C:
decrementColorComponent(color.b);
break;
case SDLK_F:
incrementAllComponents(color);
break;
case SDLK_V:
decrementAllComponents(color);
break;
default:
break;
}
}
@@ -194,27 +211,27 @@ void Title::handleControlKeys(SDL_Keycode key) {
define_buttons_->enable(0);
resetCounter();
break;
case SDLK_2:
define_buttons_->enable(1);
resetCounter();
break;
case SDLK_3:
swapControllers();
resetCounter();
break;
case SDLK_4:
swapKeyboard();
resetCounter();
break;
case SDLK_5:
showControllers();
resetCounter();
break;
default:
break;
}
@@ -235,28 +252,27 @@ void Title::checkInput() {
GlobalInputs::check();
}
bool Title::shouldSkipInputCheck() const {
auto Title::shouldSkipInputCheck() const -> bool {
return define_buttons_->isEnabled();
}
void Title::processControllerInputs() {
for (const auto &controller : Options::controllers) {
for (const auto& controller : Options::controllers) {
if (isStartButtonPressed(controller)) {
handleStartButtonPress(controller);
}
}
}
bool Title::isStartButtonPressed(const Options::GamepadOptions &controller) const {
auto Title::isStartButtonPressed(const Options::GamepadOptions& controller) -> bool {
return Input::get()->checkInput(
InputAction::START,
INPUT_DO_NOT_ALLOW_REPEAT,
controller.type,
controller.index
);
InputAction::START,
INPUT_DO_NOT_ALLOW_REPEAT,
controller.type,
controller.index);
}
void Title::handleStartButtonPress(const Options::GamepadOptions &controller) {
void Title::handleStartButtonPress(const Options::GamepadOptions& controller) {
if (!canProcessStartButton()) {
return;
}
@@ -268,7 +284,7 @@ void Title::handleStartButtonPress(const Options::GamepadOptions &controller) {
}
}
bool Title::canProcessStartButton() const {
auto Title::canProcessStartButton() const -> bool {
return (state_ != TitleState::LOGO_ANIMATING || ALLOW_TITLE_ANIMATION_SKIP);
}
@@ -546,21 +562,21 @@ void Title::initPlayers() {
// Actualza los jugadores
void Title::updatePlayers() {
for (auto &player : players_) {
for (auto& player : players_) {
player->update();
}
}
// Renderiza los jugadores
void Title::renderPlayers() {
for (auto const &player : players_) {
for (auto const& player : players_) {
player->render();
}
}
// Obtiene un jugador a partir de su "id"
auto Title::getPlayer(int id) -> std::shared_ptr<Player> {
auto it = std::find_if(players_.begin(), players_.end(), [id](const auto &player) { return player->getId() == id; });
auto it = std::find_if(players_.begin(), players_.end(), [id](const auto& player) { return player->getId() == id; });
if (it != players_.end()) {
return *it;

View File

@@ -1,14 +1,13 @@
#pragma once
#include <SDL3/SDL.h> // Para Uint32
#include <SDL3/SDL.h> // Para SDL_Keycode, SDL_Event, Uint64
#include <stdint.h> // Para uint8_t
#include <memory> // Para unique_ptr, shared_ptr
#include <string_view>
#include <vector>
#include <memory> // Para unique_ptr, shared_ptr
#include <string_view> // Para string_view
#include <vector> // Para vector
#include "color.h" // Para Color
#include "options.h" // Para Options
#include "section.hpp" // Para Options
#include "section.hpp" // Para Options, Name (ptr only)
class DefineButtons;
class Fade;
@@ -17,6 +16,10 @@ class Player;
class Sprite;
class Text;
class TiledBG;
namespace Options {
struct GamepadOptions;
} // namespace Options
struct Color;
// Textos
constexpr std::string_view TEXT_COPYRIGHT = "@2020,2025 JailDesigner";
@@ -33,12 +36,12 @@ constexpr bool ALLOW_TITLE_ANIMATION_SKIP = false;
// Clase Title
class Title {
public:
// --- Constructores y destructor ---
// --- Constructor y destructor ---
Title();
~Title();
// --- Método principal ---
void run(); // Bucle para el título del juego
// --- Bucle principal ---
void run();
private:
// --- Enumeraciones ---
@@ -84,18 +87,18 @@ class Title {
void resetCounter(); // Reinicia el contador interno
// --- Entrada de usuario ---
void checkEvents(); // Comprueba los eventos
void checkInput(); // Comprueba las entradas
void handleKeyDownEvent(const SDL_Event& event); // Maneja el evento de tecla presionada
void handleControlKeys(SDL_Keycode key); // Maneja las teclas de control específicas
bool shouldSkipInputCheck() const; // Determina si se debe omitir la comprobación de entrada
void processControllerInputs(); // Procesa las entradas de los mandos
bool isStartButtonPressed(const Options::GamepadOptions& controller) const; // Comprueba si se ha pulsado el botón Start
void handleStartButtonPress(const Options::GamepadOptions& controller); // Maneja la pulsación del botón Start
bool canProcessStartButton() const; // Verifica si se puede procesar la pulsación del botón Start
void processPlayer1Start(); // Procesa el inicio del jugador 1
void processPlayer2Start(); // Procesa el inicio del jugador 2
void activatePlayerAndSetState(int player_id); // Activa al jugador y cambia el estado del título
void checkEvents(); // Comprueba los eventos
void checkInput(); // Comprueba las entradas
void handleKeyDownEvent(const SDL_Event& event); // Maneja el evento de tecla presionada
void handleControlKeys(SDL_Keycode key); // Maneja las teclas de control específicas
[[nodiscard]] auto shouldSkipInputCheck() const -> bool; // Determina si se debe omitir la comprobación de entrada
void processControllerInputs(); // Procesa las entradas de los mandos
[[nodiscard]] static auto isStartButtonPressed(const Options::GamepadOptions& controller) -> bool; // Comprueba si se ha pulsado el botón Start
void handleStartButtonPress(const Options::GamepadOptions& controller); // Maneja la pulsación del botón Start
[[nodiscard]] auto canProcessStartButton() const -> bool; // Verifica si se puede procesar la pulsación del botón Start
void processPlayer1Start(); // Procesa el inicio del jugador 1
void processPlayer2Start(); // Procesa el inicio del jugador 2
void activatePlayerAndSetState(int player_id); // Activa al jugador y cambia el estado del título
// --- Gestión de jugadores ---
void initPlayers(); // Inicializa los jugadores
@@ -117,12 +120,12 @@ class Title {
// --- Depuración (solo en modo DEBUG) ---
#ifdef _DEBUG
void handleDebugColorKeys(SDL_Keycode key); // Maneja las teclas de depuración para colores
void adjustColorComponent(SDL_Keycode key, Color& color); // Ajusta un componente del color según la tecla
void incrementColorComponent(uint8_t& component); // Incrementa un componente de color
void decrementColorComponent(uint8_t& component); // Decrementa un componente de color
void incrementAllComponents(Color& color); // Incrementa todos los componentes del color
void decrementAllComponents(Color& color); // Decrementa todos los componentes del color
void printColorValue(const Color& color); // Imprime el valor actual del color en consola
void handleDebugColorKeys(SDL_Keycode key); // Maneja las teclas de depuración para colores
static void adjustColorComponent(SDL_Keycode key, Color& color); // Ajusta un componente del color según la tecla
static void incrementColorComponent(uint8_t& component); // Incrementa un componente de color
static void decrementColorComponent(uint8_t& component); // Decrementa un componente de color
static void incrementAllComponents(Color& color); // Incrementa todos los componentes del color
static void decrementAllComponents(Color& color); // Decrementa todos los componentes del color
static void printColorValue(const Color& color); // Imprime el valor actual del color en consola
#endif
};