LOGO funcional
This commit is contained in:
@@ -16,13 +16,6 @@ Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
||||
texture = new LTexture(renderer, asset->get("logo.png"));
|
||||
sprite = new Sprite(0, 0, GAME_WIDTH, GAME_HEIGHT, texture, renderer);
|
||||
|
||||
// Crea un backbuffer para el renderizador
|
||||
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAME_WIDTH, GAME_HEIGHT);
|
||||
if (backbuffer == nullptr)
|
||||
{
|
||||
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
// Inicializa variables
|
||||
counter = 0;
|
||||
section.name = PROG_SECTION_LOGO;
|
||||
@@ -34,8 +27,6 @@ Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
||||
// Destructor
|
||||
Logo::~Logo()
|
||||
{
|
||||
SDL_DestroyTexture(backbuffer);
|
||||
|
||||
texture->unload();
|
||||
delete texture;
|
||||
|
||||
@@ -46,24 +37,11 @@ Logo::~Logo()
|
||||
// Comprueba si ha terminado el logo
|
||||
void Logo::checkLogoEnd()
|
||||
{
|
||||
if (counter == 0)
|
||||
if (counter >= END_LOGO + 20)
|
||||
{
|
||||
if (JA_GetMusicState() == JA_MUSIC_PLAYING)
|
||||
{
|
||||
JA_StopMusic();
|
||||
}
|
||||
}
|
||||
|
||||
if (counter == END_LOGO + 20)
|
||||
{
|
||||
counter = 0;
|
||||
section.name = PROG_SECTION_INTRO;
|
||||
section.name = PROG_SECTION_QUIT;
|
||||
section.subsection = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba los eventos
|
||||
@@ -91,22 +69,13 @@ void Logo::checkEventHandler()
|
||||
// Dibuja el fade
|
||||
void Logo::renderFade()
|
||||
{
|
||||
const SDL_Rect rect = {0, 0, GAME_WIDTH, GAME_HEIGHT};
|
||||
const int fadeLenght = END_LOGO - INIT_FADE;
|
||||
|
||||
// Dibuja el fade
|
||||
if (counter >= INIT_FADE)
|
||||
{
|
||||
const Uint16 alpha = (255 * (counter - INIT_FADE)) / fadeLenght;
|
||||
if (alpha < 256)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, alpha);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||
}
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
const float step = (float)(counter - INIT_FADE) / (float)(END_LOGO - INIT_FADE);
|
||||
const int alpha = std::min((int)(255 * step), 255);
|
||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, alpha);
|
||||
SDL_RenderFillRect(renderer, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,6 +89,9 @@ void Logo::update()
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
// Actualiza el contador
|
||||
counter++;
|
||||
|
||||
// Comprueba si ha terminado el logo
|
||||
checkLogoEnd();
|
||||
}
|
||||
@@ -147,6 +119,8 @@ void Logo::render()
|
||||
// Bucle para el logo del juego
|
||||
section_t Logo::run()
|
||||
{
|
||||
JA_StopMusic();
|
||||
|
||||
while (section.name == PROG_SECTION_LOGO)
|
||||
{
|
||||
update();
|
||||
|
||||
Reference in New Issue
Block a user