LOGO funcional

This commit is contained in:
2022-09-27 19:03:24 +02:00
parent 740e495ad0
commit 50e31a3db3
3 changed files with 17 additions and 41 deletions

View File

@@ -1919,7 +1919,6 @@ void Game::popBalloon(Balloon *balloon)
mBalloonsPopped++; mBalloonsPopped++;
const Uint8 kind = balloon->getKind(); const Uint8 kind = balloon->getKind();
Uint8 freeIndex = 0;
switch (kind) switch (kind)
{ {
// Si es del tipo más pequeño, simplemente elimina el globo // Si es del tipo más pequeño, simplemente elimina el globo
@@ -2265,6 +2264,7 @@ void Game::renderBullets()
void Game::createBullet(int x, int y, Uint8 kind, bool poweredUp, int owner) void Game::createBullet(int x, int y, Uint8 kind, bool poweredUp, int owner)
{ {
Bullet *b = new Bullet(x, y, kind, poweredUp, owner, mTextureBullet, mRenderer); Bullet *b = new Bullet(x, y, kind, poweredUp, owner, mTextureBullet, mRenderer);
bullets.push_back(b);
} }
// Actualiza los items // Actualiza los items

View File

@@ -16,13 +16,6 @@ Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset)
texture = new LTexture(renderer, asset->get("logo.png")); texture = new LTexture(renderer, asset->get("logo.png"));
sprite = new Sprite(0, 0, GAME_WIDTH, GAME_HEIGHT, texture, renderer); 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 // Inicializa variables
counter = 0; counter = 0;
section.name = PROG_SECTION_LOGO; section.name = PROG_SECTION_LOGO;
@@ -34,8 +27,6 @@ Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset)
// Destructor // Destructor
Logo::~Logo() Logo::~Logo()
{ {
SDL_DestroyTexture(backbuffer);
texture->unload(); texture->unload();
delete texture; delete texture;
@@ -46,24 +37,11 @@ Logo::~Logo()
// Comprueba si ha terminado el logo // Comprueba si ha terminado el logo
void Logo::checkLogoEnd() void Logo::checkLogoEnd()
{ {
if (counter == 0) if (counter >= END_LOGO + 20)
{ {
if (JA_GetMusicState() == JA_MUSIC_PLAYING) section.name = PROG_SECTION_QUIT;
{
JA_StopMusic();
}
}
if (counter == END_LOGO + 20)
{
counter = 0;
section.name = PROG_SECTION_INTRO;
section.subsection = 0; section.subsection = 0;
} }
else
{
counter++;
}
} }
// Comprueba los eventos // Comprueba los eventos
@@ -91,22 +69,13 @@ void Logo::checkEventHandler()
// Dibuja el fade // Dibuja el fade
void Logo::renderFade() void Logo::renderFade()
{ {
const SDL_Rect rect = {0, 0, GAME_WIDTH, GAME_HEIGHT};
const int fadeLenght = END_LOGO - INIT_FADE;
// Dibuja el fade // Dibuja el fade
if (counter >= INIT_FADE) if (counter >= INIT_FADE)
{ {
const Uint16 alpha = (255 * (counter - INIT_FADE)) / fadeLenght; const float step = (float)(counter - INIT_FADE) / (float)(END_LOGO - INIT_FADE);
if (alpha < 256) const int alpha = std::min((int)(255 * step), 255);
{ SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, alpha);
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, alpha); SDL_RenderFillRect(renderer, nullptr);
}
else
{
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
}
SDL_RenderFillRect(renderer, &rect);
} }
} }
@@ -120,6 +89,9 @@ void Logo::update()
// Actualiza el contador de ticks // Actualiza el contador de ticks
ticks = SDL_GetTicks(); ticks = SDL_GetTicks();
// Actualiza el contador
counter++;
// Comprueba si ha terminado el logo // Comprueba si ha terminado el logo
checkLogoEnd(); checkLogoEnd();
} }
@@ -147,6 +119,8 @@ void Logo::render()
// Bucle para el logo del juego // Bucle para el logo del juego
section_t Logo::run() section_t Logo::run()
{ {
JA_StopMusic();
while (section.name == PROG_SECTION_LOGO) while (section.name == PROG_SECTION_LOGO)
{ {
update(); update();

View File

@@ -15,17 +15,19 @@
class Logo class Logo
{ {
private: private:
// Objetos
SDL_Renderer *renderer; // El renderizador de la ventana SDL_Renderer *renderer; // El renderizador de la ventana
Screen *screen; // Objeto encargado de dibujar en pantalla Screen *screen; // Objeto encargado de dibujar en pantalla
Asset *asset; // Objeto que gestiona todos los ficheros de recursos Asset *asset; // Objeto que gestiona todos los ficheros de recursos
LTexture *texture; // Textura con los graficos LTexture *texture; // Textura con los graficos
SDL_Event *eventHandler; // Manejador de eventos SDL_Event *eventHandler; // Manejador de eventos
SDL_Texture *backbuffer; // Textura para usar como backbuffer
Sprite *sprite; // Sprite con la textura del logo Sprite *sprite; // Sprite con la textura del logo
int counter; // Contador
section_t section; // Estado del bucle principal para saber si continua o se sale // Variables
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
section_t section; // Estado del bucle principal para saber si continua o se sale
int counter; // Contador
// Actualiza las variables del objeto // Actualiza las variables del objeto
void update(); void update();