2024-12-30 20:06:04 +01:00
6 changed files with 81 additions and 48 deletions

View File

@@ -54,7 +54,7 @@ Director::Director(int argc, const char *argv[])
section::name = section::Name::GAME; section::name = section::Name::GAME;
section::options = section::Options::GAME_PLAY_1P; section::options = section::Options::GAME_PLAY_1P;
#elif DEBUG #elif DEBUG
section::name = section::Name::GAME; section::name = section::Name::LOGO;
#else // NORMAL GAME #else // NORMAL GAME
section::name = section::Name::LOGO; section::name = section::Name::LOGO;
section::attract_mode = section::AttractMode::TITLE_TO_DEMO; section::attract_mode = section::AttractMode::TITLE_TO_DEMO;

View File

@@ -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_->setColor(fade_color.r, fade_color.g, fade_color.b);
fade_in_->setPost(0); fade_in_->setPost(0);
fade_in_->setType(FadeType::VENETIAN); fade_in_->setType(FadeType::RANDOM_SQUARE);
fade_in_->setMode(FadeMode::IN); fade_in_->setMode(FadeMode::IN);
fade_in_->activate(); 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_->setColor(fade_color.r, fade_color.g, fade_color.b);
fade_out_->setPost(param.fade.post_duration); fade_out_->setPost(param.fade.post_duration);
@@ -943,15 +941,12 @@ void Game::fillCanvas()
background_->render(); background_->render();
renderItems(); renderItems();
renderSmartSprites(); renderSmartSprites();
tabe_->render();
balloon_manager_->render(); balloon_manager_->render();
tabe_->render();
renderBullets(); renderBullets();
renderPathSprites(); renderPathSprites();
renderPlayers(); renderPlayers();
auto sprite = std::make_unique<Sprite>(Resource::get()->getTexture("game_text_game_over"));
sprite->render();
// Deja el renderizador apuntando donde estaba // Deja el renderizador apuntando donde estaba
SDL_SetRenderTarget(renderer_, temp); SDL_SetRenderTarget(renderer_, temp);
} }

View File

@@ -416,7 +416,6 @@ void Intro::render()
void Intro::run() void Intro::run()
{ {
JA_PlayMusic(Resource::get()->getMusic("intro.ogg"), 0); JA_PlayMusic(Resource::get()->getMusic("intro.ogg"), 0);
while (section::name == section::Name::INTRO) while (section::name == section::Name::INTRO)
{ {
checkInput(); checkInput();

View File

@@ -234,7 +234,7 @@ void Logo::render()
void Logo::run() void Logo::run()
{ {
// Detiene la música // Detiene la música
JA_FadeOutMusic(500); JA_FadeOutMusic(300);
while (section::name == section::Name::LOGO) while (section::name == section::Name::LOGO)
{ {

View File

@@ -33,7 +33,8 @@ Title::Title()
game_logo_(std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position)), game_logo_(std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position)),
mini_logo_sprite_(std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"))), mini_logo_sprite_(std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"))),
define_buttons_(std::make_unique<DefineButtons>()), define_buttons_(std::make_unique<DefineButtons>()),
num_controllers_(Input::get()->getNumControllers()) num_controllers_(Input::get()->getNumControllers()),
state_(TitleState::LOGO_ANIMATING)
{ {
// Configura objetos // Configura objetos
game_logo_->enable(); game_logo_->enable();
@@ -73,9 +74,8 @@ void Title::update()
// Actualiza las variables de globalInputs // Actualiza las variables de globalInputs
globalInputs::update(); globalInputs::update();
// Comprueba el fundido y si se ha acabado // Comprueba el fundido
fade_->update(); fade_->update();
// JA_SetMusicVolume(100 - fade_->getValue());
if (fade_->hasEnded()) if (fade_->hasEnded())
{ {
if (post_fade_ == -1) if (post_fade_ == -1)
@@ -90,18 +90,19 @@ void Title::update()
} }
} }
// Sección 1 - Titulo animandose // Establece la lógica según el estado
if (section::options == section::Options::TITLE_1) switch (state_)
{
case TitleState::LOGO_ANIMATING:
{ {
game_logo_->update(); game_logo_->update();
if (game_logo_->hasFinished()) if (game_logo_->hasFinished())
{ {
section::options = section::Options::TITLE_2; state_ = TitleState::LOGO_FINISHED;
} }
break;
} }
case TitleState::LOGO_FINISHED:
// Sección 2 - La pantalla con el titulo, el fondo animado y la música
else if (section::options == section::Options::TITLE_2)
{ {
// El contador solo sube si no estamos definiendo botones // El contador solo sube si no estamos definiendo botones
counter_ = define_buttons_->isEnabled() ? 0 : counter_ + 1; counter_ = define_buttons_->isEnabled() ? 0 : counter_ + 1;
@@ -109,10 +110,7 @@ void Title::update()
// Reproduce la música // Reproduce la música
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) 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 // Actualiza el logo con el título del juego
@@ -126,6 +124,27 @@ void Title::update()
fade_->activate(); fade_->activate();
post_fade_ = -1; 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 // Dibuja el logo con el título del juego
game_logo_->render(); 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 // Mini logo
const int pos1 = (param.game.height / 5 * 4) + BLOCK; const int pos1 = (param.game.height / 5 * 4) + BLOCK;
const int pos2 = pos1 + mini_logo_sprite_->getHeight() + 3; 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); 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
define_buttons_->render(); define_buttons_->render();
@@ -246,29 +277,28 @@ void Title::checkEvents()
// Comprueba las entradas // Comprueba las entradas
void Title::checkInput() 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()) if (!define_buttons_->isEnabled())
{ {
// Comprueba los métodos de control // Comprueba todos los métodos de control
for (const auto &controller : options.controllers) for (const auto &controller : options.controllers)
{ {
// START
if (Input::get()->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index) && 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)) !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);
JA_PlaySound(Resource::get()->getSound("game_start.wav")); post_fade_ = controller.player_id;
JA_FadeOutMusic(1500); state_ = TitleState::START_HAS_BEEN_PRESSED;
fade_->activate(); counter_ = 0;
post_fade_ = controller.player_id; return;
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) && 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)) Input::get()->checkInput(InputType::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index))
{ {
@@ -276,7 +306,7 @@ void Title::checkInput()
return; return;
} }
// Comprueba si algun mando quiere ser configurado // CONFIG
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, controller.type, controller.index) && 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)) 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, ' '); // Muestra la notificación
// std::string kb_text = spaces + lang::getText(69);
Notifier::get()->showText({text.at(0), text.at(1)}); Notifier::get()->showText({text.at(0), text.at(1)});
} }

View File

@@ -27,9 +27,10 @@ constexpr bool ALLOW_TITLE_ANIMATION_SKIP = false;
- Dibujar el tileado de fondo - Dibujar el tileado de fondo
- Redifinir los botones de los mandos de juego - 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 está animandose, con el fondo estático
- El titulo ya está en su sitio y el fondo se está animando - 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 Por razones de diseño, no se permite saltarse la animación del titulo, aunque es
configurable mediante un define configurable mediante un define
@@ -39,6 +40,14 @@ constexpr bool ALLOW_TITLE_ANIMATION_SKIP = false;
class Title class Title
{ {
private: private:
// Enumeraciones
enum class TitleState
{
LOGO_ANIMATING,
LOGO_FINISHED,
START_HAS_BEEN_PRESSED,
};
// Objetos y punteros // Objetos y punteros
std::shared_ptr<Text> text_; // Objeto de texto para poder escribir textos en pantalla std::shared_ptr<Text> text_; // Objeto de texto para poder escribir textos en pantalla
std::unique_ptr<Fade> fade_; // Objeto para realizar fundidos en pantalla std::unique_ptr<Fade> 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 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 post_fade_ = 0; // Opción a realizar cuando termina el fundido
int num_controllers_; // Número de mandos conectados int num_controllers_; // Número de mandos conectados
TitleState state_; // Estado en el que se encuentra la sección
// Actualiza las variables del objeto // Actualiza las variables del objeto
void update(); void update();