223 lines
6.3 KiB
C++
223 lines
6.3 KiB
C++
#include "game_logo.h"
|
|
#include <algorithm> // for max
|
|
#include <string> // for basic_string
|
|
#include "animated_sprite.h" // for AnimatedSprite
|
|
#include "asset.h" // for Asset
|
|
#include "jail_audio.h" // for JA_DeleteSound, JA_LoadSound, JA_PlaySound
|
|
#include "param.h" // for param
|
|
#include "screen.h" // for Screen
|
|
#include "smart_sprite.h" // for SmartSprite
|
|
#include "sprite.h" // for Sprite
|
|
#include "texture.h" // for Texture
|
|
#include "utils.h" // for param_t, paramGame_t, paramTitle_t
|
|
|
|
// Constructor
|
|
GameLogo::GameLogo(int x, int y)
|
|
{
|
|
// Copia los punteros
|
|
screen = Screen::get();
|
|
renderer = screen->getRenderer();
|
|
asset = Asset::get();
|
|
this->x = x;
|
|
this->y = y;
|
|
|
|
// Crea los objetos
|
|
dustTexture = new Texture(renderer, asset->get("title_dust.png"));
|
|
coffeeTexture = new Texture(renderer, asset->get("title_coffee.png"));
|
|
crisisTexture = new Texture(renderer, asset->get("title_crisis.png"));
|
|
arcadeEditionTexture = new Texture(renderer, asset->get("title_arcade_edition.png"));
|
|
|
|
coffeeBitmap = new SmartSprite(coffeeTexture);
|
|
crisisBitmap = new SmartSprite(crisisTexture);
|
|
arcadeEditionBitmap = new Sprite((param.game.width - arcadeEditionTexture->getWidth()) / 2, param.title.arcadeEditionPosition, arcadeEditionTexture->getWidth(), arcadeEditionTexture->getHeight(), arcadeEditionTexture);
|
|
dustBitmapL = new AnimatedSprite(dustTexture, asset->get("title_dust.ani"));
|
|
dustBitmapR = new AnimatedSprite(dustTexture, asset->get("title_dust.ani"));
|
|
|
|
// Sonidos
|
|
crashSound = JA_LoadSound(asset->get("title.wav").c_str());
|
|
|
|
// Inicializa las variables
|
|
init();
|
|
}
|
|
|
|
// Destructor
|
|
GameLogo::~GameLogo()
|
|
{
|
|
delete dustTexture;
|
|
delete coffeeTexture;
|
|
delete crisisTexture;
|
|
delete arcadeEditionTexture;
|
|
|
|
delete coffeeBitmap;
|
|
delete crisisBitmap;
|
|
delete arcadeEditionBitmap;
|
|
delete dustBitmapL;
|
|
delete dustBitmapR;
|
|
|
|
JA_DeleteSound(crashSound);
|
|
}
|
|
|
|
// Inicializa las variables
|
|
void GameLogo::init()
|
|
{
|
|
const int xp = x - coffeeBitmap->getWidth() / 2;
|
|
const int desp = getInitialVerticalDesp();
|
|
|
|
// Variables
|
|
status = disabled;
|
|
shake.desp = 1;
|
|
shake.delay = 2;
|
|
shake.lenght = 8;
|
|
shake.remaining = shake.lenght;
|
|
shake.counter = shake.delay;
|
|
shake.origin = xp;
|
|
|
|
// Inicializa el bitmap de 'Coffee'
|
|
coffeeBitmap->init();
|
|
coffeeBitmap->setPosX(xp);
|
|
coffeeBitmap->setPosY(y - coffeeTexture->getHeight() - desp);
|
|
coffeeBitmap->setWidth(coffeeTexture->getWidth());
|
|
coffeeBitmap->setHeight(coffeeTexture->getHeight());
|
|
coffeeBitmap->setVelX(0.0f);
|
|
coffeeBitmap->setVelY(2.5f);
|
|
coffeeBitmap->setAccelX(0.0f);
|
|
coffeeBitmap->setAccelY(0.1f);
|
|
coffeeBitmap->setSpriteClip(0, 0, coffeeTexture->getWidth(), coffeeTexture->getHeight());
|
|
coffeeBitmap->setEnabled(true);
|
|
coffeeBitmap->setEnabledCounter(0);
|
|
coffeeBitmap->setDestX(xp);
|
|
coffeeBitmap->setDestY(y - coffeeTexture->getHeight());
|
|
|
|
// Inicializa el bitmap de 'Crisis'
|
|
crisisBitmap->init();
|
|
crisisBitmap->setPosX(xp + 15);
|
|
crisisBitmap->setPosY(y + desp);
|
|
crisisBitmap->setWidth(crisisTexture->getWidth());
|
|
crisisBitmap->setHeight(crisisTexture->getHeight());
|
|
crisisBitmap->setVelX(0.0f);
|
|
crisisBitmap->setVelY(-2.5f);
|
|
crisisBitmap->setAccelX(0.0f);
|
|
crisisBitmap->setAccelY(-0.1f);
|
|
crisisBitmap->setSpriteClip(0, 0, crisisTexture->getWidth(), crisisTexture->getHeight());
|
|
crisisBitmap->setEnabled(true);
|
|
crisisBitmap->setEnabledCounter(0);
|
|
crisisBitmap->setDestX(xp + 15);
|
|
crisisBitmap->setDestY(y);
|
|
|
|
// Inicializa el bitmap de 'DustRight'
|
|
dustBitmapR->resetAnimation();
|
|
dustBitmapR->setPosX(coffeeBitmap->getPosX() + coffeeBitmap->getWidth());
|
|
dustBitmapR->setPosY(y);
|
|
dustBitmapR->setWidth(16);
|
|
dustBitmapR->setHeight(16);
|
|
dustBitmapR->setFlip(SDL_FLIP_HORIZONTAL);
|
|
|
|
// Inicializa el bitmap de 'DustLeft'
|
|
dustBitmapL->resetAnimation();
|
|
dustBitmapL->setPosX(coffeeBitmap->getPosX() - 16);
|
|
dustBitmapL->setPosY(y);
|
|
dustBitmapL->setWidth(16);
|
|
dustBitmapL->setHeight(16);
|
|
}
|
|
|
|
// Pinta la clase en pantalla
|
|
void GameLogo::render()
|
|
{
|
|
// Dibuja el logo
|
|
coffeeBitmap->render();
|
|
crisisBitmap->render();
|
|
|
|
if (status == finished)
|
|
arcadeEditionBitmap->render();
|
|
|
|
// Dibuja el polvillo del logo
|
|
dustBitmapR->render();
|
|
dustBitmapL->render();
|
|
}
|
|
|
|
// Actualiza la lógica de la clase
|
|
void GameLogo::update()
|
|
{
|
|
if (status == moving)
|
|
{
|
|
coffeeBitmap->update();
|
|
crisisBitmap->update();
|
|
|
|
// Si los objetos han llegado a su destino, cambiamos de Sección
|
|
if (coffeeBitmap->hasFinished() && crisisBitmap->hasFinished())
|
|
{
|
|
status = shaking;
|
|
|
|
// Pantallazo blanco
|
|
//screen->flash(flashColor, 10);
|
|
|
|
// Reproduce el efecto sonoro
|
|
JA_PlaySound(crashSound);
|
|
}
|
|
}
|
|
|
|
else if (status == shaking)
|
|
{
|
|
// Agita el logo
|
|
if (shake.remaining > 0)
|
|
{
|
|
if (shake.counter > 0)
|
|
{
|
|
shake.counter--;
|
|
}
|
|
else
|
|
{
|
|
shake.counter = shake.delay;
|
|
const int desp = shake.remaining % 2 == 0 ? shake.desp * (-1) : shake.desp;
|
|
coffeeBitmap->setPosX(shake.origin + desp);
|
|
crisisBitmap->setPosX(shake.origin + desp + 15);
|
|
shake.remaining--;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
coffeeBitmap->setPosX(shake.origin);
|
|
crisisBitmap->setPosX(shake.origin + 15);
|
|
status = finished;
|
|
}
|
|
|
|
dustBitmapR->update();
|
|
dustBitmapL->update();
|
|
}
|
|
|
|
else if (status == finished)
|
|
{
|
|
dustBitmapR->update();
|
|
dustBitmapL->update();
|
|
}
|
|
}
|
|
|
|
// Activa la clase
|
|
void GameLogo::enable()
|
|
{
|
|
init();
|
|
status = moving;
|
|
}
|
|
|
|
// Indica si ha terminado la animación
|
|
bool GameLogo::hasFinished()
|
|
{
|
|
return (status == finished);
|
|
}
|
|
|
|
// Recarga las texturas
|
|
void GameLogo::reLoad()
|
|
{
|
|
dustTexture->reLoad();
|
|
coffeeTexture->reLoad();
|
|
crisisTexture->reLoad();
|
|
}
|
|
|
|
// Calcula el desplazamiento vertical inicial
|
|
int GameLogo::getInitialVerticalDesp()
|
|
{
|
|
int despUp = y;
|
|
int despDown = param.game.height - y;
|
|
|
|
return std::max(despUp, despDown);
|
|
} |