From 2425ab51424108d7160d783e2d6d6b3e4ac3319c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Tue, 23 Aug 2022 17:03:10 +0200 Subject: [PATCH] =?UTF-8?q?A=C3=B1adida=20m=C3=BAsica=20al=20titulo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../music/{music_menu.ogg => music_title.ogg} | Bin source/game.cpp | 25 ++++++++---------- source/game.h | 3 --- source/prog.cpp | 4 ++- source/title.cpp | 11 +++++++- source/title.h | 1 + 6 files changed, 25 insertions(+), 19 deletions(-) rename data/music/{music_menu.ogg => music_title.ogg} (100%) diff --git a/data/music/music_menu.ogg b/data/music/music_title.ogg similarity index 100% rename from data/music/music_menu.ogg rename to data/music/music_title.ogg diff --git a/source/game.cpp b/source/game.cpp index 0da74b3..6061f13 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -3,16 +3,27 @@ // Constructor Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input) { + // Copia punteros this->renderer = renderer; this->asset = asset; this->screen = screen; this->input = input; + // Reserva memoria para los objetos eventHandler = new SDL_Event(); map = new Map(asset->get("01.map"), renderer, asset); player = new Player(renderer, asset, input, map); debugText = new Text(asset->get("debug.png"), asset->get("debug.txt"), renderer); music = JA_LoadMusic(asset->get("music_surface.ogg").c_str()); + + // Inicializa variables + ticks = 0; + ticksSpeed = 15; + + section.name = SECTION_PROG_GAME; + section.subsection = SUBSECTION_GAME_PLAY; + + debug = false; } // Destructor @@ -28,8 +39,6 @@ Game::~Game() // Bucle para el juego section_t Game::run() { - init(); - JA_PlayMusic(music); while (section.name == SECTION_PROG_GAME) @@ -47,18 +56,6 @@ section_t Game::run() return section; } -// Inicializa las variables necesarias para la sección 'Game' -void Game::init() -{ - ticks = 0; - ticksSpeed = 15; - - section.name = SECTION_PROG_GAME; - section.subsection = SUBSECTION_GAME_PLAY; - - debug = true; -} - // Actualiza el juego, las variables, comprueba la entrada, etc. void Game::update() { diff --git a/source/game.h b/source/game.h index 6f8d0a5..939ad93 100644 --- a/source/game.h +++ b/source/game.h @@ -35,9 +35,6 @@ private: // Pinta los objetos en pantalla void render(); - // Inicializa las variables necesarias para la sección 'Game' - void init(); - // Comprueba la entrada void checkInput(); diff --git a/source/prog.cpp b/source/prog.cpp index 9e0a565..0f174e8 100644 --- a/source/prog.cpp +++ b/source/prog.cpp @@ -164,13 +164,15 @@ bool Prog::setFileList() asset->add("/data/sound/sound_menu_start.wav", sound); // Ficheros con musica - asset->add("/data/music/music_menu.ogg", music); + asset->add("/data/music/music_title.ogg", music); asset->add("/data/music/music_surface.ogg", music); asset->add("/data/music/music_volcano.ogg", music); // Ficheros de fuentes de texto asset->add("/data/font/debug.png", font); asset->add("/data/font/debug.txt", font); + asset->add("/data/font/dogica.png", font); + asset->add("/data/font/dogica.txt", font); // Ficheros de enemigos asset->add("/data/actors/enemies/walking_eye.png", bitmap); diff --git a/source/title.cpp b/source/title.cpp index cf59154..b4eacc3 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -16,6 +16,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input) sprite = new AnimatedSprite(texture, renderer, asset->get("intro.ani")); sprite->setCurrentAnimation("menu"); text = new Text(asset->get("debug.png"), asset->get("debug.txt"), renderer); + music = JA_LoadMusic(asset->get("music_title.ogg").c_str()); // Inicializa variables section = {SECTION_PROG_TITLE, 0}; @@ -42,6 +43,8 @@ Title::~Title() delete text; text = nullptr; + + JA_DeleteMusic(music); } // Actualiza las variables @@ -85,7 +88,9 @@ void Title::render() // Dibuja los objetos sprite->render(); - text->writeCentered(160, 200, "@2016,2022 JailDesigner (v0.6)", -1); + //text->writeCentered(160, 200, "@2016,2022 JAILDESIGNER & JAILBROTHER (v0.6)", -1); + const color_t color = {179,83,71}; + text->writeDX(TXT_CENTER|TXT_COLOR,160, 200, "@2016,2022 JAILDESIGNER & JAILBROTHER (v0.6)", -1, color); // Vuelca el contenido del renderizador en pantalla screen->blit(); @@ -94,6 +99,8 @@ void Title::render() // Bucle principal section_t Title::run() { + JA_PlayMusic(music); + while (section.name == SECTION_PROG_TITLE) { update(); @@ -101,4 +108,6 @@ section_t Title::run() } return section; + + JA_StopMusic(); } diff --git a/source/title.h b/source/title.h index 80fda34..53e5719 100644 --- a/source/title.h +++ b/source/title.h @@ -25,6 +25,7 @@ private: Input *input; // Objeto para gestionar las entradas Text *text; // Objeto para escribir texto en pantalla AnimatedSprite *sprite; // Sprite para dibujar los graficos de la intro + JA_Music music; // Musica del titulo del juego section_t section; // Estado del bucle principal para saber si continua o se sale int ticks; // Contador de ticks para ajustar la velocidad del programa int ticksSpeed; // Velocidad a la que se repiten los bucles del programa