638 lines
16 KiB
C++
638 lines
16 KiB
C++
#include "intro.h"
|
|
#include <SDL3/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND, SDL_BLENDMODE_MOD
|
|
#include <SDL3/SDL_events.h> // Para SDL_PollEvent, SDL_Event
|
|
#include <SDL3/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
|
#include <SDL3/SDL_rect.h> // Para SDL_FRect
|
|
#include <SDL3/SDL_render.h> // Para SDL_SetTextureBlendMode, SDL_GetRend...
|
|
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
|
|
#include <array> // Para array
|
|
#include <functional> // Para function
|
|
#include <string> // Para basic_string, string
|
|
#include <utility> // Para move
|
|
#include "global_events.h" // Para check
|
|
#include "global_inputs.h" // Para check, update
|
|
#include "audio.h" // Para JA_PlayMusic, JA_StopMusic
|
|
#include "lang.h" // Para getText
|
|
#include "param.h" // Para Param, ParamGame, param
|
|
#include "path_sprite.h" // Para PathSprite, PathType
|
|
#include "resource.h" // Para Resource
|
|
#include "screen.h" // Para Screen
|
|
#include "section.h" // Para Name, name, Options, options
|
|
#include "texture.h" // Para Texture
|
|
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
|
|
#include "utils.h" // Para Color, Zone, easeOutQuint, BLOCK
|
|
#include "writer.h" // Para Writer
|
|
#include "input.h"
|
|
|
|
#ifdef DEBUG
|
|
#include <iomanip> // Para std::hex, std::setw, std::setfill
|
|
#endif
|
|
|
|
// Constructor
|
|
Intro::Intro()
|
|
: tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::DIAGONAL))
|
|
{
|
|
// Inicializa variables
|
|
Section::name = Section::Name::INTRO;
|
|
Section::options = Section::Options::NONE;
|
|
|
|
// Inicializa las imagens
|
|
initSprites();
|
|
|
|
// Inicializa los textos
|
|
initTexts();
|
|
|
|
// Configura el fondo
|
|
tiled_bg_->setSpeed(0.3f);
|
|
tiled_bg_->setColor(bg_color_);
|
|
}
|
|
|
|
// Comprueba los eventos
|
|
void Intro::checkEvents()
|
|
{
|
|
SDL_Event event;
|
|
while (SDL_PollEvent(&event))
|
|
{
|
|
#ifdef DEBUG
|
|
if (event.type == SDL_EVENT_KEY_DOWN && event.key.repeat == 1)
|
|
{
|
|
static Color color = param.intro.bg_color;
|
|
switch (event.key.key)
|
|
{
|
|
case SDLK_A:
|
|
if (color.r < 255)
|
|
++color.r;
|
|
break;
|
|
|
|
case SDLK_Z:
|
|
if (color.r > 0)
|
|
--color.r;
|
|
break;
|
|
|
|
case SDLK_S:
|
|
if (color.g < 255)
|
|
++color.g;
|
|
break;
|
|
|
|
case SDLK_X:
|
|
if (color.g > 0)
|
|
--color.g;
|
|
break;
|
|
|
|
case SDLK_D:
|
|
if (color.b < 255)
|
|
++color.b;
|
|
break;
|
|
|
|
case SDLK_C:
|
|
if (color.b > 0)
|
|
--color.b;
|
|
break;
|
|
|
|
case SDLK_F:
|
|
if (color.r < 255)
|
|
++color.r;
|
|
if (color.g < 255)
|
|
++color.g;
|
|
if (color.b < 255)
|
|
++color.b;
|
|
break;
|
|
|
|
case SDLK_V:
|
|
if (color.r > 0)
|
|
--color.r;
|
|
if (color.g > 0)
|
|
--color.g;
|
|
if (color.b > 0)
|
|
--color.b;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
tiled_bg_->setColor(color);
|
|
std::cout << "#"
|
|
<< std::hex << std::setw(2) << std::setfill('0') << (int)color.r
|
|
<< std::setw(2) << std::setfill('0') << (int)color.g
|
|
<< std::setw(2) << std::setfill('0') << (int)color.b
|
|
<< std::endl;
|
|
}
|
|
#endif
|
|
GlobalEvents::check(event);
|
|
}
|
|
}
|
|
|
|
// Comprueba las entradas
|
|
void Intro::checkInput()
|
|
{
|
|
Input::get()->update();
|
|
GlobalInputs::check();
|
|
}
|
|
|
|
// Actualiza las escenas de la intro
|
|
void Intro::updateScenes()
|
|
{
|
|
switch (scene_)
|
|
{
|
|
case 0:
|
|
{
|
|
// Primera imagen - UPV
|
|
card_sprites_.at(0)->enable();
|
|
shadow_sprites_.at(0)->enable();
|
|
|
|
// Primer texto de la primera imagen
|
|
if (card_sprites_.at(0)->hasFinished() && !texts_.at(0)->hasFinished())
|
|
{
|
|
texts_.at(0)->setEnabled(true);
|
|
}
|
|
|
|
// Segundo texto de la primera imagen
|
|
if (texts_.at(0)->hasFinished() && !texts_.at(1)->hasFinished())
|
|
{
|
|
texts_.at(0)->setEnabled(false);
|
|
texts_.at(1)->setEnabled(true);
|
|
}
|
|
|
|
// Tercer texto de la primera imagen
|
|
if (texts_.at(1)->hasFinished() && !texts_.at(2)->hasFinished())
|
|
{
|
|
texts_.at(1)->setEnabled(false);
|
|
texts_.at(2)->setEnabled(true);
|
|
}
|
|
|
|
// Fin de la primera escena
|
|
if (texts_.at(2)->hasFinished())
|
|
{
|
|
texts_.at(2)->setEnabled(false);
|
|
scene_++;
|
|
}
|
|
break;
|
|
}
|
|
|
|
case 1:
|
|
{
|
|
// Segunda imagen - Máquina
|
|
card_sprites_.at(1)->enable();
|
|
shadow_sprites_.at(1)->enable();
|
|
|
|
// Primer texto de la segunda imagen
|
|
if (card_sprites_.at(1)->hasFinished() && !texts_.at(3)->hasFinished())
|
|
{
|
|
texts_.at(3)->setEnabled(true);
|
|
}
|
|
|
|
// Fin de la segunda escena
|
|
if (texts_.at(3)->hasFinished())
|
|
{
|
|
texts_.at(3)->setEnabled(false);
|
|
scene_++;
|
|
}
|
|
break;
|
|
}
|
|
|
|
case 2:
|
|
{
|
|
// Tercera imagen junto con primer texto - GRITO
|
|
if (!texts_.at(4)->hasFinished())
|
|
{
|
|
card_sprites_.at(2)->enable();
|
|
shadow_sprites_.at(2)->enable();
|
|
|
|
texts_.at(4)->setEnabled(true);
|
|
}
|
|
|
|
// Fin de la tercera escena
|
|
if (card_sprites_.at(2)->hasFinished() && texts_.at(4)->hasFinished())
|
|
{
|
|
texts_.at(4)->setEnabled(false);
|
|
scene_++;
|
|
}
|
|
break;
|
|
}
|
|
|
|
case 3:
|
|
{
|
|
// Cuarta imagen junto con primer texto - Reflexión
|
|
card_sprites_.at(3)->enable();
|
|
shadow_sprites_.at(3)->enable();
|
|
|
|
if (!texts_.at(5)->hasFinished())
|
|
{
|
|
texts_.at(5)->setEnabled(true);
|
|
}
|
|
|
|
// Segundo texto de la cuarta imagen
|
|
if (texts_.at(5)->hasFinished() && !texts_.at(6)->hasFinished())
|
|
{
|
|
texts_.at(5)->setEnabled(false);
|
|
texts_.at(6)->setEnabled(true);
|
|
}
|
|
|
|
// Fin de la cuarta escena
|
|
if (card_sprites_.at(3)->hasFinished() && texts_.at(6)->hasFinished())
|
|
{
|
|
texts_.at(6)->setEnabled(false);
|
|
scene_++;
|
|
}
|
|
break;
|
|
}
|
|
|
|
case 4:
|
|
{
|
|
// Quinta imagen - Patada
|
|
card_sprites_.at(4)->enable();
|
|
shadow_sprites_.at(4)->enable();
|
|
|
|
// Primer texto de la quinta imagen
|
|
if (!texts_.at(7)->hasFinished())
|
|
{
|
|
texts_.at(7)->setEnabled(true);
|
|
}
|
|
|
|
// Fin de la quinta escena
|
|
if (card_sprites_.at(4)->hasFinished() && texts_.at(7)->hasFinished())
|
|
{
|
|
texts_.at(7)->setEnabled(false);
|
|
scene_++;
|
|
}
|
|
break;
|
|
}
|
|
|
|
case 5:
|
|
{
|
|
// Sexta imagen junto con texto - Globos de café
|
|
card_sprites_.at(5)->enable();
|
|
shadow_sprites_.at(5)->enable();
|
|
|
|
if (!texts_.at(8)->hasFinished())
|
|
{
|
|
texts_.at(8)->setEnabled(true);
|
|
}
|
|
|
|
// Acaba el último texto
|
|
if (texts_.at(8)->hasFinished())
|
|
{
|
|
texts_.at(8)->setEnabled(false);
|
|
}
|
|
|
|
// Acaba la ultima imagen
|
|
if (card_sprites_.at(5)->hasFinished() && texts_.at(8)->hasFinished())
|
|
{
|
|
state_ = IntroState::POST;
|
|
state_start_time_ = SDL_GetTicks();
|
|
}
|
|
break;
|
|
}
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Actualiza las variables del objeto
|
|
void Intro::update()
|
|
{
|
|
if (SDL_GetTicks() - ticks_ > param.game.speed)
|
|
{
|
|
// Actualiza el contador de ticks
|
|
ticks_ = SDL_GetTicks();
|
|
|
|
// Actualiza el fondo
|
|
tiled_bg_->update();
|
|
|
|
switch (state_)
|
|
{
|
|
case IntroState::SCENES:
|
|
updateSprites();
|
|
updateTexts();
|
|
updateScenes();
|
|
break;
|
|
|
|
case IntroState::POST:
|
|
updatePostState();
|
|
break;
|
|
}
|
|
|
|
// Actualiza el objeto screen
|
|
Screen::get()->update();
|
|
}
|
|
}
|
|
|
|
// Dibuja el objeto en pantalla
|
|
void Intro::render()
|
|
{
|
|
// Prepara para empezar a dibujar en la textura de juego
|
|
Screen::get()->start();
|
|
|
|
// Limpia la pantalla
|
|
Screen::get()->clean();
|
|
|
|
// Dibuja el fondo
|
|
tiled_bg_->render();
|
|
|
|
switch (state_)
|
|
{
|
|
case IntroState::SCENES:
|
|
{
|
|
renderTextRect();
|
|
renderSprites();
|
|
renderTexts();
|
|
break;
|
|
}
|
|
case IntroState::POST:
|
|
break;
|
|
}
|
|
|
|
// Vuelca el contenido del renderizador en pantalla
|
|
Screen::get()->render();
|
|
}
|
|
|
|
// Bucle principal
|
|
void Intro::run()
|
|
{
|
|
Audio::get()->playMusic("intro.ogg", 0);
|
|
while (Section::name == Section::Name::INTRO)
|
|
{
|
|
checkInput();
|
|
update();
|
|
checkEvents(); // Tiene que ir antes del render
|
|
render();
|
|
}
|
|
}
|
|
|
|
// Inicializa las imagens
|
|
void Intro::initSprites()
|
|
{
|
|
// Listado de imagenes a usar
|
|
const std::array<std::string, 6> TEXTURE_LIST = {
|
|
"intro1.png",
|
|
"intro2.png",
|
|
"intro3.png",
|
|
"intro4.png",
|
|
"intro5.png",
|
|
"intro6.png"};
|
|
|
|
// Constantes
|
|
constexpr int TOTAL_SPRITES = TEXTURE_LIST.size();
|
|
const float BORDER = 2.0f;
|
|
|
|
auto texture = Resource::get()->getTexture(TEXTURE_LIST.front());
|
|
const float CARD_WIDTH = texture->getWidth() + (BORDER * 2);
|
|
const float CARD_HEIGHT = texture->getHeight() + (BORDER * 2);
|
|
|
|
// Crea las texturas para las tarjetas
|
|
std::vector<std::shared_ptr<Texture>> card_textures;
|
|
|
|
for (int i = 0; i < TOTAL_SPRITES; ++i)
|
|
{
|
|
// Crea la textura
|
|
auto card_texture = std::make_shared<Texture>(Screen::get()->getRenderer());
|
|
card_texture->createBlank(CARD_WIDTH, CARD_HEIGHT, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
|
card_texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
|
|
|
// Apuntamos el renderizador a la textura
|
|
auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
|
card_texture->setAsRenderTarget(Screen::get()->getRenderer());
|
|
|
|
// Limpia la textura
|
|
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);
|
|
SDL_RenderClear(Screen::get()->getRenderer());
|
|
|
|
// Pone color en el marco de la textura
|
|
auto color = param.intro.card_color;
|
|
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, color.a);
|
|
SDL_FRect rect1 = {1, 0, CARD_WIDTH - 2, CARD_HEIGHT};
|
|
SDL_FRect rect2 = {0, 1, CARD_WIDTH, CARD_HEIGHT - 2};
|
|
SDL_RenderRect(Screen::get()->getRenderer(), &rect1);
|
|
SDL_RenderRect(Screen::get()->getRenderer(), &rect2);
|
|
|
|
// Copia la textura con la imagen dentro del marco
|
|
SDL_FRect dest = {BORDER, BORDER, CARD_WIDTH - (BORDER * 2), CARD_HEIGHT - (BORDER * 2)};
|
|
SDL_RenderTexture(Screen::get()->getRenderer(), Resource::get()->getTexture(TEXTURE_LIST.at(i))->getSDLTexture(), nullptr, &dest);
|
|
|
|
// Deja el renderizador como estaba y añade la textura a la lista
|
|
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
|
|
card_textures.push_back(card_texture);
|
|
}
|
|
|
|
// Inicializa los sprites para las tarjetas
|
|
for (int i = 0; i < TOTAL_SPRITES; ++i)
|
|
{
|
|
auto sprite = std::make_unique<PathSprite>(card_textures.at(i));
|
|
sprite->setWidth(CARD_WIDTH);
|
|
sprite->setHeight(CARD_HEIGHT);
|
|
sprite->setSpriteClip(0, 0, CARD_WIDTH, CARD_HEIGHT);
|
|
card_sprites_.push_back(std::move(sprite));
|
|
}
|
|
|
|
const float X_DEST = param.game.game_area.center_x - CARD_WIDTH / 2;
|
|
const float Y_DEST = param.game.game_area.first_quarter_y - (CARD_HEIGHT / 4);
|
|
|
|
card_sprites_.at(0)->addPath(-CARD_WIDTH - 10, X_DEST, PathType::HORIZONTAL, Y_DEST, 100, easeInOutExpo, 0);
|
|
card_sprites_.at(1)->addPath(param.game.width, X_DEST, PathType::HORIZONTAL, Y_DEST, 100, easeOutBounce, 0);
|
|
card_sprites_.at(2)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, 40, easeOutQuint, 0);
|
|
card_sprites_.at(3)->addPath(param.game.height, Y_DEST, PathType::VERTICAL, X_DEST, 300, easeInOutExpo, 0);
|
|
card_sprites_.at(4)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, 70, easeOutElastic, 0);
|
|
card_sprites_.at(5)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, 250, easeOutQuad, 450);
|
|
card_sprites_.at(5)->addPath(X_DEST, -CARD_WIDTH, PathType::HORIZONTAL, Y_DEST, 80, easeInElastic, 0);
|
|
|
|
// Constantes
|
|
const float DESP = 8;
|
|
const float SHADOW_SPRITE_WIDTH = CARD_WIDTH;
|
|
const float SHADOW_SPRITE_HEIGHT = CARD_HEIGHT;
|
|
|
|
// Crea la textura para las sombras de las tarjetas
|
|
auto shadow_texture = std::make_shared<Texture>(Screen::get()->getRenderer());
|
|
shadow_texture->createBlank(SHADOW_SPRITE_WIDTH, SHADOW_SPRITE_HEIGHT, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
|
shadow_texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
|
|
|
// Apuntamos el renderizador a la textura
|
|
auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
|
shadow_texture->setAsRenderTarget(Screen::get()->getRenderer());
|
|
|
|
// Limpia la textura
|
|
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);
|
|
SDL_RenderClear(Screen::get()->getRenderer());
|
|
|
|
// Dibuja la sombra sobre la textura
|
|
auto color = param.intro.shadow_color;
|
|
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 255);
|
|
SDL_FRect rect1 = {1, 0, SHADOW_SPRITE_WIDTH - 2, SHADOW_SPRITE_HEIGHT};
|
|
SDL_FRect rect2 = {0, 1, SHADOW_SPRITE_WIDTH, SHADOW_SPRITE_HEIGHT - 2};
|
|
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect1);
|
|
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect2);
|
|
|
|
// Deja el renderizador como estaba y añade la textura a la lista
|
|
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
|
|
|
|
// Inicializa los sprites para la sombras usando la texturas con la sombra
|
|
for (int i = 0; i < TOTAL_SPRITES; ++i)
|
|
{
|
|
auto color = param.intro.shadow_color;
|
|
auto sprite = std::make_unique<PathSprite>(shadow_texture);
|
|
sprite->setWidth(SHADOW_SPRITE_WIDTH);
|
|
sprite->setHeight(SHADOW_SPRITE_HEIGHT);
|
|
sprite->setSpriteClip(0, 0, SHADOW_SPRITE_WIDTH, SHADOW_SPRITE_HEIGHT);
|
|
sprite->getTexture()->setAlpha(color.a);
|
|
shadow_sprites_.push_back(std::move(sprite));
|
|
}
|
|
|
|
const float S_X_DEST = X_DEST + DESP;
|
|
const float S_Y_DEST = Y_DEST + DESP;
|
|
|
|
shadow_sprites_.at(0)->addPath(param.game.height + 10, S_Y_DEST, PathType::VERTICAL, S_X_DEST, 100, easeInOutExpo, 0);
|
|
shadow_sprites_.at(1)->addPath(-SHADOW_SPRITE_HEIGHT, S_Y_DEST, PathType::VERTICAL, S_X_DEST, 100, easeOutBounce, 0);
|
|
shadow_sprites_.at(2)->addPath(-SHADOW_SPRITE_WIDTH, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, 40, easeOutQuint, 0);
|
|
shadow_sprites_.at(3)->addPath(-SHADOW_SPRITE_HEIGHT, S_Y_DEST, PathType::VERTICAL, S_X_DEST, 300, easeInOutExpo, 0);
|
|
shadow_sprites_.at(4)->addPath(param.game.height, S_Y_DEST, PathType::VERTICAL, S_X_DEST, 70, easeOutElastic, 0);
|
|
shadow_sprites_.at(5)->addPath(param.game.width, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, 250, easeOutQuad, 450);
|
|
shadow_sprites_.at(5)->addPath(S_X_DEST, param.game.width, PathType::HORIZONTAL, S_Y_DEST, 80, easeInElastic, 0);
|
|
}
|
|
|
|
// Inicializa los textos
|
|
void Intro::initTexts()
|
|
{
|
|
constexpr int TOTAL_TEXTS = 9;
|
|
for (int i = 0; i < TOTAL_TEXTS; ++i)
|
|
{
|
|
auto w = std::make_unique<Writer>(Resource::get()->getText("04b_25_metal"));
|
|
w->setPosX(0);
|
|
w->setPosY(param.game.height - param.intro.text_distance_from_bottom);
|
|
w->setKerning(-2);
|
|
w->setEnabled(false);
|
|
w->setFinishedCounter(180);
|
|
texts_.push_back(std::move(w));
|
|
}
|
|
|
|
// Un dia qualsevol de l'any 2000
|
|
texts_.at(0)->setCaption(Lang::getText("[INTRO] 1"));
|
|
texts_.at(0)->setSpeed(8);
|
|
|
|
// Tot esta tranquil a la UPV
|
|
texts_.at(1)->setCaption(Lang::getText("[INTRO] 2"));
|
|
texts_.at(1)->setSpeed(8);
|
|
|
|
// Fins que un desaprensiu...
|
|
texts_.at(2)->setCaption(Lang::getText("[INTRO] 3"));
|
|
texts_.at(2)->setSpeed(12);
|
|
|
|
// HEY! ME ANE A FERME UN CORTAET...
|
|
texts_.at(3)->setCaption(Lang::getText("[INTRO] 4"));
|
|
texts_.at(3)->setSpeed(8);
|
|
|
|
// UAAAAAAAAAAAAA!!!
|
|
texts_.at(4)->setCaption(Lang::getText("[INTRO] 5"));
|
|
texts_.at(4)->setSpeed(1);
|
|
|
|
// Espera un moment...
|
|
texts_.at(5)->setCaption(Lang::getText("[INTRO] 6"));
|
|
texts_.at(5)->setSpeed(16);
|
|
|
|
// Si resulta que no tinc solt!
|
|
texts_.at(6)->setCaption(Lang::getText("[INTRO] 7"));
|
|
texts_.at(6)->setSpeed(2);
|
|
|
|
// MERDA DE MAQUINA!
|
|
texts_.at(7)->setCaption(Lang::getText("[INTRO] 8"));
|
|
texts_.at(7)->setSpeed(3);
|
|
|
|
// Blop... blop... blop...
|
|
texts_.at(8)->setCaption(Lang::getText("[INTRO] 9"));
|
|
texts_.at(8)->setSpeed(20);
|
|
|
|
for (auto &text : texts_)
|
|
{
|
|
text->center(param.game.game_area.center_x);
|
|
}
|
|
}
|
|
|
|
// Actualiza los sprites
|
|
void Intro::updateSprites()
|
|
{
|
|
for (auto &sprite : card_sprites_)
|
|
{
|
|
sprite->update();
|
|
}
|
|
|
|
for (auto &sprite : shadow_sprites_)
|
|
{
|
|
sprite->update();
|
|
}
|
|
}
|
|
|
|
// Actualiza los textos
|
|
void Intro::updateTexts()
|
|
{
|
|
for (auto &text : texts_)
|
|
{
|
|
text->update();
|
|
}
|
|
}
|
|
|
|
// Dibuja los sprites
|
|
void Intro::renderSprites()
|
|
{
|
|
shadow_sprites_.at(scene_)->render();
|
|
card_sprites_.at(scene_)->render();
|
|
}
|
|
|
|
// Dibuja los textos
|
|
void Intro::renderTexts()
|
|
{
|
|
for (const auto &text : texts_)
|
|
{
|
|
text->render();
|
|
}
|
|
}
|
|
|
|
// Actualiza el estado POST
|
|
void Intro::updatePostState()
|
|
{
|
|
const Uint32 ELAPSED_TIME = SDL_GetTicks() - state_start_time_;
|
|
|
|
switch (post_state_)
|
|
{
|
|
case IntroPostState::STOP_BG:
|
|
// EVENTO: Detiene el fondo después de 1 segundo
|
|
if (ELAPSED_TIME >= 1000)
|
|
{
|
|
tiled_bg_->stopGracefully();
|
|
|
|
if (!bg_color_.isEqualTo(param.title.bg_color))
|
|
{
|
|
bg_color_ = bg_color_.approachTo(param.title.bg_color, 1);
|
|
}
|
|
|
|
tiled_bg_->setColor(bg_color_);
|
|
}
|
|
|
|
// Cambia de estado si el fondo se ha detenido y recuperado el color
|
|
if (tiled_bg_->isStopped() && bg_color_.isEqualTo(param.title.bg_color))
|
|
{
|
|
post_state_ = IntroPostState::END;
|
|
state_start_time_ = SDL_GetTicks();
|
|
}
|
|
break;
|
|
|
|
case IntroPostState::END:
|
|
// Finaliza la intro después de 1 segundo
|
|
if (ELAPSED_TIME >= 1000)
|
|
{
|
|
Audio::get()->stopMusic();
|
|
Section::name = Section::Name::TITLE;
|
|
Section::options = Section::Options::TITLE_1;
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void Intro::renderTextRect()
|
|
{
|
|
static const float HEIGHT = Resource::get()->getText("04b_25_metal")->getCharacterSize();
|
|
static SDL_FRect rect = {0.0f, param.game.height - param.intro.text_distance_from_bottom - HEIGHT, param.game.width, HEIGHT * 3};
|
|
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), param.intro.shadow_color.r, param.intro.shadow_color.g, param.intro.shadow_color.b, param.intro.shadow_color.a);
|
|
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
|
|
} |