From edfe78f3b75f4cf305c888de22699b9934ba4df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Sun, 7 May 2023 09:39:52 +0200 Subject: [PATCH] =?UTF-8?q?A=C3=B1adida=20la=20clase=20Asset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index c1a6a07..4c4d2d2 100644 --- a/main.cpp +++ b/main.cpp @@ -10,10 +10,14 @@ Código fuente creado por JailDesigner #include "units/jail_audio.h" #include "units/text.h" #include "units/utils.h" +#include "units/asset.h" SDL_Event *event; SDL_Window *window; SDL_Renderer *renderer; +int ticks = 0; +int ticksSpeed = 15; +int counter = 0; int main(int argc, char *argv[]) { @@ -22,6 +26,19 @@ int main(int argc, char *argv[]) struct options_t *options = new options_t; options->gameWidth = 640; options->gameHeight = 480; + options->console = true; + + // Inicializa la lista de recursos + Asset *asset = new Asset(argv[0]); + asset->add("/data/music.ogg", t_music); + asset->add("/data/sound.wav", t_sound); + asset->add("/data/smb2.txt", t_font); + asset->add("/data/smb2.png", t_bitmap); + asset->setVerbose(options->console); + if (!asset->check()) + { + exit(EXIT_FAILURE); + } // Inicializa SDL y la ventana SDL_Init(SDL_INIT_EVERYTHING); @@ -29,6 +46,14 @@ int main(int argc, char *argv[]) if (window != nullptr) { renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); + if (renderer == nullptr) + { + exit(EXIT_FAILURE); + } + } + else + { + exit(EXIT_FAILURE); } event = new SDL_Event(); @@ -38,12 +63,12 @@ int main(int argc, char *argv[]) JA_Music_t *music; JA_Sound_t *peiv; - music = JA_LoadMusic("data/music.ogg"); - peiv = JA_LoadSound("data/sound.wav"); + music = JA_LoadMusic(asset->get("music.ogg").c_str()); + peiv = JA_LoadSound(asset->get("sound.wav").c_str()); int volume = 128; // Inicializa el texto - Text *text = new Text("data/smb2.txt", "data/smb2.png", renderer); + Text *text = new Text(asset->get("smb2.txt"), asset->get("smb2.png"), renderer); // Bucle principal // JA_PlayMusic(music, true); @@ -51,7 +76,7 @@ int main(int argc, char *argv[]) while (!should_exit) { - // Actualiza la lógica del programa + // Comprueba el teclado y los eventos while (SDL_PollEvent(event)) { if (event->type == SDL_QUIT) @@ -70,6 +95,16 @@ int main(int argc, char *argv[]) } } + // Actualiza la lógica del programa + if (SDL_GetTicks() - ticks > ticksSpeed) + { + // Actualiza la variable + ticks = SDL_GetTicks(); + + // Incrementa el contador + counter++; + } + // Dibuja en pantalla SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF); SDL_RenderClear(renderer); @@ -87,10 +122,15 @@ int main(int argc, char *argv[]) SDL_SetRenderDrawColor(renderer, color, 0x00, 0x00, 0xFF); SDL_RenderDrawLine(renderer, 0, i, options->gameWidth, i); } + // Escribe el texto text->writeCentered(options->gameWidth / 2, text->getCharacterSize(), "Jail Engine DEMO"); + // Vuelca el buffer en pantalla SDL_RenderPresent(renderer); } + // Finaliza el objeto con la lista de recuros + delete asset; + // Finaliza el texto delete text;