From 74d9c9a2b9edc315c4feba283a2ce03212f32bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Mon, 30 Dec 2024 19:07:13 +0100 Subject: [PATCH] =?UTF-8?q?Commit=20per=20a=20vore=20qu=C3=A9=20est=C3=A0?= =?UTF-8?q?=20passant=20amb=20la=20m=C3=BAsica?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/director.cpp | 2 +- source/game.cpp | 9 +--- source/intro.cpp | 1 - source/logo.cpp | 2 +- source/title.cpp | 103 ++++++++++++++++++++++++++++---------------- source/title.h | 12 +++++- 6 files changed, 81 insertions(+), 48 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index e092c67..7e85192 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -54,7 +54,7 @@ Director::Director(int argc, const char *argv[]) section::name = section::Name::GAME; section::options = section::Options::GAME_PLAY_1P; #elif DEBUG - section::name = section::Name::GAME; + section::name = section::Name::LOGO; #else // NORMAL GAME section::name = section::Name::LOGO; section::attract_mode = section::AttractMode::TITLE_TO_DEMO; diff --git a/source/game.cpp b/source/game.cpp index dc76e09..6b56fd0 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -68,11 +68,9 @@ Game::Game(int player_id, int current_stage, bool demo) fade_in_->setColor(fade_color.r, fade_color.g, fade_color.b); fade_in_->setPost(0); - fade_in_->setType(FadeType::VENETIAN); + fade_in_->setType(FadeType::RANDOM_SQUARE); fade_in_->setMode(FadeMode::IN); fade_in_->activate(); - // JA_PlaySound(Resource::get()->getSound("fade_in.wav")); - // playMusic(); fade_out_->setColor(fade_color.r, fade_color.g, fade_color.b); fade_out_->setPost(param.fade.post_duration); @@ -943,15 +941,12 @@ void Game::fillCanvas() background_->render(); renderItems(); renderSmartSprites(); - tabe_->render(); balloon_manager_->render(); + tabe_->render(); renderBullets(); renderPathSprites(); renderPlayers(); - auto sprite = std::make_unique(Resource::get()->getTexture("game_text_game_over")); - sprite->render(); - // Deja el renderizador apuntando donde estaba SDL_SetRenderTarget(renderer_, temp); } diff --git a/source/intro.cpp b/source/intro.cpp index fc92798..2911599 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -416,7 +416,6 @@ void Intro::render() void Intro::run() { JA_PlayMusic(Resource::get()->getMusic("intro.ogg"), 0); - while (section::name == section::Name::INTRO) { checkInput(); diff --git a/source/logo.cpp b/source/logo.cpp index 42fa3a5..2ce04ae 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -234,7 +234,7 @@ void Logo::render() void Logo::run() { // Detiene la música - JA_FadeOutMusic(500); + JA_FadeOutMusic(300); while (section::name == section::Name::LOGO) { diff --git a/source/title.cpp b/source/title.cpp index 48b225c..153984a 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -33,7 +33,8 @@ Title::Title() game_logo_(std::make_unique(param.game.game_area.center_x, param.title.title_c_c_position)), mini_logo_sprite_(std::make_unique(Resource::get()->getTexture("logo_jailgames_mini.png"))), define_buttons_(std::make_unique()), - num_controllers_(Input::get()->getNumControllers()) + num_controllers_(Input::get()->getNumControllers()), + state_(TitleState::LOGO_ANIMATING) { // Configura objetos game_logo_->enable(); @@ -73,9 +74,8 @@ void Title::update() // Actualiza las variables de globalInputs globalInputs::update(); - // Comprueba el fundido y si se ha acabado + // Comprueba el fundido fade_->update(); - // JA_SetMusicVolume(100 - fade_->getValue()); if (fade_->hasEnded()) { if (post_fade_ == -1) @@ -90,18 +90,19 @@ void Title::update() } } - // Sección 1 - Titulo animandose - if (section::options == section::Options::TITLE_1) + // Establece la lógica según el estado + switch (state_) + { + case TitleState::LOGO_ANIMATING: { game_logo_->update(); if (game_logo_->hasFinished()) { - section::options = section::Options::TITLE_2; + state_ = TitleState::LOGO_FINISHED; } + break; } - - // Sección 2 - La pantalla con el titulo, el fondo animado y la música - else if (section::options == section::Options::TITLE_2) + case TitleState::LOGO_FINISHED: { // El contador solo sube si no estamos definiendo botones counter_ = define_buttons_->isEnabled() ? 0 : counter_ + 1; @@ -109,10 +110,7 @@ void Title::update() // Reproduce la música if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) { - if (!fade_->isEnabled()) - { - JA_PlayMusic(Resource::get()->getMusic("title.ogg")); - } + JA_PlayMusic(Resource::get()->getMusic("title.ogg")); } // Actualiza el logo con el título del juego @@ -126,6 +124,27 @@ void Title::update() fade_->activate(); post_fade_ = -1; } + + break; + } + case TitleState::START_HAS_BEEN_PRESSED: + { + // Actualiza el logo con el título del juego + game_logo_->update(); + + // Actualiza el mosaico de fondo + tiled_bg_->update(); + + if (counter_ == 100) + { + fade_->activate(); + } + ++counter_; + break; + } + + default: + break; } } } @@ -145,16 +164,10 @@ void Title::render() // Dibuja el logo con el título del juego game_logo_->render(); - if (section::options == section::Options::TITLE_2) + constexpr Color shadow = Color(0x14, 0x87, 0xc4); + + if (state_ != TitleState::LOGO_ANIMATING) { - constexpr Color shadow = Color(0x14, 0x87, 0xc4); - - // 'PRESS TO PLAY' - if (counter_ % 50 > 14 && !define_buttons_->isEnabled()) - { - text_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, param.title.press_start_position, lang::getText(23), 1, no_color, 1, shadow); - } - // Mini logo const int pos1 = (param.game.height / 5 * 4) + BLOCK; const int pos2 = pos1 + mini_logo_sprite_->getHeight() + 3; @@ -165,6 +178,24 @@ void Title::render() text_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, pos2, TEXT_COPYRIGHT, 1, no_color, 1, shadow); } + if (state_ == TitleState::LOGO_FINISHED) + { + // 'PRESS TO PLAY' + if (counter_ % 50 > 14 && !define_buttons_->isEnabled()) + { + text_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, param.title.press_start_position, lang::getText(23), 1, no_color, 1, shadow); + } + } + + if (state_ == TitleState::START_HAS_BEEN_PRESSED) + { + // 'PRESS TO PLAY' + if (counter_ % 10 > 4 && !define_buttons_->isEnabled()) + { + text_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, param.title.press_start_position, lang::getText(23), 1, no_color, 1, shadow); + } + } + // Define Buttons define_buttons_->render(); @@ -246,29 +277,28 @@ void Title::checkEvents() // Comprueba las entradas void Title::checkInput() { - // Comprueba los controladores solo si no se estan definiendo los botones + // Comprueba las entradas solo si no se estan definiendo los botones if (!define_buttons_->isEnabled()) { - // Comprueba los métodos de control + // Comprueba todos los métodos de control for (const auto &controller : options.controllers) { + // START if (Input::get()->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index) && !Input::get()->checkInput(InputType::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index)) { - if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP) + if (state_ == TitleState::LOGO_FINISHED || ALLOW_TITLE_ANIMATION_SKIP) { - if (!fade_->isEnabled()) - { - JA_PlaySound(Resource::get()->getSound("game_start.wav")); - JA_FadeOutMusic(1500); - fade_->activate(); - post_fade_ = controller.player_id; - return; - } + JA_PlaySound(Resource::get()->getSound("game_start.wav")); + JA_FadeOutMusic(1500); + post_fade_ = controller.player_id; + state_ = TitleState::START_HAS_BEEN_PRESSED; + counter_ = 0; + return; } } - // Comprueba si se va a intercambiar la asignación de mandos a jugadores + // SWAP_CONTROLLERS if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, controller.type, controller.index) && Input::get()->checkInput(InputType::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index)) { @@ -276,7 +306,7 @@ void Title::checkInput() return; } - // Comprueba si algun mando quiere ser configurado + // CONFIG if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, controller.type, controller.index) && Input::get()->checkInput(InputType::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index)) { @@ -355,7 +385,6 @@ void Title::showControllers() } } - // std::string spaces(lang::getText(100).length() + 3, ' '); - // std::string kb_text = spaces + lang::getText(69); + // Muestra la notificación Notifier::get()->showText({text.at(0), text.at(1)}); } diff --git a/source/title.h b/source/title.h index 16d766c..8a15cba 100644 --- a/source/title.h +++ b/source/title.h @@ -27,9 +27,10 @@ constexpr bool ALLOW_TITLE_ANIMATION_SKIP = false; - Dibujar el tileado de fondo - Redifinir los botones de los mandos de juego - Esta clase tiene dos estados: + Esta clase tiene tres estados: - El titulo está animandose, con el fondo estático - El titulo ya está en su sitio y el fondo se está animando + - Se ha pulsado el botón de start Por razones de diseño, no se permite saltarse la animación del titulo, aunque es configurable mediante un define @@ -39,6 +40,14 @@ constexpr bool ALLOW_TITLE_ANIMATION_SKIP = false; class Title { private: + // Enumeraciones + enum class TitleState + { + LOGO_ANIMATING, + LOGO_FINISHED, + START_HAS_BEEN_PRESSED, + }; + // Objetos y punteros std::shared_ptr text_; // Objeto de texto para poder escribir textos en pantalla std::unique_ptr fade_; // Objeto para realizar fundidos en pantalla @@ -53,6 +62,7 @@ private: section::Name next_section_; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo int post_fade_ = 0; // Opción a realizar cuando termina el fundido int num_controllers_; // Número de mandos conectados + TitleState state_; // Estado en el que se encuentra la sección // Actualiza las variables del objeto void update();