arreglos d'estil pa deixar el repo com a plantilla
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
#include "audio.h"
|
||||
#include "jail_audio.h"
|
||||
#include "options.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_audio.h> // for SDL_AudioFormat
|
||||
#include <SDL3/SDL_error.h> // for SDL_GetError
|
||||
#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
|
||||
Audio *Audio::audio_ = nullptr;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "jail_audio.h"
|
||||
struct JA_Music_t;
|
||||
struct JA_Sound_t;
|
||||
|
||||
class Audio
|
||||
{
|
||||
|
||||
@@ -1,34 +1,10 @@
|
||||
#include "global_inputs.h"
|
||||
#include <SDL3/SDL.h> // Para SDL_RendererLogicalPresentation, SDL_Se...
|
||||
#include <string> // Para operator+, allocator, char_traits, string
|
||||
#include <vector> // Para vector
|
||||
#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
|
||||
#include <SDL3/SDL_keycode.h> // for SDLK_ESCAPE, SDLK_F1, SDLK_F2, SDLK_F3
|
||||
#include "options.h" // for Options, OptionsLogo, options
|
||||
#include "screen.h" // for Screen
|
||||
|
||||
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
|
||||
void check(const SDL_Event &event)
|
||||
{
|
||||
@@ -58,12 +34,12 @@ namespace globalInputs
|
||||
|
||||
// Integer Scale
|
||||
case SDLK_F5:
|
||||
toggleIntegerScale();
|
||||
Screen::get()->toggleIntegerScale();
|
||||
return;
|
||||
|
||||
// VSync
|
||||
case SDLK_F6:
|
||||
toggleVSync();
|
||||
Screen::get()->toggleVSync();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_events.h> // for SDL_Event
|
||||
|
||||
namespace globalInputs
|
||||
{
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL_audio.h> // Para SDL_AudioFormat
|
||||
#include <SDL3/SDL_stdinc.h> // Para Uint32, Uint8
|
||||
struct JA_Music_t; // lines 8-8
|
||||
struct JA_Sound_t; // lines 7-7
|
||||
#include <SDL3/SDL_audio.h> // for SDL_AudioFormat
|
||||
#include <SDL3/SDL_stdinc.h> // for Uint32, Uint8
|
||||
struct JA_Music_t; // lines 4-4
|
||||
struct JA_Sound_t; // lines 5-5
|
||||
|
||||
enum JA_Channel_state
|
||||
{
|
||||
|
||||
121
source/logo.cpp
121
source/logo.cpp
@@ -1,87 +1,112 @@
|
||||
#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"
|
||||
#include "mouse.h"
|
||||
#include "surface.h"
|
||||
#include "s_sprite.h"
|
||||
#include "global_inputs.h"
|
||||
|
||||
// Constructor de la clase Logo: inicializa los recursos necesarios
|
||||
Logo::Logo()
|
||||
{
|
||||
init();
|
||||
init();
|
||||
}
|
||||
|
||||
// Destructor de la clase Logo: libera los recursos utilizados
|
||||
Logo::~Logo()
|
||||
{
|
||||
close();
|
||||
close();
|
||||
}
|
||||
|
||||
// Método privado para inicializar los recursos del logotipo
|
||||
void Logo::init()
|
||||
{
|
||||
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
SDL_SetLogPriority(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_ERROR);
|
||||
// Configura las prioridades de los logs
|
||||
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
SDL_SetLogPriority(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_ERROR);
|
||||
|
||||
Screen::get()->init();
|
||||
logo_surface = std::make_shared<Surface>("jailgames.gif");
|
||||
logo_surface->scale(5);
|
||||
// Inicializa la pantalla
|
||||
Screen::get()->init();
|
||||
|
||||
logo_sprite = std::make_unique<SSprite>(logo_surface);
|
||||
logo_sprite->setPosition(
|
||||
(options.logo.width - logo_sprite->getWidth()) / 2,
|
||||
(options.logo.height - logo_sprite->getHeight()) / 2);
|
||||
// Carga la superficie del logotipo desde un archivo y la escala
|
||||
logo_surface = std::make_shared<Surface>("jailgames.gif");
|
||||
logo_surface->scale(5);
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Logo start");
|
||||
// Crea el sprite del logotipo y lo posiciona en el centro de la pantalla
|
||||
logo_sprite = std::make_unique<SSprite>(logo_surface);
|
||||
logo_sprite->setPosition(
|
||||
(options.logo.width - logo_sprite->getWidth()) / 2,
|
||||
(options.logo.height - logo_sprite->getHeight()) / 2);
|
||||
|
||||
// Log de inicio del logotipo
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Logo start");
|
||||
}
|
||||
|
||||
// Método privado para liberar los recursos del logotipo
|
||||
void Logo::close()
|
||||
{
|
||||
Screen::get()->destroy();
|
||||
// Destruye la pantalla
|
||||
Screen::get()->destroy();
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nBye!");
|
||||
SDL_Quit();
|
||||
// Log de finalización del logotipo
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nBye!");
|
||||
|
||||
// Finaliza SDL
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
// Método privado para manejar los eventos de entrada
|
||||
void Logo::checkEvents()
|
||||
{
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_EVENT_QUIT:
|
||||
options.logo.running = false;
|
||||
return;
|
||||
}
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) // Procesa todos los eventos en la cola
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_EVENT_QUIT: // Evento de salida (cerrar la ventana)
|
||||
options.logo.running = false; // Detiene el bucle principal
|
||||
return;
|
||||
}
|
||||
|
||||
globalInputs::check(event);
|
||||
Mouse::handleEvent(event);
|
||||
}
|
||||
// Maneja entradas globales y eventos del ratón
|
||||
globalInputs::check(event);
|
||||
Mouse::handleEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Método privado para actualizar el estado del logotipo
|
||||
void Logo::update()
|
||||
{
|
||||
if (SDL_GetTicks() - ticks > options.logo.speed)
|
||||
{
|
||||
ticks = SDL_GetTicks();
|
||||
// Comprueba si ha pasado suficiente tiempo para actualizar
|
||||
if (SDL_GetTicks() - ticks > options.logo.speed)
|
||||
{
|
||||
ticks = SDL_GetTicks(); // Actualiza el contador de ticks
|
||||
|
||||
Screen::get()->update();
|
||||
}
|
||||
// Actualiza la pantalla
|
||||
Screen::get()->update();
|
||||
}
|
||||
}
|
||||
|
||||
// Método privado para renderizar el logotipo en pantalla
|
||||
void Logo::render()
|
||||
{
|
||||
Screen::get()->start();
|
||||
logo_sprite->render();
|
||||
Screen::get()->render();
|
||||
Screen::get()->start(); // Inicia el proceso de renderizado
|
||||
logo_sprite->render(); // Renderiza el sprite del logotipo
|
||||
Screen::get()->render(); // Finaliza el renderizado
|
||||
}
|
||||
|
||||
// Método principal que ejecuta el ciclo de vida del logotipo
|
||||
int Logo::run()
|
||||
{
|
||||
while (options.logo.running)
|
||||
{
|
||||
update();
|
||||
checkEvents();
|
||||
render();
|
||||
}
|
||||
return 0;
|
||||
while (options.logo.running) // Bucle principal mientras el logotipo esté activo
|
||||
{
|
||||
update(); // Actualiza el estado del logotipo
|
||||
checkEvents(); // Maneja los eventos de entrada
|
||||
render(); // Renderiza el logotipo
|
||||
}
|
||||
return 0; // Devuelve 0 al finalizar
|
||||
}
|
||||
@@ -1,27 +1,28 @@
|
||||
#pragma once
|
||||
#pragma once // Evita inclusiones múltiples del archivo de encabezado
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <memory>
|
||||
#include "surface.h"
|
||||
#include "s_sprite.h"
|
||||
#include <SDL3/SDL_stdinc.h> // Incluye definiciones estándar de SDL, como Uint64
|
||||
#include <memory> // Proporciona soporte para punteros inteligentes (shared_ptr, unique_ptr)
|
||||
#include "s_sprite.h" // Declara la clase SSprite, utilizada para manejar sprites
|
||||
|
||||
class Surface; // Declaración adelantada de la clase Surface
|
||||
|
||||
// Clase Logo: Maneja la lógica principal de un logotipo animado o interactivo
|
||||
class Logo
|
||||
{
|
||||
|
||||
private:
|
||||
bool running = true;
|
||||
Uint64 ticks = 0;
|
||||
std::shared_ptr<Surface> logo_surface = nullptr;
|
||||
std::unique_ptr<SSprite> logo_sprite = nullptr;
|
||||
Uint64 ticks = 0; // Contador de ticks para medir el tiempo o controlar animaciones
|
||||
std::shared_ptr<Surface> logo_surface = nullptr; // Superficie del logotipo, compartida entre múltiples objetos
|
||||
std::unique_ptr<SSprite> logo_sprite = nullptr; // Sprite del logotipo, propiedad exclusiva de esta clase
|
||||
|
||||
void init();
|
||||
void close();
|
||||
void checkEvents();
|
||||
void update();
|
||||
void render();
|
||||
// Métodos privados para manejar el ciclo de vida y la lógica del logotipo
|
||||
void init(); // Inicializa los recursos necesarios para el logotipo
|
||||
void close(); // Libera los recursos utilizados por el logotipo
|
||||
void checkEvents(); // Maneja los eventos de entrada (teclado, ratón, etc.)
|
||||
void update(); // Actualiza el estado del logotipo (animaciones, lógica, etc.)
|
||||
void render(); // Renderiza el logotipo en pantalla
|
||||
|
||||
public:
|
||||
Logo();
|
||||
~Logo();
|
||||
int run();
|
||||
Logo(); // Constructor: Inicializa la clase Logo
|
||||
~Logo(); // Destructor: Limpia los recursos utilizados por la clase Logo
|
||||
int run(); // Método principal que ejecuta el ciclo de vida del logotipo
|
||||
};
|
||||
@@ -1,6 +1,5 @@
|
||||
#include <SDL3/SDL.h>
|
||||
#include <memory>
|
||||
#include "logo.h"
|
||||
#include <memory> // for make_unique, unique_ptr
|
||||
#include "logo.h" // for Logo
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
@@ -1,14 +1,4 @@
|
||||
#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
|
||||
Options options;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h> // Para Uint32
|
||||
#include <string> // Para string, basic_string
|
||||
#include "utils.h" // Para Color, Palette
|
||||
#include <algorithm>
|
||||
#include <SDL3/SDL_stdinc.h> // for Uint64
|
||||
#include <SDL3/SDL_surface.h> // for SDL_ScaleMode
|
||||
#include <algorithm> // for clamp
|
||||
#include <string> // for string, basic_string
|
||||
|
||||
// Constantes
|
||||
constexpr int DEFAULT_GAME_WIDTH = 480; // Ancho de la ventana por defecto
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <memory> // Para shared_ptr
|
||||
class Surface; // lines 5-5
|
||||
#include <SDL3/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||
#include <SDL3/SDL_stdinc.h> // for Uint8
|
||||
#include <memory> // for shared_ptr
|
||||
class Surface; // lines 5-5
|
||||
|
||||
// Clase SSprite
|
||||
class SSprite
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#include "screen.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <ctype.h> // Para toupper
|
||||
#include <algorithm> // Para max, min, transform
|
||||
#include <fstream> // Para basic_ostream, operator<<, endl, basic_...
|
||||
#include <iostream> // Para cerr
|
||||
#include <iterator> // Para istreambuf_iterator, operator==
|
||||
#include <string> // Para char_traits, string, operator+, operator==
|
||||
#include "mouse.h" // Para updateCursorVisibility
|
||||
#include "options.h" // Para Options, options, OptionsVideo, Border
|
||||
#include "surface.h" // Para Surface, readPalFile
|
||||
#include <SDL3/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL3/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL3/SDL_hints.h> // for SDL_SetHint, SDL_HINT_RENDER_DRIVER
|
||||
#include <SDL3/SDL_init.h> // for SDL_Init, SDL_INIT_VIDEO
|
||||
#include <SDL3/SDL_log.h> // for SDL_LogCategory, SDL_LogInfo, SDL_Lo...
|
||||
#include <SDL3/SDL_pixels.h> // for SDL_PixelFormat
|
||||
#include <algorithm> // for min, max
|
||||
#include <string> // for char_traits, operator+, to_string
|
||||
#include "mouse.h" // for updateCursorVisibility
|
||||
#include "options.h" // for Options, options, OptionsWindow, Opt...
|
||||
#include "surface.h" // for Surface, readPalFile
|
||||
|
||||
// [SINGLETON]
|
||||
Screen *Screen::screen_ = nullptr;
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <stddef.h> // Para size_t
|
||||
#include <memory> // Para shared_ptr, __shared_ptr_access
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include "utils.h" // Para Color
|
||||
#include "options.h"
|
||||
struct Surface;
|
||||
#include <SDL3/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||
#include <SDL3/SDL_stdinc.h> // for Uint8
|
||||
#include <SDL3/SDL_video.h> // for SDL_Window
|
||||
#include <memory> // for shared_ptr
|
||||
#include "options.h" // for Options, OptionsVideo, options
|
||||
#include "surface.h" // for Surface
|
||||
#include "utils.h" // for Color
|
||||
|
||||
class Screen
|
||||
{
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
// IWYU pragma: no_include <bits/std_abs.h>
|
||||
#include "surface.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <cmath> // Para abs
|
||||
#include <algorithm> // Para min, max, copy_n, fill
|
||||
#include <cstdint> // Para uint32_t
|
||||
#include <cstring> // Para memcpy, size_t
|
||||
#include <fstream> // Para basic_ifstream, basic_ostream, basic_ist...
|
||||
#include <iostream> // Para cerr
|
||||
#include <memory> // Para shared_ptr, __shared_ptr_access, default...
|
||||
#include <sstream> // Para basic_istringstream
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include <vector> // Para vector
|
||||
#include "gif.h" // Para Gif
|
||||
#include "screen.h" // Para Screen
|
||||
#include <SDL3/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL3/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <stdlib.h> // for abs
|
||||
#include <algorithm> // for min, max, copy_n, fill
|
||||
#include <cstdint> // for uint32_t
|
||||
#include <cstring> // for memcpy, size_t
|
||||
#include <fstream> // for basic_ifstream, basic_ostream, basic_ist...
|
||||
#include <iostream> // for cerr
|
||||
#include <memory> // for shared_ptr, __shared_ptr_access, default...
|
||||
#include <sstream> // for basic_istringstream
|
||||
#include <stdexcept> // for runtime_error
|
||||
#include <vector> // for vector
|
||||
#include "gif.h" // for Gif
|
||||
#include "screen.h" // for Screen
|
||||
#include "utils.h" // for printWithDots
|
||||
|
||||
// Carga una paleta desde un archivo .gif
|
||||
Palette loadPalette(const std::string &file_path)
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <array> // Para array
|
||||
#include <memory> // Para default_delete, shared_ptr, __shared_pt...
|
||||
#include <numeric> // Para iota
|
||||
#include <string> // Para string
|
||||
#include <utility> // Para move
|
||||
#include "utils.h" // Para PaletteColor
|
||||
#include <SDL3/SDL_rect.h> // for SDL_Rect, SDL_FRect
|
||||
#include <SDL3/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||
#include <SDL3/SDL_stdinc.h> // for Uint8, Uint16, Uint32
|
||||
#include <SDL3/SDL_surface.h> // for SDL_FlipMode
|
||||
#include <array> // for array
|
||||
#include <memory> // for default_delete, shared_ptr, __shared_p...
|
||||
#include <numeric> // for iota
|
||||
#include <stdexcept> // for invalid_argument
|
||||
#include <string> // for string
|
||||
#include <utility> // for move
|
||||
|
||||
// Alias
|
||||
using Palette = std::array<Uint32, 256>;
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
#include "utils.h"
|
||||
#include <stdlib.h> // Para abs
|
||||
#include <algorithm> // Para find, transform
|
||||
#include <cctype> // Para tolower
|
||||
#include <cmath> // Para round, abs
|
||||
#include <exception> // Para exception
|
||||
#include <filesystem> // Para path
|
||||
#include <iostream> // Para basic_ostream, cout, basic_ios, ios, endl
|
||||
#include <string> // Para basic_string, string, char_traits, allocator
|
||||
#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
|
||||
#include <stdlib.h> // for abs
|
||||
#include <algorithm> // for transform, find
|
||||
#include <cctype> // for tolower, toupper
|
||||
#include <cmath> // for round
|
||||
#include <exception> // for exception
|
||||
#include <filesystem> // for path
|
||||
#include <iostream> // for basic_ostream, cout, basic_ios, ios, endl
|
||||
#include <string> // for string, char_traits, allocator, operator==
|
||||
|
||||
// Calcula el cuadrado de la distancia entre dos puntos
|
||||
double distanceSquared(int x1, int y1, int x2, int y2)
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_Rect, SDL_Point
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include <SDL3/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||
#include <SDL3/SDL_stdinc.h> // for Uint8
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
|
||||
// Estructura para definir un circulo
|
||||
struct Circle
|
||||
|
||||
Reference in New Issue
Block a user