476 lines
10 KiB
C++
476 lines
10 KiB
C++
#include "intro.h"
|
|
#include "param.h"
|
|
|
|
// Constructor
|
|
Intro::Intro(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music)
|
|
{
|
|
// Copia los punteros
|
|
this->screen = screen;
|
|
this->asset = asset;
|
|
this->input = input;
|
|
this->section = section;
|
|
this->music = music;
|
|
SDL_Renderer *renderer = screen->getRenderer();
|
|
|
|
// Reserva memoria para los objetos
|
|
eventHandler = new SDL_Event();
|
|
texture = new Texture(renderer, asset->get("intro.png"));
|
|
text = new Text(asset->get("nokia.png"), asset->get("nokia.txt"), renderer);
|
|
|
|
// Inicializa variables
|
|
section->name = SECTION_PROG_INTRO;
|
|
section->options = 0;
|
|
ticks = 0;
|
|
ticksSpeed = 15;
|
|
scene = 1;
|
|
|
|
// Inicializa los bitmaps de la intro
|
|
const int totalBitmaps = 6;
|
|
for (int i = 0; i < totalBitmaps; ++i)
|
|
{
|
|
SmartSprite *ss = new SmartSprite(texture);
|
|
ss->setWidth(128);
|
|
ss->setHeight(96);
|
|
ss->setEnabledCounter(20);
|
|
ss->setDestX(param.game.gameArea.centerX - 64);
|
|
ss->setDestY(param.game.gameArea.firstQuarterY - 24);
|
|
bitmaps.push_back(ss);
|
|
}
|
|
|
|
bitmaps[0]->setPosX(-128);
|
|
bitmaps[0]->setPosY(param.game.gameArea.firstQuarterY - 24);
|
|
bitmaps[0]->setVelX(0.0f);
|
|
bitmaps[0]->setVelY(0.0f);
|
|
bitmaps[0]->setAccelX(0.6f);
|
|
bitmaps[0]->setAccelY(0.0f);
|
|
bitmaps[0]->setSpriteClip(0, 0, 128, 96);
|
|
|
|
bitmaps[1]->setPosX(param.game.width);
|
|
bitmaps[1]->setPosY(param.game.gameArea.firstQuarterY - 24);
|
|
bitmaps[1]->setVelX(-1.0f);
|
|
bitmaps[1]->setVelY(0.0f);
|
|
bitmaps[1]->setAccelX(-0.3f);
|
|
bitmaps[1]->setAccelY(0.0f);
|
|
bitmaps[1]->setSpriteClip(128, 0, 128, 96);
|
|
|
|
bitmaps[2]->setPosX(param.game.gameArea.centerX - 64);
|
|
bitmaps[2]->setPosY(-96);
|
|
bitmaps[2]->setVelX(0.0f);
|
|
bitmaps[2]->setVelY(3.0f);
|
|
bitmaps[2]->setAccelX(0.1f);
|
|
bitmaps[2]->setAccelY(0.3f);
|
|
bitmaps[2]->setSpriteClip(0, 96, 128, 96);
|
|
bitmaps[2]->setEnabledCounter(250);
|
|
|
|
bitmaps[3]->setPosX(param.game.gameArea.centerX - 64);
|
|
bitmaps[3]->setPosY(param.game.height);
|
|
bitmaps[3]->setVelX(0.0f);
|
|
bitmaps[3]->setVelY(-0.7f);
|
|
bitmaps[3]->setAccelX(0.0f);
|
|
bitmaps[3]->setAccelY(0.0f);
|
|
bitmaps[3]->setSpriteClip(128, 96, 128, 96);
|
|
|
|
bitmaps[4]->setPosX(param.game.gameArea.centerX - 64);
|
|
bitmaps[4]->setPosY(-96);
|
|
bitmaps[4]->setVelX(0.0f);
|
|
bitmaps[4]->setVelY(3.0f);
|
|
bitmaps[4]->setAccelX(0.1f);
|
|
bitmaps[4]->setAccelY(0.3f);
|
|
bitmaps[4]->setSpriteClip(0, 192, 128, 96);
|
|
|
|
bitmaps[5]->setPosX(param.game.width);
|
|
bitmaps[5]->setPosY(param.game.gameArea.firstQuarterY - 24);
|
|
bitmaps[5]->setVelX(-0.7f);
|
|
bitmaps[5]->setVelY(0.0f);
|
|
bitmaps[5]->setAccelX(0.0f);
|
|
bitmaps[5]->setAccelY(0.0f);
|
|
bitmaps[5]->setSpriteClip(128, 192, 128, 96);
|
|
|
|
// Inicializa los textos de la intro
|
|
const int totalTexts = 9;
|
|
for (int i = 0; i < totalTexts; ++i)
|
|
{
|
|
Writer *w = new Writer(text);
|
|
w->setPosX(BLOCK * 0);
|
|
w->setPosY(param.game.height - (BLOCK * 6));
|
|
w->setKerning(-1);
|
|
w->setEnabled(false);
|
|
w->setEnabledCounter(180);
|
|
texts.push_back(w);
|
|
}
|
|
|
|
// Un dia qualsevol de l'any 2000
|
|
texts[0]->setCaption(lang::getText(27));
|
|
texts[0]->setSpeed(8);
|
|
|
|
// Tot esta tranquil a la UPV
|
|
texts[1]->setCaption(lang::getText(28));
|
|
texts[1]->setSpeed(8);
|
|
|
|
// Fins que un desaprensiu...
|
|
texts[2]->setCaption(lang::getText(29));
|
|
texts[2]->setSpeed(12);
|
|
|
|
// HEY! ME ANE A FERME UN CORTAET...
|
|
texts[3]->setCaption(lang::getText(30));
|
|
texts[3]->setSpeed(8);
|
|
|
|
// UAAAAAAAAAAAAA!!!
|
|
texts[4]->setCaption(lang::getText(31));
|
|
texts[4]->setSpeed(1);
|
|
|
|
// Espera un moment...
|
|
texts[5]->setCaption(lang::getText(32));
|
|
texts[5]->setSpeed(16);
|
|
|
|
// Si resulta que no tinc solt!
|
|
texts[6]->setCaption(lang::getText(33));
|
|
texts[6]->setSpeed(2);
|
|
|
|
// MERDA DE MAQUINA!
|
|
texts[7]->setCaption(lang::getText(34));
|
|
texts[7]->setSpeed(3);
|
|
|
|
// Blop... blop... blop...
|
|
texts[8]->setCaption(lang::getText(35));
|
|
texts[8]->setSpeed(16);
|
|
|
|
for (auto text : texts)
|
|
{
|
|
text->center(param.game.gameArea.centerX);
|
|
}
|
|
}
|
|
|
|
// Destructor
|
|
Intro::~Intro()
|
|
{
|
|
delete eventHandler;
|
|
delete texture;
|
|
|
|
for (auto bitmap : bitmaps)
|
|
{
|
|
delete bitmap;
|
|
}
|
|
|
|
for (auto text : texts)
|
|
{
|
|
delete text;
|
|
}
|
|
}
|
|
|
|
// Recarga todas las texturas
|
|
void Intro::reloadTextures()
|
|
{
|
|
texture->reLoad();
|
|
text->reLoadTexture();
|
|
}
|
|
|
|
// Comprueba los eventos
|
|
void Intro::checkEvents()
|
|
{
|
|
// Comprueba los eventos que hay en la cola
|
|
while (SDL_PollEvent(eventHandler) != 0)
|
|
{
|
|
// Evento de salida de la aplicación
|
|
if (eventHandler->type == SDL_QUIT)
|
|
{
|
|
section->name = SECTION_PROG_QUIT;
|
|
break;
|
|
}
|
|
|
|
// Comprueba si se ha cambiado el tamaño de la ventana
|
|
else if (eventHandler->type == SDL_WINDOWEVENT)
|
|
{
|
|
if (eventHandler->window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
|
{
|
|
reloadTextures();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Comprueba las entradas
|
|
void Intro::checkInput()
|
|
{
|
|
// Comprueba si se sale con el teclado
|
|
if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
|
{
|
|
quit(SECTION_OPTIONS_QUIT_NORMAL);
|
|
return;
|
|
}
|
|
|
|
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
|
if (input->checkAnyButtonPressed())
|
|
{
|
|
JA_StopMusic();
|
|
section->name = SECTION_PROG_TITLE;
|
|
section->options = SECTION_OPTIONS_TITLE_1;
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < input->getNumControllers(); ++i)
|
|
{
|
|
// Comprueba si se sale con el mando
|
|
if (input->checkModInput(input_service, input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
|
{
|
|
quit(SECTION_OPTIONS_QUIT_SHUTDOWN);
|
|
return;
|
|
}
|
|
|
|
// Comprueba si se va a resetear el juego
|
|
if (input->checkModInput(input_service, input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
|
{
|
|
section->name = SECTION_PROG_INIT;
|
|
screen->showNotification("Reset");
|
|
return;
|
|
}
|
|
|
|
// Comprueba si se va a activar o desactivar el audio
|
|
if (input->checkModInput(input_service, input_mute, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
|
{
|
|
options->audio.sound.enabled = options->audio.music.enabled = !options->audio.music.enabled;
|
|
JA_EnableMusic(options->audio.music.enabled);
|
|
JA_EnableSound(options->audio.sound.enabled);
|
|
screen->showNotification("Audio " + boolToOnOff(options->audio.music.enabled));
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Comprueba el input para el resto de objetos
|
|
screen->checkInput();
|
|
}
|
|
|
|
// Actualiza las escenas de la intro
|
|
void Intro::updateScenes()
|
|
{
|
|
switch (scene)
|
|
{
|
|
case 1:
|
|
// Primera imagen - UPV
|
|
if (!bitmaps[0]->hasFinished())
|
|
{
|
|
bitmaps[0]->setEnabled(true);
|
|
}
|
|
|
|
// Primer texto de la primera imagen
|
|
if (bitmaps[0]->hasFinished() && !texts[0]->hasFinished())
|
|
{
|
|
texts[0]->setEnabled(true);
|
|
}
|
|
|
|
// Segundo texto de la primera imagen
|
|
if (texts[0]->hasFinished() && !texts[1]->hasFinished())
|
|
{
|
|
texts[0]->setEnabled(false);
|
|
texts[1]->setEnabled(true);
|
|
}
|
|
|
|
// Tercer texto de la primera imagen
|
|
if (texts[1]->hasFinished() && !texts[2]->hasFinished())
|
|
{
|
|
texts[1]->setEnabled(false);
|
|
texts[2]->setEnabled(true);
|
|
}
|
|
|
|
// Fin de la primera escena
|
|
if (texts[2]->hasFinished())
|
|
{
|
|
bitmaps[0]->setEnabled(false);
|
|
texts[2]->setEnabled(false);
|
|
scene++;
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
// Segunda imagen - Máquina
|
|
if (!bitmaps[1]->hasFinished())
|
|
{
|
|
bitmaps[1]->setEnabled(true);
|
|
}
|
|
|
|
// Primer texto de la segunda imagen
|
|
if (bitmaps[1]->hasFinished() && !texts[3]->hasFinished())
|
|
{
|
|
texts[3]->setEnabled(true);
|
|
}
|
|
|
|
// Fin de la segunda escena
|
|
if (texts[3]->hasFinished())
|
|
{
|
|
bitmaps[1]->setEnabled(false);
|
|
texts[3]->setEnabled(false);
|
|
scene++;
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
// Tercera imagen junto con primer texto - GRITO
|
|
if (!bitmaps[2]->hasFinished() && !texts[4]->hasFinished())
|
|
{
|
|
bitmaps[2]->setEnabled(true);
|
|
texts[4]->setEnabled(true);
|
|
}
|
|
|
|
// Fin de la tercera escena
|
|
if (bitmaps[2]->hasFinished() && texts[4]->hasFinished())
|
|
{
|
|
bitmaps[2]->setEnabled(false);
|
|
texts[4]->setEnabled(false);
|
|
scene++;
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
// Cuarta imagen junto con primer texto - Reflexión
|
|
if (!bitmaps[3]->hasFinished() && !texts[5]->hasFinished())
|
|
{
|
|
bitmaps[3]->setEnabled(true);
|
|
texts[5]->setEnabled(true);
|
|
}
|
|
|
|
// Segundo texto de la cuarta imagen
|
|
if (texts[5]->hasFinished() && !texts[6]->hasFinished())
|
|
{
|
|
texts[5]->setEnabled(false);
|
|
texts[6]->setEnabled(true);
|
|
}
|
|
|
|
// Fin de la cuarta escena
|
|
if (bitmaps[3]->hasFinished() && texts[6]->hasFinished())
|
|
{
|
|
bitmaps[3]->setEnabled(false);
|
|
texts[6]->setEnabled(false);
|
|
scene++;
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
|
// Quinta imagen - Patada
|
|
if (!bitmaps[4]->hasFinished())
|
|
{
|
|
bitmaps[4]->setEnabled(true);
|
|
}
|
|
|
|
// Primer texto de la quinta imagen
|
|
if (bitmaps[4]->hasFinished() && !texts[7]->hasFinished())
|
|
{
|
|
texts[7]->setEnabled(true);
|
|
}
|
|
|
|
// Fin de la quinta escena
|
|
if (bitmaps[4]->hasFinished() && texts[7]->hasFinished())
|
|
{
|
|
bitmaps[4]->setEnabled(false);
|
|
texts[7]->setEnabled(false);
|
|
scene++;
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
|
// Sexta imagen junto con texto - Globos de café
|
|
if (!bitmaps[5]->hasFinished() && !texts[8]->hasFinished())
|
|
{
|
|
bitmaps[5]->setEnabled(true);
|
|
texts[8]->setEnabled(true);
|
|
}
|
|
|
|
// Acaba el último texto
|
|
if (bitmaps[5]->hasFinished() && texts[8]->hasFinished())
|
|
{
|
|
bitmaps[5]->setEnabled(false);
|
|
texts[8]->setEnabled(false);
|
|
JA_StopMusic();
|
|
section->name = SECTION_PROG_TITLE;
|
|
section->options = SECTION_OPTIONS_TITLE_1;
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Actualiza las variables del objeto
|
|
void Intro::update()
|
|
{
|
|
if (SDL_GetTicks() - ticks > ticksSpeed)
|
|
{
|
|
// Actualiza el contador de ticks
|
|
ticks = SDL_GetTicks();
|
|
|
|
// Actualiza el objeto screen
|
|
screen->update();
|
|
|
|
// Actualiza los objetos
|
|
for (auto bitmap : bitmaps)
|
|
{
|
|
bitmap->update();
|
|
}
|
|
|
|
for (auto text : texts)
|
|
{
|
|
text->update();
|
|
}
|
|
|
|
// Actualiza las escenas de la intro
|
|
updateScenes();
|
|
}
|
|
}
|
|
|
|
// Dibuja el objeto en pantalla
|
|
void Intro::render()
|
|
{
|
|
// Prepara para empezar a dibujar en la textura de juego
|
|
screen->start();
|
|
|
|
// Limpia la pantalla
|
|
screen->clean(bgColor);
|
|
|
|
// Dibuja los objetos
|
|
for (auto bitmap : bitmaps)
|
|
{
|
|
bitmap->render();
|
|
}
|
|
|
|
for (auto text : texts)
|
|
{
|
|
text->render();
|
|
}
|
|
|
|
// Vuelca el contenido del renderizador en pantalla
|
|
screen->blit();
|
|
}
|
|
|
|
// Bucle principal
|
|
void Intro::run()
|
|
{
|
|
JA_PlayMusic(music, 0);
|
|
|
|
while (section->name == SECTION_PROG_INTRO)
|
|
{
|
|
checkInput();
|
|
update();
|
|
checkEvents(); // Tiene que ir antes del render
|
|
render();
|
|
}
|
|
}
|
|
|
|
// Termina
|
|
void Intro::quit(int code)
|
|
{
|
|
if (screen->notificationsAreActive())
|
|
{
|
|
section->name = SECTION_PROG_QUIT;
|
|
section->options = code;
|
|
}
|
|
else
|
|
{
|
|
screen->showNotification(lang::getText(94));
|
|
}
|
|
} |