152 lines
3.3 KiB
C++
152 lines
3.3 KiB
C++
#include "logo.h"
|
|
#ifdef __MIPSEL__
|
|
#include <sys/stat.h>
|
|
#include <dirent.h>
|
|
#endif
|
|
|
|
// Constructor
|
|
Logo::Logo(SDL_Renderer *renderer, std::string *fileList)
|
|
{
|
|
// Copia la dirección del renderizador
|
|
mRenderer = renderer;
|
|
|
|
// Copia la dirección del la lista de ficheros
|
|
mFileList = fileList;
|
|
|
|
// Reserva memoria para los punteros
|
|
mEventHandler = new SDL_Event();
|
|
mTexture = new LTexture();
|
|
mSprite = new Sprite();
|
|
|
|
// Crea un backbuffer para el renderizador
|
|
mBackbuffer = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
if (mBackbuffer == NULL)
|
|
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
|
}
|
|
|
|
// Destructor
|
|
Logo::~Logo()
|
|
{
|
|
mTexture->unload();
|
|
delete mTexture;
|
|
mTexture = nullptr;
|
|
|
|
delete mSprite;
|
|
mSprite = nullptr;
|
|
|
|
delete mEventHandler;
|
|
mEventHandler = nullptr;
|
|
|
|
SDL_DestroyTexture(mBackbuffer);
|
|
mBackbuffer = nullptr;
|
|
}
|
|
|
|
// Inicializa las variables necesarias para la sección 'Logo'
|
|
void Logo::init()
|
|
{
|
|
// Carga los recursos
|
|
loadMedia();
|
|
|
|
// Inicializa variables
|
|
mCounter = 0;
|
|
mSection.name = PROG_SECTION_LOGO;
|
|
mSection.subsection = 0;
|
|
mSprite->init(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, mTexture, mRenderer);
|
|
mTicks = 0;
|
|
mTicksSpeed = 15;
|
|
}
|
|
|
|
// Carga los recursos necesarios para la sección 'Logo'
|
|
bool Logo::loadMedia()
|
|
{
|
|
bool success = true;
|
|
|
|
success &= loadTextureFromFile(mTexture, mFileList[35], mRenderer);
|
|
|
|
return success;
|
|
}
|
|
|
|
// Bucle para el logo del juego
|
|
section_t Logo::run()
|
|
{
|
|
init();
|
|
const SDL_Rect rect = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
|
|
|
|
while (mSection.name == PROG_SECTION_LOGO)
|
|
{
|
|
// Comprueba los eventos que hay en la cola
|
|
while (SDL_PollEvent(mEventHandler) != 0)
|
|
{
|
|
// Evento de salida de la aplicación
|
|
if (mEventHandler->type == SDL_QUIT)
|
|
{
|
|
mSection.name = PROG_SECTION_QUIT;
|
|
break;
|
|
}
|
|
|
|
// Cualquier tecla pulsada
|
|
if ((mEventHandler->type == SDL_KEYDOWN) || (mEventHandler->type == SDL_JOYBUTTONDOWN))
|
|
{
|
|
mSection.name = PROG_SECTION_TITLE;
|
|
mSection.subsection = TITLE_SECTION_1;
|
|
}
|
|
}
|
|
|
|
// Cambia el destino donde se pinta todo
|
|
//SDL_SetRenderTarget(mRenderer, mBackbuffer);
|
|
|
|
// Limpia el destino
|
|
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
|
SDL_RenderClear(mRenderer);
|
|
|
|
// Dibuja los objetos
|
|
mSprite->render();
|
|
|
|
// Dibuja el fade
|
|
if (mCounter >= 200)
|
|
{
|
|
Uint16 alpha = mCounter - 200;
|
|
if (alpha < 256)
|
|
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, alpha);
|
|
else
|
|
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255); // alpha - 0 trans, 255 opaco
|
|
SDL_RenderFillRect(mRenderer, &rect);
|
|
}
|
|
|
|
// Vuelve a usar el renderizador como destino
|
|
//SDL_SetRenderTarget(mRenderer, NULL);
|
|
|
|
// Copia el backbufer al renderizador
|
|
//SDL_RenderCopy(mRenderer, mBackbuffer, NULL, NULL);
|
|
|
|
// Actualiza la pantalla
|
|
SDL_RenderPresent(mRenderer);
|
|
|
|
// Comprueba si ha terminado el logo
|
|
if (SDL_GetTicks() - mTicks > mTicksSpeed)
|
|
{
|
|
// Actualiza el contador de ticks
|
|
mTicks = SDL_GetTicks();
|
|
|
|
if (mCounter == 0)
|
|
{
|
|
if (JA_GetMusicState() == JA_MUSIC_PLAYING)
|
|
JA_StopMusic();
|
|
}
|
|
|
|
if (mCounter == 500) // minimo 200 + 255
|
|
{
|
|
mCounter = 0;
|
|
mSection.name = PROG_SECTION_INTRO;
|
|
mSection.subsection = 0;
|
|
}
|
|
else
|
|
{
|
|
mCounter++;
|
|
}
|
|
}
|
|
}
|
|
|
|
return mSection;
|
|
}
|