arreglos d'estil pa deixar el repo com a plantilla

This commit is contained in:
2025-04-07 13:57:19 +02:00
parent 502ba7297a
commit c3e1abff13
17 changed files with 178 additions and 177 deletions

View File

@@ -1,7 +1,13 @@
#include "audio.h" #include "audio.h"
#include "jail_audio.h" #include <SDL3/SDL_audio.h> // for SDL_AudioFormat
#include "options.h" #include <SDL3/SDL_error.h> // for SDL_GetError
#include <SDL3/SDL.h> #include <SDL3/SDL_init.h> // for SDL_Init, SDL_INIT_AUDIO
#include <SDL3/SDL_log.h> // for SDL_LogInfo, SDL_LogCategory, SDL_LogError
#include <algorithm> // for clamp
#include "jail_audio.h" // for JA_FadeOutMusic, JA_Init, JA_PauseMusic
#include "options.h" // for Options, OptionsAudio, options, OptionsM...
struct JA_Music_t;
struct JA_Sound_t;
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado // [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
Audio *Audio::audio_ = nullptr; Audio *Audio::audio_ = nullptr;

View File

@@ -1,7 +1,7 @@
#pragma once #pragma once
#include <string> struct JA_Music_t;
#include "jail_audio.h" struct JA_Sound_t;
class Audio class Audio
{ {

View File

@@ -1,34 +1,10 @@
#include "global_inputs.h" #include "global_inputs.h"
#include <SDL3/SDL.h> // Para SDL_RendererLogicalPresentation, SDL_Se... #include <SDL3/SDL_keycode.h> // for SDLK_ESCAPE, SDLK_F1, SDLK_F2, SDLK_F3
#include <string> // Para operator+, allocator, char_traits, string #include "options.h" // for Options, OptionsLogo, options
#include <vector> // Para vector #include "screen.h" // for Screen
#include "audio.h" // Para JA_SetMusicVolume, JA_SetSoundVolume
#include "options.h" // Para Options, options, VideoOptions, GameOpt...
#include "screen.h" // Para Screen
#include "utils.h" // Para boolToOnOff
namespace globalInputs namespace globalInputs
{ {
// Activa o desactiva el audio
void toggleAudio()
{
options.audio.enabled = !options.audio.enabled;
Audio::get()->enable(options.audio.enabled);
}
// Cambia el modo de escalado entero
void toggleIntegerScale()
{
Screen::get()->toggleIntegerScale();
}
// Activa / desactiva el vsync
void toggleVSync()
{
Screen::get()->toggleVSync();
}
// Comprueba los inputs que se pueden introducir en cualquier sección del juego // Comprueba los inputs que se pueden introducir en cualquier sección del juego
void check(const SDL_Event &event) void check(const SDL_Event &event)
{ {
@@ -58,12 +34,12 @@ namespace globalInputs
// Integer Scale // Integer Scale
case SDLK_F5: case SDLK_F5:
toggleIntegerScale(); Screen::get()->toggleIntegerScale();
return; return;
// VSync // VSync
case SDLK_F6: case SDLK_F6:
toggleVSync(); Screen::get()->toggleVSync();
return; return;
} }
} }

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL.h> #include <SDL3/SDL_events.h> // for SDL_Event
namespace globalInputs namespace globalInputs
{ {

View File

@@ -1,9 +1,9 @@
#pragma once #pragma once
#include <SDL3/SDL_audio.h> // Para SDL_AudioFormat #include <SDL3/SDL_audio.h> // for SDL_AudioFormat
#include <SDL3/SDL_stdinc.h> // Para Uint32, Uint8 #include <SDL3/SDL_stdinc.h> // for Uint32, Uint8
struct JA_Music_t; // lines 8-8 struct JA_Music_t; // lines 4-4
struct JA_Sound_t; // lines 7-7 struct JA_Sound_t; // lines 5-5
enum JA_Channel_state enum JA_Channel_state
{ {

View File

@@ -1,87 +1,112 @@
#include "logo.h" #include "logo.h"
#include <SDL3/SDL_events.h> // Manejo de eventos de SDL (teclado, ratón, etc.)
#include <SDL3/SDL_init.h> // Inicialización y limpieza de SDL
#include <SDL3/SDL_log.h> // Manejo de logs en SDL
#include <SDL3/SDL_timer.h> // Funciones de temporización de SDL
#include "global_inputs.h" // Funciones para manejar entradas globales
#include "mouse.h" // Manejo de eventos del ratón
#include "options.h" // Configuración global de opciones
#include "s_sprite.h" // Clase para manejar sprites
#include "screen.h" // Clase para manejar la pantalla
#include "surface.h" // Clase para manejar superficies
#include "screen.h" // Constructor de la clase Logo: inicializa los recursos necesarios
#include "mouse.h"
#include "surface.h"
#include "s_sprite.h"
#include "global_inputs.h"
Logo::Logo() Logo::Logo()
{ {
init(); init();
} }
// Destructor de la clase Logo: libera los recursos utilizados
Logo::~Logo() Logo::~Logo()
{ {
close(); close();
} }
// Método privado para inicializar los recursos del logotipo
void Logo::init() void Logo::init()
{ {
// Configura las prioridades de los logs
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
SDL_SetLogPriority(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_ERROR); SDL_SetLogPriority(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_ERROR);
// Inicializa la pantalla
Screen::get()->init(); Screen::get()->init();
// Carga la superficie del logotipo desde un archivo y la escala
logo_surface = std::make_shared<Surface>("jailgames.gif"); logo_surface = std::make_shared<Surface>("jailgames.gif");
logo_surface->scale(5); logo_surface->scale(5);
// Crea el sprite del logotipo y lo posiciona en el centro de la pantalla
logo_sprite = std::make_unique<SSprite>(logo_surface); logo_sprite = std::make_unique<SSprite>(logo_surface);
logo_sprite->setPosition( logo_sprite->setPosition(
(options.logo.width - logo_sprite->getWidth()) / 2, (options.logo.width - logo_sprite->getWidth()) / 2,
(options.logo.height - logo_sprite->getHeight()) / 2); (options.logo.height - logo_sprite->getHeight()) / 2);
// Log de inicio del logotipo
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Logo start"); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Logo start");
} }
// Método privado para liberar los recursos del logotipo
void Logo::close() void Logo::close()
{ {
// Destruye la pantalla
Screen::get()->destroy(); Screen::get()->destroy();
// Log de finalización del logotipo
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nBye!"); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nBye!");
// Finaliza SDL
SDL_Quit(); SDL_Quit();
} }
// Método privado para manejar los eventos de entrada
void Logo::checkEvents() void Logo::checkEvents()
{ {
SDL_Event event; SDL_Event event;
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event)) // Procesa todos los eventos en la cola
{ {
switch (event.type) switch (event.type)
{ {
case SDL_EVENT_QUIT: case SDL_EVENT_QUIT: // Evento de salida (cerrar la ventana)
options.logo.running = false; options.logo.running = false; // Detiene el bucle principal
return; return;
} }
// Maneja entradas globales y eventos del ratón
globalInputs::check(event); globalInputs::check(event);
Mouse::handleEvent(event); Mouse::handleEvent(event);
} }
} }
// Método privado para actualizar el estado del logotipo
void Logo::update() void Logo::update()
{ {
// Comprueba si ha pasado suficiente tiempo para actualizar
if (SDL_GetTicks() - ticks > options.logo.speed) if (SDL_GetTicks() - ticks > options.logo.speed)
{ {
ticks = SDL_GetTicks(); ticks = SDL_GetTicks(); // Actualiza el contador de ticks
// Actualiza la pantalla
Screen::get()->update(); Screen::get()->update();
} }
} }
// Método privado para renderizar el logotipo en pantalla
void Logo::render() void Logo::render()
{ {
Screen::get()->start(); Screen::get()->start(); // Inicia el proceso de renderizado
logo_sprite->render(); logo_sprite->render(); // Renderiza el sprite del logotipo
Screen::get()->render(); Screen::get()->render(); // Finaliza el renderizado
} }
// Método principal que ejecuta el ciclo de vida del logotipo
int Logo::run() int Logo::run()
{ {
while (options.logo.running) while (options.logo.running) // Bucle principal mientras el logotipo esté activo
{ {
update(); update(); // Actualiza el estado del logotipo
checkEvents(); checkEvents(); // Maneja los eventos de entrada
render(); render(); // Renderiza el logotipo
} }
return 0; return 0; // Devuelve 0 al finalizar
} }

View File

@@ -1,27 +1,28 @@
#pragma once #pragma once // Evita inclusiones múltiples del archivo de encabezado
#include <SDL3/SDL.h> #include <SDL3/SDL_stdinc.h> // Incluye definiciones estándar de SDL, como Uint64
#include <memory> #include <memory> // Proporciona soporte para punteros inteligentes (shared_ptr, unique_ptr)
#include "surface.h" #include "s_sprite.h" // Declara la clase SSprite, utilizada para manejar sprites
#include "s_sprite.h"
class Surface; // Declaración adelantada de la clase Surface
// Clase Logo: Maneja la lógica principal de un logotipo animado o interactivo
class Logo class Logo
{ {
private: private:
bool running = true; Uint64 ticks = 0; // Contador de ticks para medir el tiempo o controlar animaciones
Uint64 ticks = 0; std::shared_ptr<Surface> logo_surface = nullptr; // Superficie del logotipo, compartida entre múltiples objetos
std::shared_ptr<Surface> logo_surface = nullptr; std::unique_ptr<SSprite> logo_sprite = nullptr; // Sprite del logotipo, propiedad exclusiva de esta clase
std::unique_ptr<SSprite> logo_sprite = nullptr;
void init(); // Métodos privados para manejar el ciclo de vida y la lógica del logotipo
void close(); void init(); // Inicializa los recursos necesarios para el logotipo
void checkEvents(); void close(); // Libera los recursos utilizados por el logotipo
void update(); void checkEvents(); // Maneja los eventos de entrada (teclado, ratón, etc.)
void render(); void update(); // Actualiza el estado del logotipo (animaciones, lógica, etc.)
void render(); // Renderiza el logotipo en pantalla
public: public:
Logo(); Logo(); // Constructor: Inicializa la clase Logo
~Logo(); ~Logo(); // Destructor: Limpia los recursos utilizados por la clase Logo
int run(); int run(); // Método principal que ejecuta el ciclo de vida del logotipo
}; };

View File

@@ -1,6 +1,5 @@
#include <SDL3/SDL.h> #include <memory> // for make_unique, unique_ptr
#include <memory> #include "logo.h" // for Logo
#include "logo.h"
int main() int main()
{ {

View File

@@ -1,14 +1,4 @@
#include "options.h" #include "options.h"
#include <SDL3/SDL.h>
#include <algorithm> // Para find_if
#include <cctype> // Para isspace
#include <fstream> // Para basic_ostream, operator<<, basic_ofstream
#include <functional> // Para function
#include <iostream> // Para cout, cerr
#include <sstream> // Para basic_istringstream
#include <string> // Para char_traits, string, operator<<, hash
#include <unordered_map> // Para unordered_map, operator==, _Node_const_i...
#include <utility> // Para pair
// Variables // Variables
Options options; Options options;

View File

@@ -1,9 +1,9 @@
#pragma once #pragma once
#include <SDL3/SDL.h> // Para Uint32 #include <SDL3/SDL_stdinc.h> // for Uint64
#include <string> // Para string, basic_string #include <SDL3/SDL_surface.h> // for SDL_ScaleMode
#include "utils.h" // Para Color, Palette #include <algorithm> // for clamp
#include <algorithm> #include <string> // for string, basic_string
// Constantes // Constantes
constexpr int DEFAULT_GAME_WIDTH = 480; // Ancho de la ventana por defecto constexpr int DEFAULT_GAME_WIDTH = 480; // Ancho de la ventana por defecto

View File

@@ -1,7 +1,8 @@
#pragma once #pragma once
#include <SDL3/SDL.h> #include <SDL3/SDL_rect.h> // for SDL_Rect, SDL_Point
#include <memory> // Para shared_ptr #include <SDL3/SDL_stdinc.h> // for Uint8
#include <memory> // for shared_ptr
class Surface; // lines 5-5 class Surface; // lines 5-5
// Clase SSprite // Clase SSprite

View File

@@ -1,14 +1,15 @@
#include "screen.h" #include "screen.h"
#include <SDL3/SDL.h> #include <SDL3/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
#include <ctype.h> // Para toupper #include <SDL3/SDL_error.h> // for SDL_GetError
#include <algorithm> // Para max, min, transform #include <SDL3/SDL_hints.h> // for SDL_SetHint, SDL_HINT_RENDER_DRIVER
#include <fstream> // Para basic_ostream, operator<<, endl, basic_... #include <SDL3/SDL_init.h> // for SDL_Init, SDL_INIT_VIDEO
#include <iostream> // Para cerr #include <SDL3/SDL_log.h> // for SDL_LogCategory, SDL_LogInfo, SDL_Lo...
#include <iterator> // Para istreambuf_iterator, operator== #include <SDL3/SDL_pixels.h> // for SDL_PixelFormat
#include <string> // Para char_traits, string, operator+, operator== #include <algorithm> // for min, max
#include "mouse.h" // Para updateCursorVisibility #include <string> // for char_traits, operator+, to_string
#include "options.h" // Para Options, options, OptionsVideo, Border #include "mouse.h" // for updateCursorVisibility
#include "surface.h" // Para Surface, readPalFile #include "options.h" // for Options, options, OptionsWindow, Opt...
#include "surface.h" // for Surface, readPalFile
// [SINGLETON] // [SINGLETON]
Screen *Screen::screen_ = nullptr; Screen *Screen::screen_ = nullptr;

View File

@@ -1,13 +1,12 @@
#pragma once #pragma once
#include <SDL3/SDL.h> #include <SDL3/SDL_render.h> // for SDL_Renderer, SDL_Texture
#include <stddef.h> // Para size_t #include <SDL3/SDL_stdinc.h> // for Uint8
#include <memory> // Para shared_ptr, __shared_ptr_access #include <SDL3/SDL_video.h> // for SDL_Window
#include <string> // Para string #include <memory> // for shared_ptr
#include <vector> // Para vector #include "options.h" // for Options, OptionsVideo, options
#include "utils.h" // Para Color #include "surface.h" // for Surface
#include "options.h" #include "utils.h" // for Color
struct Surface;
class Screen class Screen
{ {

View File

@@ -1,18 +1,20 @@
// IWYU pragma: no_include <bits/std_abs.h> // IWYU pragma: no_include <bits/std_abs.h>
#include "surface.h" #include "surface.h"
#include <SDL3/SDL.h> #include <SDL3/SDL_error.h> // for SDL_GetError
#include <cmath> // Para abs #include <SDL3/SDL_timer.h> // for SDL_GetTicks
#include <algorithm> // Para min, max, copy_n, fill #include <stdlib.h> // for abs
#include <cstdint> // Para uint32_t #include <algorithm> // for min, max, copy_n, fill
#include <cstring> // Para memcpy, size_t #include <cstdint> // for uint32_t
#include <fstream> // Para basic_ifstream, basic_ostream, basic_ist... #include <cstring> // for memcpy, size_t
#include <iostream> // Para cerr #include <fstream> // for basic_ifstream, basic_ostream, basic_ist...
#include <memory> // Para shared_ptr, __shared_ptr_access, default... #include <iostream> // for cerr
#include <sstream> // Para basic_istringstream #include <memory> // for shared_ptr, __shared_ptr_access, default...
#include <stdexcept> // Para runtime_error #include <sstream> // for basic_istringstream
#include <vector> // Para vector #include <stdexcept> // for runtime_error
#include "gif.h" // Para Gif #include <vector> // for vector
#include "screen.h" // Para Screen #include "gif.h" // for Gif
#include "screen.h" // for Screen
#include "utils.h" // for printWithDots
// Carga una paleta desde un archivo .gif // Carga una paleta desde un archivo .gif
Palette loadPalette(const std::string &file_path) Palette loadPalette(const std::string &file_path)

View File

@@ -1,12 +1,15 @@
#pragma once #pragma once
#include <SDL3/SDL.h> #include <SDL3/SDL_rect.h> // for SDL_Rect, SDL_FRect
#include <array> // Para array #include <SDL3/SDL_render.h> // for SDL_Renderer, SDL_Texture
#include <memory> // Para default_delete, shared_ptr, __shared_pt... #include <SDL3/SDL_stdinc.h> // for Uint8, Uint16, Uint32
#include <numeric> // Para iota #include <SDL3/SDL_surface.h> // for SDL_FlipMode
#include <string> // Para string #include <array> // for array
#include <utility> // Para move #include <memory> // for default_delete, shared_ptr, __shared_p...
#include "utils.h" // Para PaletteColor #include <numeric> // for iota
#include <stdexcept> // for invalid_argument
#include <string> // for string
#include <utility> // for move
// Alias // Alias
using Palette = std::array<Uint32, 256>; using Palette = std::array<Uint32, 256>;

View File

@@ -1,15 +1,12 @@
#include "utils.h" #include "utils.h"
#include <stdlib.h> // Para abs #include <stdlib.h> // for abs
#include <algorithm> // Para find, transform #include <algorithm> // for transform, find
#include <cctype> // Para tolower #include <cctype> // for tolower, toupper
#include <cmath> // Para round, abs #include <cmath> // for round
#include <exception> // Para exception #include <exception> // for exception
#include <filesystem> // Para path #include <filesystem> // for path
#include <iostream> // Para basic_ostream, cout, basic_ios, ios, endl #include <iostream> // for basic_ostream, cout, basic_ios, ios, endl
#include <string> // Para basic_string, string, char_traits, allocator #include <string> // for string, char_traits, allocator, operator==
#include <unordered_map> // Para unordered_map, operator==, _Node_const_iter...
#include <utility> // Para pair
#include "jail_audio.h" // Para JA_GetMusicState, JA_Music_state, JA_PlayMusic
// Calcula el cuadrado de la distancia entre dos puntos // Calcula el cuadrado de la distancia entre dos puntos
double distanceSquared(int x1, int y1, int x2, int y2) double distanceSquared(int x1, int y1, int x2, int y2)

View File

@@ -1,8 +1,9 @@
#pragma once #pragma once
#include <SDL3/SDL.h> // Para SDL_Rect, SDL_Point #include <SDL3/SDL_rect.h> // for SDL_Rect, SDL_Point
#include <string> // Para string #include <SDL3/SDL_stdinc.h> // for Uint8
#include <vector> // Para vector #include <string> // for string
#include <vector> // for vector
// Estructura para definir un circulo // Estructura para definir un circulo
struct Circle struct Circle