Sanejar codi

This commit is contained in:
2025-02-21 15:55:44 +01:00
parent c86a6496b3
commit debcc3409e
23 changed files with 375 additions and 281 deletions

View File

@@ -1,4 +1,4 @@
#include "gamestate_credits.h" #include "credits.h"
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND #include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_error.h> // Para SDL_GetError #include <SDL2/SDL_error.h> // Para SDL_GetError
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888 #include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888

View File

@@ -1,4 +1,4 @@
#include "gamestate_demo.h" #include "demo.h"
#include <SDL2/SDL_rect.h> // Para SDL_Rect #include <SDL2/SDL_rect.h> // Para SDL_Rect
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks #include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include <iostream> // Para basic_ostream, basic_ios, operator<<, cout #include <iostream> // Para basic_ostream, basic_ios, operator<<, cout

View File

@@ -1,41 +1,41 @@
#include "director.h" #include "director.h"
#include <SDL2/SDL.h> // Para SDL_Init, SDL_Quit, SDL_INIT_E... #include <SDL2/SDL.h> // Para SDL_Init, SDL_Quit, SDL_INIT_E...
#include <SDL2/SDL_audio.h> // Para AUDIO_S16 #include <SDL2/SDL_audio.h> // Para AUDIO_S16
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND #include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_error.h> // Para SDL_GetError #include <SDL2/SDL_error.h> // Para SDL_GetError
#include <SDL2/SDL_gamecontroller.h> // Para SDL_CONTROLLER_BUTTON_B, SDL_C... #include <SDL2/SDL_gamecontroller.h> // Para SDL_CONTROLLER_BUTTON_B, SDL_C...
#include <SDL2/SDL_hints.h> // Para SDL_SetHint, SDL_HINT_RENDER_D... #include <SDL2/SDL_hints.h> // Para SDL_SetHint, SDL_HINT_RENDER_D...
#include <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_A, SDL_SCANCODE_E... #include <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_A, SDL_SCANCODE_E...
#include <SDL2/SDL_stdinc.h> // Para Uint32 #include <SDL2/SDL_stdinc.h> // Para Uint32
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks #include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include <errno.h> // Para errno, EEXIST, EACCES, ENAMETO... #include <errno.h> // Para errno, EEXIST, EACCES, ENAMETO...
#include <stdio.h> // Para printf, perror #include <stdio.h> // Para printf, perror
#include <string.h> // Para strcmp #include <string.h> // Para strcmp
#include <sys/stat.h> // Para mkdir, stat, S_IRWXU #include <sys/stat.h> // Para mkdir, stat, S_IRWXU
#include <unistd.h> // Para getuid #include <unistd.h> // Para getuid
#include <cstdlib> // Para exit, EXIT_FAILURE, srand #include <cstdlib> // Para exit, EXIT_FAILURE, srand
#include <fstream> // Para basic_ofstream, basic_ifstream #include <fstream> // Para basic_ofstream, basic_ifstream
#include <iostream> // Para basic_ostream, operator<<, cout #include <iostream> // Para basic_ostream, operator<<, cout
#include <string> // Para basic_string, operator+, char_... #include <string> // Para basic_string, operator+, char_...
#include <vector> // Para vector #include <vector> // Para vector
#include <memory> #include <memory>
#include "asset.h" // Para Asset, assetType #include "asset.h" // Para Asset, assetType
#include "const.h" // Para SECTION_LOGO, SECTION_TITLE #include "const.h" // Para SECTION_LOGO, SECTION_TITLE
#include "debug.h" // Para Debug #include "debug.h" // Para Debug
#include "gamestate_credits.h" // Para Credits #include "credits.h" // Para Credits
#include "gamestate_demo.h" // Para Demo #include "demo.h" // Para Demo
#include "gamestate_ending.h" // Para Ending #include "ending.h" // Para Ending
#include "gamestate_ending2.h" // Para Ending2 #include "ending2.h" // Para Ending2
#include "gamestate_game.h" // Para Game #include "game.h" // Para Game
#include "gamestate_game_over.h" // Para GameOver #include "game_over.h" // Para GameOver
#include "gamestate_loading_screen.h" // Para LoadingScreen #include "loading_screen.h" // Para LoadingScreen
#include "gamestate_logo.h" // Para Logo #include "logo.h" // Para Logo
#include "gamestate_title.h" // Para Title #include "title.h" // Para Title
#include "input.h" // Para Input, inputs_e #include "input.h" // Para Input, inputs_e
#include "jail_audio.h" // Para JA_GetMusicState, JA_DeleteMusic #include "jail_audio.h" // Para JA_GetMusicState, JA_DeleteMusic
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "screen.h" // Para Screen, FILTER_NEAREST, FILTER... #include "screen.h" // Para Screen, FILTER_NEAREST, FILTER...
#include "utils.h" // Para options_t, section_t, op_notif... #include "utils.h" // Para options_t, section_t, op_notif...
#ifndef _WIN32 #ifndef _WIN32
#include <pwd.h> #include <pwd.h>

View File

@@ -1,39 +1,30 @@
#pragma once #pragma once
#include <SDL2/SDL_render.h> // Para SDL_Renderer #include <SDL2/SDL_render.h> // for SDL_Renderer
#include <SDL2/SDL_video.h> // Para SDL_Window #include <SDL2/SDL_video.h> // for SDL_Window
#include <string> // Para string, basic_string #include <string> // for string
class Asset; class Asset; // lines 6-6
class Credits; class Debug; // lines 8-8
class Debug; class Input; // lines 14-14
class Demo; class Resource; // lines 17-17
class Ending2; class Screen; // lines 18-18
class Ending; struct JA_Music_t; // lines 20-20
class Game; struct options_t; // lines 21-21
class GameOver; struct section_t; // lines 22-22
class Input;
class LoadingScreen;
class Logo;
class Resource;
class Screen;
class Title;
struct JA_Music_t;
struct options_t;
struct section_t;
class Director class Director
{ {
private: private:
// Objetos y punteros // Objetos y punteros
SDL_Window *window; // La ventana donde dibujamos SDL_Window *window; // La ventana donde dibujamos
SDL_Renderer *renderer; // El renderizador de la ventana SDL_Renderer *renderer; // El renderizador de la ventana
Screen *screen; // Objeto encargado de dibujar en pantalla Screen *screen; // Objeto encargado de dibujar en pantalla
Resource *resource; // Objeto con los recursos Resource *resource; // Objeto con los recursos
Asset *asset; // Objeto que gestiona todos los ficheros de recursos Asset *asset; // Objeto que gestiona todos los ficheros de recursos
Input *input; // Objeto Input para gestionar las entradas Input *input; // Objeto Input para gestionar las entradas
Debug *debug; // Objeto para getsionar la información de debug Debug *debug; // Objeto para getsionar la información de debug
struct options_t *options; // Variable con todas las opciones del programa struct options_t *options; // Variable con todas las opciones del programa
section_t *section; // Sección y subsección actual del programa; section_t *section; // Sección y subsección actual del programa;
// Variables // Variables
JA_Music_t *music; // Musica del titulo JA_Music_t *music; // Musica del titulo

View File

@@ -1,4 +1,4 @@
#include "gamestate_ending.h" #include "ending.h"
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND #include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_error.h> // Para SDL_GetError #include <SDL2/SDL_error.h> // Para SDL_GetError
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888 #include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888

View File

@@ -1,17 +1,18 @@
#include "gamestate_ending2.h" #include "ending2.h"
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND #include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks #include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <algorithm> // Para max, min, replace #include <algorithm> // for max, min, replace
#include "animatedsprite.h" // Para AnimatedSprite #include "animatedsprite.h" // for AnimatedSprite
#include "asset.h" // Para Asset #include "asset.h" // for Asset
#include "const.h" // Para GAMECANVAS_HEIGHT, GAMECANVAS_CENTER_X #include "const.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_CENTER_X
#include "input.h" // Para Input, REPEAT_FALSE, inputs_e #include "input.h" // for Input, REPEAT_FALSE, inputs_e
#include "jail_audio.h" // Para JA_SetVolume, JA_DeleteMusic, JA_Loa... #include "jail_audio.h" // for JA_SetVolume, JA_DeleteMusic, JA_Loa...
#include "movingsprite.h" // Para MovingSprite #include "movingsprite.h" // for MovingSprite
#include "resource.h" // Para Resource #include "resource.h" // for Resource
#include "screen.h" // Para Screen #include "screen.h" // for Screen
#include "text.h" // Para Text #include "text.h" // for Text
#include "texture.h" // Para Texture #include "texture.h" // for Texture
#include "utils.h" // for color_t, stringToColor, options_t
// Constructor // Constructor
Ending2::Ending2(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section) Ending2::Ending2(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section)

View File

@@ -1,19 +1,21 @@
#pragma once #pragma once
#include <SDL2/SDL_events.h> // Para SDL_Event #include <SDL2/SDL_events.h> // for SDL_Event
#include <SDL2/SDL_render.h> // Para SDL_Renderer #include <SDL2/SDL_render.h> // for SDL_Renderer
#include <SDL2/SDL_stdinc.h> // Para Uint32 #include <SDL2/SDL_stdinc.h> // for Uint32
#include <string> // Para string #include <string> // for string
#include <vector> // Para vector #include <vector> // for vector
#include "utils.h" // Para color_t class AnimatedSprite; // lines 9-9
class AnimatedSprite; class Asset; // lines 10-10
class Asset; class Input; // lines 11-11
class Input; class MovingSprite; // lines 12-12
class MovingSprite; class Resource; // lines 13-13
class Resource; class Screen; // lines 14-14
class Screen; class Text; // lines 15-15
class Text; struct JA_Music_t; // lines 16-16
struct JA_Music_t; struct color_t;
struct options_t;
struct section_t;
class Ending2 class Ending2
{ {

View File

@@ -1,26 +1,25 @@
#include "gamestate_game.h" #include "game.h"
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND #include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
#include <SDL2/SDL_error.h> // Para SDL_GetError #include <SDL2/SDL_error.h> // for SDL_GetError
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888 #include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_A, SDL_SCANCODE_D, SDL_... #include <SDL2/SDL_scancode.h> // for SDL_SCANCODE_A, SDL_SCANCODE_D, SDL_...
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks #include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <iostream> // Para char_traits, basic_ostream, operator<< #include <iostream> // for basic_ostream, operator<<, cout, endl
#include <vector> // Para vector #include <vector> // for vector
#include "asset.h" // Para Asset #include "asset.h" // for Asset
#include "cheevos.h" // Para Cheevos #include "cheevos.h" // for Cheevos
#include "const.h" // Para PLAY_AREA_HEIGHT, GAMECANVAS_WIDTH #include "const.h" // for PLAY_AREA_HEIGHT, GAMECANVAS_WIDTH
#include "debug.h" // Para Debug #include "debug.h" // for Debug
#include "input.h" // Para Input, REPEAT_FALSE, inputs_e #include "input.h" // for Input, REPEAT_FALSE, inputs_e
#include "item.h" // Para item_t #include "item_tracker.h" // for ItemTracker
#include "item_tracker.h" // Para ItemTracker #include "jail_audio.h" // for JA_PauseMusic, JA_PlaySound, JA_Resu...
#include "jail_audio.h" // Para JA_PauseMusic, JA_PlaySound, JA_Resu... #include "resource.h" // for Resource, res_room_t
#include "resource.h" // Para res_room_t, Resource #include "room.h" // for Room, room_t
#include "room.h" // Para Room, room_t #include "room_tracker.h" // for RoomTracker
#include "room_tracker.h" // Para RoomTracker #include "screen.h" // for Screen
#include "screen.h" // Para Screen #include "stats.h" // for Stats
#include "stats.h" // Para Stats #include "text.h" // for Text, TXT_CENTER, TXT_COLOR
#include "text.h" // Para Text, TXT_CENTER, TXT_COLOR #include "utils.h" // for options_t, cheat_t, stringToColor
#include "utils.h" // Para options_t, color_t, cheat_t, stringT...
// Constructor // Constructor
Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, section_t *section, Debug *debug) Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, section_t *section, Debug *debug)

View File

@@ -1,4 +1,4 @@
#include "gamestate_game_over.h" #include "game_over.h"
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks #include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include <algorithm> // Para min, max #include <algorithm> // Para min, max
#include <string> // Para basic_string, operator+, to_string, char... #include <string> // Para basic_string, operator+, to_string, char...

View File

@@ -1,41 +1,47 @@
#include "jail_audio.h" #include "jail_audio.h"
#include "stb_vorbis.c" #include <SDL2/SDL_rwops.h> // for SDL_RWFromMem
#include <SDL2/SDL.h> #include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <stdio.h> #include <stdint.h> // for uint8_t, uint32_t
#include <stdio.h> // for NULL, fseek, fclose, fopen, fread, ftell
#include <stdlib.h> // for free, malloc
#include "stb_vorbis.c" // for stb_vorbis_decode_memory
constexpr int JA_MAX_SIMULTANEOUS_CHANNELS = 20; constexpr int JA_MAX_SIMULTANEOUS_CHANNELS = 20;
struct JA_Sound_t { struct JA_Sound_t
Uint32 length {0}; {
Uint8* buffer {NULL}; Uint32 length{0};
Uint8 *buffer{NULL};
}; };
struct JA_Channel_t { struct JA_Channel_t
JA_Sound_t *sound; {
int pos {0}; JA_Sound_t *sound;
int times {0}; int pos{0};
JA_Channel_state state { JA_CHANNEL_FREE }; int times{0};
JA_Channel_state state{JA_CHANNEL_FREE};
}; };
struct JA_Music_t { struct JA_Music_t
int samples {0}; {
Uint32 length {0}; int samples{0};
int pos {0}; Uint32 length{0};
int times {0}; int pos{0};
short* output {NULL}; int times{0};
JA_Music_state state {JA_MUSIC_INVALID}; short *output{NULL};
JA_Music_state state{JA_MUSIC_INVALID};
}; };
JA_Music_t *current_music{NULL}; JA_Music_t *current_music{NULL};
JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS]; JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS];
int JA_freq {48000}; int JA_freq{48000};
SDL_AudioFormat JA_format {AUDIO_S16}; SDL_AudioFormat JA_format{AUDIO_S16};
Uint8 JA_channels {2}; Uint8 JA_channels{2};
int JA_musicVolume = 128; int JA_musicVolume = 128;
int JA_soundVolume = 64; int JA_soundVolume = 64;
bool JA_musicEnabled = true; bool JA_musicEnabled = true;
bool JA_soundEnabled = true; bool JA_soundEnabled = true;
SDL_AudioDeviceID sdlAudioDevice = 0; SDL_AudioDeviceID sdlAudioDevice = 0;
bool fading = false; bool fading = false;
@@ -43,49 +49,67 @@ int fade_start_time;
int fade_duration; int fade_duration;
int fade_initial_volume; int fade_initial_volume;
void audioCallback(void * userdata, uint8_t * stream, int len) { void audioCallback(void *userdata, uint8_t *stream, int len)
{
SDL_memset(stream, 0, len); SDL_memset(stream, 0, len);
if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING) { if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING)
{
int volume = JA_musicVolume; int volume = JA_musicVolume;
if (fading) { if (fading)
{
int time = SDL_GetTicks(); int time = SDL_GetTicks();
if (time > (fade_start_time+fade_duration)) { if (time > (fade_start_time + fade_duration))
{
fading = false; fading = false;
current_music->pos = 0; current_music->pos = 0;
current_music->state = JA_MUSIC_STOPPED; current_music->state = JA_MUSIC_STOPPED;
volume = 0; volume = 0;
} else { }
else
{
const int time_passed = time - fade_start_time; const int time_passed = time - fade_start_time;
const float percent = (float)time_passed / (float)fade_duration; const float percent = (float)time_passed / (float)fade_duration;
volume = JA_musicVolume * (1.0 - percent); volume = JA_musicVolume * (1.0 - percent);
} }
} }
const int size = SDL_min(len, current_music->length - current_music->pos); const int size = SDL_min(len, current_music->length - current_music->pos);
SDL_MixAudioFormat(stream, (Uint8*)(current_music->output)+current_music->pos, AUDIO_S16, size, volume); SDL_MixAudioFormat(stream, (Uint8 *)(current_music->output) + current_music->pos, AUDIO_S16, size, volume);
current_music->pos += size; current_music->pos += size;
if (size < len) { if (size < len)
if (current_music->times != 0) { {
SDL_MixAudioFormat(stream+size, (Uint8*)current_music->output, AUDIO_S16, len-size, volume); if (current_music->times != 0)
current_music->pos = len-size; {
if (current_music->times > 0) current_music->times--; SDL_MixAudioFormat(stream + size, (Uint8 *)current_music->output, AUDIO_S16, len - size, volume);
} else { current_music->pos = len - size;
if (current_music->times > 0)
current_music->times--;
}
else
{
current_music->pos = 0; current_music->pos = 0;
current_music->state = JA_MUSIC_STOPPED; current_music->state = JA_MUSIC_STOPPED;
} }
} }
} }
// Mixar els channels mi amol // Mixar els channels mi amol
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) { for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
if (channels[i].state == JA_CHANNEL_PLAYING) { {
if (channels[i].state == JA_CHANNEL_PLAYING)
{
const int size = SDL_min(len, channels[i].sound->length - channels[i].pos); const int size = SDL_min(len, channels[i].sound->length - channels[i].pos);
SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, JA_soundVolume); SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, JA_soundVolume);
channels[i].pos += size; channels[i].pos += size;
if (size < len) { if (size < len)
if (channels[i].times != 0) { {
SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, JA_soundVolume); if (channels[i].times != 0)
channels[i].pos = len-size; {
if (channels[i].times > 0) channels[i].times--; SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len - size, JA_soundVolume);
} else { channels[i].pos = len - size;
if (channels[i].times > 0)
channels[i].times--;
}
else
{
JA_StopChannel(i); JA_StopChannel(i);
} }
} }
@@ -99,18 +123,21 @@ void JA_Init(const int freq, const SDL_AudioFormat format, const int channels)
JA_format = format; JA_format = format;
JA_channels = channels; JA_channels = channels;
SDL_AudioSpec audioSpec{JA_freq, JA_format, JA_channels, 0, 1024, 0, 0, audioCallback, NULL}; SDL_AudioSpec audioSpec{JA_freq, JA_format, JA_channels, 0, 1024, 0, 0, audioCallback, NULL};
if (sdlAudioDevice != 0) SDL_CloseAudioDevice(sdlAudioDevice); if (sdlAudioDevice != 0)
SDL_CloseAudioDevice(sdlAudioDevice);
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0); sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
SDL_PauseAudioDevice(sdlAudioDevice, 0); SDL_PauseAudioDevice(sdlAudioDevice, 0);
} }
void JA_Quit() { void JA_Quit()
{
SDL_PauseAudioDevice(sdlAudioDevice, 1); SDL_PauseAudioDevice(sdlAudioDevice, 1);
if (sdlAudioDevice != 0) SDL_CloseAudioDevice(sdlAudioDevice); if (sdlAudioDevice != 0)
SDL_CloseAudioDevice(sdlAudioDevice);
sdlAudioDevice = 0; sdlAudioDevice = 0;
} }
JA_Music_t *JA_LoadMusic(Uint8* buffer, Uint32 length) JA_Music_t *JA_LoadMusic(Uint8 *buffer, Uint32 length)
{ {
int chan, samplerate; int chan, samplerate;
JA_Music_t *music = new JA_Music_t(); JA_Music_t *music = new JA_Music_t();
@@ -119,14 +146,15 @@ JA_Music_t *JA_LoadMusic(Uint8* buffer, Uint32 length)
SDL_AudioCVT cvt; SDL_AudioCVT cvt;
SDL_BuildAudioCVT(&cvt, AUDIO_S16, chan, samplerate, JA_format, JA_channels, JA_freq); SDL_BuildAudioCVT(&cvt, AUDIO_S16, chan, samplerate, JA_format, JA_channels, JA_freq);
if (cvt.needed) { if (cvt.needed)
{
cvt.len = music->samples * chan * 2; cvt.len = music->samples * chan * 2;
music->length = cvt.len; music->length = cvt.len;
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult); cvt.buf = (Uint8 *)SDL_malloc(cvt.len * cvt.len_mult);
SDL_memcpy(cvt.buf, music->output, cvt.len); SDL_memcpy(cvt.buf, music->output, cvt.len);
SDL_ConvertAudio(&cvt); SDL_ConvertAudio(&cvt);
free(music->output); free(music->output);
music->output = (short*)cvt.buf; music->output = (short *)cvt.buf;
} }
music->length = music->samples * chan * 2; music->length = music->samples * chan * 2;
music->pos = 0; music->pos = 0;
@@ -135,15 +163,16 @@ JA_Music_t *JA_LoadMusic(Uint8* buffer, Uint32 length)
return music; return music;
} }
JA_Music_t *JA_LoadMusic(const char* filename) JA_Music_t *JA_LoadMusic(const char *filename)
{ {
// [RZC 28/08/22] Carreguem primer el arxiu en memòria i després el descomprimim. Es algo més rapid. // [RZC 28/08/22] Carreguem primer el arxiu en memòria i després el descomprimim. Es algo més rapid.
FILE *f = fopen(filename, "rb"); FILE *f = fopen(filename, "rb");
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
long fsize = ftell(f); long fsize = ftell(f);
fseek(f, 0, SEEK_SET); fseek(f, 0, SEEK_SET);
Uint8 *buffer = (Uint8*)malloc(fsize + 1); Uint8 *buffer = (Uint8 *)malloc(fsize + 1);
if (fread(buffer, fsize, 1, f)!=1) return NULL; if (fread(buffer, fsize, 1, f) != 1)
return NULL;
fclose(f); fclose(f);
JA_Music_t *music = JA_LoadMusic(buffer, fsize); JA_Music_t *music = JA_LoadMusic(buffer, fsize);
@@ -155,9 +184,11 @@ JA_Music_t *JA_LoadMusic(const char* filename)
void JA_PlayMusic(JA_Music_t *music, const int loop) void JA_PlayMusic(JA_Music_t *music, const int loop)
{ {
if (!JA_musicEnabled) return; if (!JA_musicEnabled)
return;
if (current_music != NULL) { if (current_music != NULL)
{
current_music->pos = 0; current_music->pos = 0;
current_music->state = JA_MUSIC_STOPPED; current_music->state = JA_MUSIC_STOPPED;
} }
@@ -169,33 +200,41 @@ void JA_PlayMusic(JA_Music_t *music, const int loop)
void JA_PauseMusic() void JA_PauseMusic()
{ {
if (!JA_musicEnabled) return; if (!JA_musicEnabled)
return;
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return; if (current_music == NULL || current_music->state == JA_MUSIC_INVALID)
return;
current_music->state = JA_MUSIC_PAUSED; current_music->state = JA_MUSIC_PAUSED;
} }
void JA_ResumeMusic() void JA_ResumeMusic()
{ {
if (!JA_musicEnabled) return; if (!JA_musicEnabled)
return;
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return; if (current_music == NULL || current_music->state == JA_MUSIC_INVALID)
return;
current_music->state = JA_MUSIC_PLAYING; current_music->state = JA_MUSIC_PLAYING;
} }
void JA_StopMusic() void JA_StopMusic()
{ {
if (!JA_musicEnabled) return; if (!JA_musicEnabled)
return;
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return; if (current_music == NULL || current_music->state == JA_MUSIC_INVALID)
return;
current_music->pos = 0; current_music->pos = 0;
current_music->state = JA_MUSIC_STOPPED; current_music->state = JA_MUSIC_STOPPED;
} }
void JA_FadeOutMusic(const int milliseconds) void JA_FadeOutMusic(const int milliseconds)
{ {
if (!JA_musicEnabled) return; if (!JA_musicEnabled)
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return; return;
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID)
return;
fading = true; fading = true;
fade_start_time = SDL_GetTicks(); fade_start_time = SDL_GetTicks();
@@ -203,64 +242,71 @@ void JA_FadeOutMusic(const int milliseconds)
fade_initial_volume = JA_musicVolume; fade_initial_volume = JA_musicVolume;
} }
JA_Music_state JA_GetMusicState() { JA_Music_state JA_GetMusicState()
if (!JA_musicEnabled) return JA_MUSIC_DISABLED; {
if (!JA_musicEnabled)
return JA_MUSIC_DISABLED;
if (current_music == NULL) return JA_MUSIC_INVALID; if (current_music == NULL)
return JA_MUSIC_INVALID;
return current_music->state; return current_music->state;
} }
void JA_DeleteMusic(JA_Music_t *music) { void JA_DeleteMusic(JA_Music_t *music)
if (current_music == music) current_music = NULL; {
if (current_music == music)
current_music = NULL;
free(music->output); free(music->output);
delete music; delete music;
} }
int JA_SetMusicVolume(int volume) int JA_SetMusicVolume(int volume)
{ {
JA_musicVolume = volume > 128 ? 128 : volume < 0 ? 0 : volume; JA_musicVolume = volume > 128 ? 128 : volume < 0 ? 0
: volume;
return JA_musicVolume; return JA_musicVolume;
} }
void JA_SetMusicPosition(float value) void JA_SetMusicPosition(float value)
{ {
if (!current_music) return; if (!current_music)
return;
current_music->pos = value * JA_freq; current_music->pos = value * JA_freq;
} }
float JA_GetMusicPosition() float JA_GetMusicPosition()
{ {
if (!current_music) return 0; if (!current_music)
return float(current_music->pos)/float(JA_freq); return 0;
return float(current_music->pos) / float(JA_freq);
} }
void JA_EnableMusic(const bool value) void JA_EnableMusic(const bool value)
{ {
if (!value && current_music != NULL && current_music->state==JA_MUSIC_PLAYING) JA_StopMusic(); if (!value && current_music != NULL && current_music->state == JA_MUSIC_PLAYING)
JA_StopMusic();
JA_musicEnabled = value; JA_musicEnabled = value;
} }
JA_Sound_t *JA_NewSound(Uint8 *buffer, Uint32 length)
{
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length) {
JA_Sound_t *sound = new JA_Sound_t(); JA_Sound_t *sound = new JA_Sound_t();
sound->buffer = buffer; sound->buffer = buffer;
sound->length = length; sound->length = length;
return sound; return sound;
} }
JA_Sound_t *JA_LoadSound(uint8_t* buffer, uint32_t size) { JA_Sound_t *JA_LoadSound(uint8_t *buffer, uint32_t size)
{
JA_Sound_t *sound = new JA_Sound_t(); JA_Sound_t *sound = new JA_Sound_t();
SDL_AudioSpec wavSpec; SDL_AudioSpec wavSpec;
SDL_LoadWAV_RW(SDL_RWFromMem(buffer, size),1, &wavSpec, &sound->buffer, &sound->length); SDL_LoadWAV_RW(SDL_RWFromMem(buffer, size), 1, &wavSpec, &sound->buffer, &sound->length);
SDL_AudioCVT cvt; SDL_AudioCVT cvt;
SDL_BuildAudioCVT(&cvt, wavSpec.format, wavSpec.channels, wavSpec.freq, JA_format, JA_channels, JA_freq); SDL_BuildAudioCVT(&cvt, wavSpec.format, wavSpec.channels, wavSpec.freq, JA_format, JA_channels, JA_freq);
cvt.len = sound->length; cvt.len = sound->length;
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult); cvt.buf = (Uint8 *)SDL_malloc(cvt.len * cvt.len_mult);
SDL_memcpy(cvt.buf, sound->buffer, sound->length); SDL_memcpy(cvt.buf, sound->buffer, sound->length);
SDL_ConvertAudio(&cvt); SDL_ConvertAudio(&cvt);
SDL_FreeWAV(sound->buffer); SDL_FreeWAV(sound->buffer);
@@ -270,7 +316,8 @@ JA_Sound_t *JA_LoadSound(uint8_t* buffer, uint32_t size) {
return sound; return sound;
} }
JA_Sound_t *JA_LoadSound(const char* filename) { JA_Sound_t *JA_LoadSound(const char *filename)
{
JA_Sound_t *sound = new JA_Sound_t(); JA_Sound_t *sound = new JA_Sound_t();
SDL_AudioSpec wavSpec; SDL_AudioSpec wavSpec;
SDL_LoadWAV(filename, &wavSpec, &sound->buffer, &sound->length); SDL_LoadWAV(filename, &wavSpec, &sound->buffer, &sound->length);
@@ -278,7 +325,7 @@ JA_Sound_t *JA_LoadSound(const char* filename) {
SDL_AudioCVT cvt; SDL_AudioCVT cvt;
SDL_BuildAudioCVT(&cvt, wavSpec.format, wavSpec.channels, wavSpec.freq, JA_format, JA_channels, JA_freq); SDL_BuildAudioCVT(&cvt, wavSpec.format, wavSpec.channels, wavSpec.freq, JA_format, JA_channels, JA_freq);
cvt.len = sound->length; cvt.len = sound->length;
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult); cvt.buf = (Uint8 *)SDL_malloc(cvt.len * cvt.len_mult);
SDL_memcpy(cvt.buf, sound->buffer, sound->length); SDL_memcpy(cvt.buf, sound->buffer, sound->length);
SDL_ConvertAudio(&cvt); SDL_ConvertAudio(&cvt);
SDL_FreeWAV(sound->buffer); SDL_FreeWAV(sound->buffer);
@@ -290,11 +337,16 @@ JA_Sound_t *JA_LoadSound(const char* filename) {
int JA_PlaySound(JA_Sound_t *sound, const int loop) int JA_PlaySound(JA_Sound_t *sound, const int loop)
{ {
if (!JA_soundEnabled) return -1; if (!JA_soundEnabled)
return -1;
int channel = 0; int channel = 0;
while (channel < JA_MAX_SIMULTANEOUS_CHANNELS && channels[channel].state != JA_CHANNEL_FREE) { channel++; } while (channel < JA_MAX_SIMULTANEOUS_CHANNELS && channels[channel].state != JA_CHANNEL_FREE)
if (channel == JA_MAX_SIMULTANEOUS_CHANNELS) channel = 0; {
channel++;
}
if (channel == JA_MAX_SIMULTANEOUS_CHANNELS)
channel = 0;
channels[channel].sound = sound; channels[channel].sound = sound;
channels[channel].times = loop; channels[channel].times = loop;
@@ -305,9 +357,11 @@ int JA_PlaySound(JA_Sound_t *sound, const int loop)
int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop) int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop)
{ {
if (!JA_soundEnabled) return -1; if (!JA_soundEnabled)
return -1;
if (channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return -1; if (channel >= JA_MAX_SIMULTANEOUS_CHANNELS)
return -1;
channels[channel].sound = sound; channels[channel].sound = sound;
channels[channel].times = loop; channels[channel].times = loop;
@@ -318,8 +372,10 @@ int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop)
void JA_DeleteSound(JA_Sound_t *sound) void JA_DeleteSound(JA_Sound_t *sound)
{ {
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) { for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
if (channels[i].sound == sound) JA_StopChannel(i); {
if (channels[i].sound == sound)
JA_StopChannel(i);
} }
SDL_free(sound->buffer); SDL_free(sound->buffer);
delete sound; delete sound;
@@ -327,41 +383,60 @@ void JA_DeleteSound(JA_Sound_t *sound)
void JA_PauseChannel(const int channel) void JA_PauseChannel(const int channel)
{ {
if (!JA_soundEnabled) return; if (!JA_soundEnabled)
return;
if (channel == -1) { if (channel == -1)
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) { {
if (channels[i].state == JA_CHANNEL_PLAYING) channels[i].state = JA_CHANNEL_PAUSED; for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
{
if (channels[i].state == JA_CHANNEL_PLAYING)
channels[i].state = JA_CHANNEL_PAUSED;
} }
} else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) { }
if (channels[channel].state == JA_CHANNEL_PLAYING) channels[channel].state = JA_CHANNEL_PAUSED; else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS)
{
if (channels[channel].state == JA_CHANNEL_PLAYING)
channels[channel].state = JA_CHANNEL_PAUSED;
} }
} }
void JA_ResumeChannel(const int channel) void JA_ResumeChannel(const int channel)
{ {
if (!JA_soundEnabled) return; if (!JA_soundEnabled)
return;
if (channel == -1) { if (channel == -1)
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) { {
if (channels[i].state == JA_CHANNEL_PAUSED) channels[i].state = JA_CHANNEL_PLAYING; for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
{
if (channels[i].state == JA_CHANNEL_PAUSED)
channels[i].state = JA_CHANNEL_PLAYING;
} }
} else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) { }
if (channels[channel].state == JA_CHANNEL_PAUSED) channels[channel].state = JA_CHANNEL_PLAYING; else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS)
{
if (channels[channel].state == JA_CHANNEL_PAUSED)
channels[channel].state = JA_CHANNEL_PLAYING;
} }
} }
void JA_StopChannel(const int channel) void JA_StopChannel(const int channel)
{ {
if (!JA_soundEnabled) return; if (!JA_soundEnabled)
return;
if (channel == -1) { if (channel == -1)
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) { {
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
{
channels[i].state = JA_CHANNEL_FREE; channels[i].state = JA_CHANNEL_FREE;
channels[i].pos = 0; channels[i].pos = 0;
channels[i].sound = NULL; channels[i].sound = NULL;
} }
} else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) { }
else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS)
{
channels[channel].state = JA_CHANNEL_FREE; channels[channel].state = JA_CHANNEL_FREE;
channels[channel].pos = 0; channels[channel].pos = 0;
channels[channel].sound = NULL; channels[channel].sound = NULL;
@@ -370,15 +445,18 @@ void JA_StopChannel(const int channel)
JA_Channel_state JA_GetChannelState(const int channel) JA_Channel_state JA_GetChannelState(const int channel)
{ {
if (!JA_soundEnabled) return JA_SOUND_DISABLED; if (!JA_soundEnabled)
return JA_SOUND_DISABLED;
if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return JA_CHANNEL_INVALID; if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS)
return JA_CHANNEL_INVALID;
return channels[channel].state; return channels[channel].state;
} }
int JA_SetSoundVolume(int volume) int JA_SetSoundVolume(int volume)
{ {
JA_soundVolume = volume > 128 ? 128 : volume < 0 ? 0 : volume; JA_soundVolume = volume > 128 ? 128 : volume < 0 ? 0
: volume;
return JA_soundVolume; return JA_soundVolume;
} }
@@ -386,14 +464,16 @@ void JA_EnableSound(const bool value)
{ {
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
{ {
if (channels[i].state == JA_CHANNEL_PLAYING) JA_StopChannel(i); if (channels[i].state == JA_CHANNEL_PLAYING)
JA_StopChannel(i);
} }
JA_soundEnabled = value; JA_soundEnabled = value;
} }
int JA_SetVolume(int volume) int JA_SetVolume(int volume)
{ {
JA_musicVolume = volume > 128 ? 128 : volume < 0 ? 0 : volume; JA_musicVolume = volume > 128 ? 128 : volume < 0 ? 0
JA_soundVolume = JA_musicVolume/2; : volume;
JA_soundVolume = JA_musicVolume / 2;
return JA_musicVolume; return JA_musicVolume;
} }

View File

@@ -1,8 +1,26 @@
#pragma once #pragma once
#include <SDL2/SDL.h>
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED, JA_SOUND_DISABLED }; #include <SDL2/SDL_audio.h> // for SDL_AudioFormat
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED, JA_MUSIC_DISABLED }; #include <SDL2/SDL_stdinc.h> // for Uint32, Uint8
struct JA_Music_t; // lines 8-8
struct JA_Sound_t; // lines 7-7
enum JA_Channel_state
{
JA_CHANNEL_INVALID,
JA_CHANNEL_FREE,
JA_CHANNEL_PLAYING,
JA_CHANNEL_PAUSED,
JA_SOUND_DISABLED
};
enum JA_Music_state
{
JA_MUSIC_INVALID,
JA_MUSIC_PLAYING,
JA_MUSIC_PAUSED,
JA_MUSIC_STOPPED,
JA_MUSIC_DISABLED
};
struct JA_Sound_t; struct JA_Sound_t;
struct JA_Music_t; struct JA_Music_t;
@@ -10,8 +28,8 @@ struct JA_Music_t;
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels); void JA_Init(const int freq, const SDL_AudioFormat format, const int channels);
void JA_Quit(); void JA_Quit();
JA_Music_t *JA_LoadMusic(const char* filename); JA_Music_t *JA_LoadMusic(const char *filename);
JA_Music_t *JA_LoadMusic(Uint8* buffer, Uint32 length); JA_Music_t *JA_LoadMusic(Uint8 *buffer, Uint32 length);
void JA_PlayMusic(JA_Music_t *music, const int loop = -1); void JA_PlayMusic(JA_Music_t *music, const int loop = -1);
void JA_PauseMusic(); void JA_PauseMusic();
void JA_ResumeMusic(); void JA_ResumeMusic();
@@ -24,9 +42,9 @@ void JA_SetMusicPosition(float value);
float JA_GetMusicPosition(); float JA_GetMusicPosition();
void JA_EnableMusic(const bool value); void JA_EnableMusic(const bool value);
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length); JA_Sound_t *JA_NewSound(Uint8 *buffer, Uint32 length);
JA_Sound_t *JA_LoadSound(Uint8* buffer, Uint32 length); JA_Sound_t *JA_LoadSound(Uint8 *buffer, Uint32 length);
JA_Sound_t *JA_LoadSound(const char* filename); JA_Sound_t *JA_LoadSound(const char *filename);
int JA_PlaySound(JA_Sound_t *sound, const int loop = 0); int JA_PlaySound(JA_Sound_t *sound, const int loop = 0);
int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop = 0); int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop = 0);
void JA_PauseChannel(const int channel); void JA_PauseChannel(const int channel);

View File

@@ -1,16 +1,15 @@
#include "gamestate_loading_screen.h" #include "loading_screen.h"
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks #include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <stdlib.h> // Para rand #include <stdlib.h> // for rand
#include <string> // Para basic_string #include "asset.h" // for Asset
#include "asset.h" // Para Asset #include "const.h" // for SECTION_LOADING_SCREEN, SECTION_QUIT
#include "const.h" // Para SECTION_LOADING_SCREEN, SECTION_QUIT #include "input.h" // for Input, REPEAT_FALSE, inputs_e
#include "input.h" // Para Input, REPEAT_FALSE, inputs_e #include "jail_audio.h" // for JA_DeleteMusic, JA_LoadMusic, JA_PlayMusic
#include "jail_audio.h" // Para JA_DeleteMusic, JA_LoadMusic, JA_PlayMusic #include "resource.h" // for Resource
#include "resource.h" // Para Resource #include "screen.h" // for Screen
#include "screen.h" // Para Screen #include "sprite.h" // for Sprite
#include "sprite.h" // Para Sprite #include "texture.h" // for Texture
#include "texture.h" // Para Texture #include "utils.h" // for options_t, section_t, color_t, stringToC...
#include "utils.h" // Para options_t, color_t, section_t, stringToC...
// Constructor // Constructor
LoadingScreen::LoadingScreen(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section) LoadingScreen::LoadingScreen(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section)

View File

@@ -1,14 +1,15 @@
#include "gamestate_logo.h" #include "logo.h"
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks #include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <string> // Para basic_string, string #include <string> // for basic_string, string
#include "const.h" // Para SECTION_LOGO, SECTION_TITLE, SUBSECTION_... #include "const.h" // for SECTION_LOGO, SECTION_TITLE, SUBSECTION_...
#include "input.h" // Para Input, REPEAT_FALSE, inputs_e #include "input.h" // for Input, REPEAT_FALSE, inputs_e
#include "jail_audio.h" // Para JA_StopMusic #include "jail_audio.h" // for JA_StopMusic
#include "resource.h" // Para Resource #include "resource.h" // for Resource
#include "screen.h" // Para Screen #include "screen.h" // for Screen
#include "sprite.h" // Para Sprite #include "sprite.h" // for Sprite
#include "texture.h" // Para Texture #include "texture.h" // for Texture
class Asset; #include "utils.h" // for color_t, section_t, options_t, stringToC...
class Asset; // lines 11-11
// Constructor // Constructor
Logo::Logo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section) Logo::Logo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section)

View File

@@ -1,16 +1,18 @@
#pragma once #pragma once
#include <SDL2/SDL_events.h> // Para SDL_Event #include <SDL2/SDL_events.h> // for SDL_Event
#include <SDL2/SDL_render.h> // Para SDL_Renderer #include <SDL2/SDL_render.h> // for SDL_Renderer
#include <SDL2/SDL_stdinc.h> // Para Uint32 #include <SDL2/SDL_stdinc.h> // for Uint32
#include <vector> // Para vector #include <vector> // for vector
#include "utils.h" // Para color_t class Asset; // lines 8-8
class Asset; class Input; // lines 9-9
class Input; class Resource; // lines 10-10
class Resource; class Screen; // lines 11-11
class Screen; class Sprite; // lines 12-12
class Sprite; class Texture; // lines 13-13
class Texture; struct color_t;
struct options_t;
struct section_t;
class Logo class Logo
{ {

View File

@@ -1,3 +1,4 @@
// IWYU pragma: no_include <bits/std_abs.h>
#include "player.h" #include "player.h"
#include <stdlib.h> // Para rand #include <stdlib.h> // Para rand
#include <algorithm> // Para max, min #include <algorithm> // Para max, min

View File

@@ -1,4 +1,4 @@
#include "gamestate_title.h" #include "title.h"
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND #include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_error.h> // Para SDL_GetError #include <SDL2/SDL_error.h> // Para SDL_GetError
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888 #include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888