Completado el logo y la intro
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
png_width_in_tiles=6
|
frames_per_row=6
|
||||||
tile_width=16
|
frame_width=16
|
||||||
tile_height=16
|
frame_height=16
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=walk
|
name=walk
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
png_width_in_tiles=6
|
frames_per_row=6
|
||||||
tile_width=16
|
frame_width=16
|
||||||
tile_height=16
|
frame_height=16
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=walk
|
name=walk
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
png_width_in_tiles=6
|
frames_per_row=6
|
||||||
tile_width=16
|
frame_width=16
|
||||||
tile_height=16
|
frame_height=16
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=walk
|
name=walk
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
png_width_in_tiles=6
|
frames_per_row=6
|
||||||
tile_width=16
|
frame_width=16
|
||||||
tile_height=16
|
frame_height=16
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=walk
|
name=walk
|
||||||
|
|||||||
17
data/intro/intro.ani
Normal file
17
data/intro/intro.ani
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
frames_per_row=4
|
||||||
|
frame_width=320
|
||||||
|
frame_height=240
|
||||||
|
|
||||||
|
[animation]
|
||||||
|
name=intro
|
||||||
|
speed=12
|
||||||
|
loop=-1
|
||||||
|
frames=0,1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26
|
||||||
|
[/animation]
|
||||||
|
|
||||||
|
[animation]
|
||||||
|
name=menu
|
||||||
|
speed=12
|
||||||
|
loop=0
|
||||||
|
frames=18,26,18,26,18,26,18,26,18,26,18,26,18,26,18,19,20,21,22,23,24,25,26
|
||||||
|
[/animation]
|
||||||
BIN
data/intro/intro.png
Normal file
BIN
data/intro/intro.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 670 KiB |
BIN
data/logo/logo.png
Normal file
BIN
data/logo/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
@@ -1,6 +1,6 @@
|
|||||||
png_width_in_tiles=8
|
frames_per_row=8
|
||||||
tile_width=16
|
frame_width=16
|
||||||
tile_height=24
|
frame_height=24
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=stand
|
name=stand
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ AnimatedSprite::AnimatedSprite(LTexture *texture, SDL_Renderer *renderer, std::s
|
|||||||
|
|
||||||
// Carga las animaciones
|
// Carga las animaciones
|
||||||
load(file);
|
load(file);
|
||||||
|
|
||||||
|
// Inicializa variables
|
||||||
|
currentAnimation = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -51,6 +54,7 @@ void AnimatedSprite::animate()
|
|||||||
if (animation[currentAnimation].loop == -1)
|
if (animation[currentAnimation].loop == -1)
|
||||||
{ // Si no hay loop, deja el último frame
|
{ // Si no hay loop, deja el último frame
|
||||||
animation[currentAnimation].currentFrame = animation[currentAnimation].frames.size();
|
animation[currentAnimation].currentFrame = animation[currentAnimation].frames.size();
|
||||||
|
animation[currentAnimation].completed = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // Si hay loop, vuelve al frame indicado
|
{ // Si hay loop, vuelve al frame indicado
|
||||||
@@ -101,9 +105,9 @@ void AnimatedSprite::setAnimationCompleted(std::string name, bool value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si ha terminado la animación
|
// Comprueba si ha terminado la animación
|
||||||
bool AnimatedSprite::animationIsCompleted(std::string name)
|
bool AnimatedSprite::animationIsCompleted()
|
||||||
{
|
{
|
||||||
return animation[getIndex(name)].completed;
|
return animation[currentAnimation].completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve el rectangulo de una animación y frame concreto
|
// Devuelve el rectangulo de una animación y frame concreto
|
||||||
@@ -115,9 +119,10 @@ SDL_Rect AnimatedSprite::getAnimationClip(std::string name, Uint8 index)
|
|||||||
// Carga la animación desde un fichero
|
// Carga la animación desde un fichero
|
||||||
bool AnimatedSprite::load(std::string filePath)
|
bool AnimatedSprite::load(std::string filePath)
|
||||||
{
|
{
|
||||||
int png_width_in_tiles = 0;
|
int frames_per_row = 0;
|
||||||
int tile_width = 0;
|
int frame_width = 0;
|
||||||
int tile_height = 0;
|
int frame_height = 0;
|
||||||
|
|
||||||
// Indicador de éxito en la carga
|
// Indicador de éxito en la carga
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
@@ -167,12 +172,12 @@ bool AnimatedSprite::load(std::string filePath)
|
|||||||
// Se introducen los valores separados por comas en un vector
|
// Se introducen los valores separados por comas en un vector
|
||||||
std::stringstream ss(line.substr(pos + 1, line.length()));
|
std::stringstream ss(line.substr(pos + 1, line.length()));
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
SDL_Rect rect = {0, 0, tile_width, tile_height};
|
SDL_Rect rect = {0, 0, frame_width, frame_height};
|
||||||
while (getline(ss, tmp, ','))
|
while (getline(ss, tmp, ','))
|
||||||
{
|
{
|
||||||
int num_tile = std::stoi(tmp);
|
int num_tile = std::stoi(tmp);
|
||||||
rect.x = (num_tile % png_width_in_tiles) * tile_width;
|
rect.x = (num_tile % frames_per_row) * frame_width;
|
||||||
rect.y = (num_tile / png_width_in_tiles) * tile_height;
|
rect.y = (num_tile / frames_per_row) * frame_height;
|
||||||
buffer.frames.push_back(rect);
|
buffer.frames.push_back(rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,17 +202,17 @@ bool AnimatedSprite::load(std::string filePath)
|
|||||||
// Procesa las dos subcadenas
|
// Procesa las dos subcadenas
|
||||||
if (pos != line.npos)
|
if (pos != line.npos)
|
||||||
{
|
{
|
||||||
if (line.substr(0, pos) == "png_width_in_tiles")
|
if (line.substr(0, pos) == "frames_per_row")
|
||||||
{
|
{
|
||||||
png_width_in_tiles = std::stoi(line.substr(pos + 1, line.length()));
|
frames_per_row = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
}
|
}
|
||||||
else if (line.substr(0, pos) == "tile_width")
|
else if (line.substr(0, pos) == "frame_width")
|
||||||
{
|
{
|
||||||
tile_width = std::stoi(line.substr(pos + 1, line.length()));
|
frame_width = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
}
|
}
|
||||||
else if (line.substr(0, pos) == "tile_height")
|
else if (line.substr(0, pos) == "frame_height")
|
||||||
{
|
{
|
||||||
tile_height = std::stoi(line.substr(pos + 1, line.length()));
|
frame_height = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -229,6 +234,9 @@ bool AnimatedSprite::load(std::string filePath)
|
|||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pone un valor por defecto
|
||||||
|
setPos({0, 0, frame_width, frame_height});
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public:
|
|||||||
void setAnimationCompleted(std::string name, bool value);
|
void setAnimationCompleted(std::string name, bool value);
|
||||||
|
|
||||||
// Comprueba si ha terminado la animación
|
// Comprueba si ha terminado la animación
|
||||||
bool animationIsCompleted(std::string name);
|
bool animationIsCompleted();
|
||||||
|
|
||||||
// Devuelve el rectangulo de una animación y frame concreto
|
// Devuelve el rectangulo de una animación y frame concreto
|
||||||
SDL_Rect getAnimationClip(std::string name, Uint8 index);
|
SDL_Rect getAnimationClip(std::string name, Uint8 index);
|
||||||
|
|||||||
407
source/intro.cpp
407
source/intro.cpp
@@ -1,378 +1,99 @@
|
|||||||
#include "intro.h"
|
#include "intro.h"
|
||||||
#ifdef __MIPSEL__
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Intro::Intro(SDL_Renderer *renderer, Screen *screen, std::string *fileList, Lang *lang)
|
Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
// Copia los punteros
|
||||||
mRenderer = renderer;
|
this->renderer = renderer;
|
||||||
mScreen = screen;
|
this->screen = screen;
|
||||||
mFileList = fileList;
|
this->asset = asset;
|
||||||
mLang = lang;
|
|
||||||
|
|
||||||
// Reserva memoria para los punteros
|
// Reserva memoria para los punteros
|
||||||
mEventHandler = new SDL_Event();
|
eventHandler = new SDL_Event();
|
||||||
mBitmapTexture = new LTexture();
|
texture = new LTexture();
|
||||||
mTextTexture = new LTexture();
|
loadTextureFromFile(texture, asset->get("intro.png"), renderer);
|
||||||
mText = new Text(mFileList[52], mTextTexture, mRenderer);
|
sprite = new AnimatedSprite(texture, renderer, asset->get("intro.ani"));
|
||||||
|
|
||||||
for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++)
|
// Inicializa variables
|
||||||
mBitmap[i] = new SmartSprite();
|
section = {SECTION_PROG_INTRO, 0};
|
||||||
|
ticks = 0;
|
||||||
for (int i = 0; i < INTRO_TOTAL_TEXTS; i++)
|
ticksSpeed = 15;
|
||||||
mWriter[i] = new Writer(mText);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Intro::~Intro()
|
Intro::~Intro()
|
||||||
{
|
{
|
||||||
mRenderer = nullptr;
|
renderer = nullptr;
|
||||||
mScreen = nullptr;
|
screen = nullptr;
|
||||||
mFileList = nullptr;
|
asset = nullptr;
|
||||||
mLang = nullptr;
|
|
||||||
|
|
||||||
delete mEventHandler;
|
delete eventHandler;
|
||||||
mEventHandler = nullptr;
|
eventHandler = nullptr;
|
||||||
|
|
||||||
mBitmapTexture->unload();
|
texture->unload();
|
||||||
delete mBitmapTexture;
|
delete texture;
|
||||||
mBitmapTexture = nullptr;
|
texture = nullptr;
|
||||||
|
|
||||||
mTextTexture->unload();
|
|
||||||
delete mTextTexture;
|
|
||||||
mTextTexture = nullptr;
|
|
||||||
|
|
||||||
for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++)
|
|
||||||
{
|
|
||||||
delete mBitmap[i];
|
|
||||||
mBitmap[i] = nullptr;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < INTRO_TOTAL_TEXTS; i++)
|
|
||||||
{
|
|
||||||
delete mWriter[i];
|
|
||||||
mWriter[i] = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_DeleteMusic(mMusic);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa las variables
|
// Actualiza las variables
|
||||||
void Intro::init()
|
void Intro::update()
|
||||||
{
|
{
|
||||||
// Carga los recursos
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||||
loadMedia();
|
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||||
|
|
||||||
mSection = {PROG_SECTION_INTRO, 0};
|
|
||||||
mTicks = 0;
|
|
||||||
mTicksSpeed = 15;
|
|
||||||
|
|
||||||
// Inicializa el vector de eventos de la intro
|
|
||||||
for (int i = 0; i < INTRO_TOTAL_EVENTS; i++)
|
|
||||||
mEvents[i] = EVENT_WAITING;
|
|
||||||
|
|
||||||
// Inicializa los bitmaps de la intro
|
|
||||||
for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++)
|
|
||||||
{
|
{
|
||||||
mBitmap[i]->init(mBitmapTexture, mRenderer);
|
// Actualiza el contador de ticks
|
||||||
mBitmap[i]->setId(i);
|
ticks = SDL_GetTicks();
|
||||||
mBitmap[i]->setIntroEvents(&mEvents[0]);
|
|
||||||
mBitmap[i]->setWidth(128);
|
// Comprueba los eventos que hay en la cola
|
||||||
mBitmap[i]->setHeight(96);
|
while (SDL_PollEvent(eventHandler) != 0)
|
||||||
mBitmap[i]->setEnabled(false);
|
{
|
||||||
mBitmap[i]->setEnabledTimer(20);
|
// Evento de salida de la aplicación
|
||||||
mBitmap[i]->setDestX(SCREEN_CENTER_X - 64);
|
if (eventHandler->type == SDL_QUIT)
|
||||||
mBitmap[i]->setDestY(SCREEN_FIRST_QUARTER_Y - 24);
|
{
|
||||||
|
section.name = SECTION_PROG_QUIT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cualquier tecla pulsada
|
||||||
|
if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
||||||
|
{
|
||||||
|
section.name = SECTION_PROG_GAME;
|
||||||
|
section.subsection = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sprite->animate();
|
||||||
|
|
||||||
|
if (sprite->animationIsCompleted())
|
||||||
|
{
|
||||||
|
section.name = SECTION_PROG_GAME;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mBitmap[0]->setPosX(-128);
|
|
||||||
mBitmap[0]->setPosY(SCREEN_FIRST_QUARTER_Y - 24);
|
|
||||||
mBitmap[0]->setVelX(0.0f);
|
|
||||||
mBitmap[0]->setVelY(0.0f);
|
|
||||||
mBitmap[0]->setAccelX(0.6f);
|
|
||||||
mBitmap[0]->setAccelY(0.0f);
|
|
||||||
mBitmap[0]->setSpriteClip(0, 0, 128, 96);
|
|
||||||
|
|
||||||
mBitmap[1]->setPosX(SCREEN_WIDTH);
|
|
||||||
mBitmap[1]->setPosY(SCREEN_FIRST_QUARTER_Y - 24);
|
|
||||||
mBitmap[1]->setVelX(-1.0f);
|
|
||||||
mBitmap[1]->setVelY(0.0f);
|
|
||||||
mBitmap[1]->setAccelX(-0.3f);
|
|
||||||
mBitmap[1]->setAccelY(0.0f);
|
|
||||||
mBitmap[1]->setSpriteClip(128, 0, 128, 96);
|
|
||||||
|
|
||||||
mBitmap[2]->setPosX(SCREEN_CENTER_X - 64);
|
|
||||||
mBitmap[2]->setPosY(-96);
|
|
||||||
mBitmap[2]->setVelX(0.0f);
|
|
||||||
mBitmap[2]->setVelY(3.0f);
|
|
||||||
mBitmap[2]->setAccelX(0.1f);
|
|
||||||
mBitmap[2]->setAccelY(0.3f);
|
|
||||||
mBitmap[2]->setSpriteClip(0, 96, 128, 96);
|
|
||||||
|
|
||||||
mBitmap[2]->setEnabledTimer(250);
|
|
||||||
|
|
||||||
mBitmap[3]->setPosX(SCREEN_CENTER_X - 64);
|
|
||||||
mBitmap[3]->setPosY(SCREEN_HEIGHT);
|
|
||||||
mBitmap[3]->setVelX(0.0f);
|
|
||||||
mBitmap[3]->setVelY(-0.7f);
|
|
||||||
mBitmap[3]->setAccelX(0.0f);
|
|
||||||
mBitmap[3]->setAccelY(0.0f);
|
|
||||||
mBitmap[3]->setSpriteClip(128, 96, 128, 96);
|
|
||||||
|
|
||||||
mBitmap[4]->setPosX(SCREEN_CENTER_X - 64);
|
|
||||||
mBitmap[4]->setPosY(-96);
|
|
||||||
mBitmap[4]->setVelX(0.0f);
|
|
||||||
mBitmap[4]->setVelY(3.0f);
|
|
||||||
mBitmap[4]->setAccelX(0.1f);
|
|
||||||
mBitmap[4]->setAccelY(0.3f);
|
|
||||||
mBitmap[4]->setSpriteClip(0, 192, 128, 96);
|
|
||||||
|
|
||||||
mBitmap[5]->setPosX(SCREEN_WIDTH);
|
|
||||||
mBitmap[5]->setPosY(SCREEN_FIRST_QUARTER_Y - 24);
|
|
||||||
mBitmap[5]->setVelX(-0.7f);
|
|
||||||
mBitmap[5]->setVelY(0.0f);
|
|
||||||
mBitmap[5]->setAccelX(0.0f);
|
|
||||||
mBitmap[5]->setAccelY(0.0f);
|
|
||||||
mBitmap[5]->setSpriteClip(128, 192, 128, 96);
|
|
||||||
|
|
||||||
// Inicializa los textos de la intro
|
|
||||||
for (int i = 0; i < INTRO_TOTAL_TEXTS; i++)
|
|
||||||
{
|
|
||||||
mWriter[i]->init();
|
|
||||||
mWriter[i]->setId(6 + i);
|
|
||||||
mWriter[i]->setIntroEvents(&mEvents[0]);
|
|
||||||
mWriter[i]->setPosX(BLOCK * 0);
|
|
||||||
mWriter[i]->setPosY(SCREEN_HEIGHT - (BLOCK * 6));
|
|
||||||
mWriter[i]->setKerning(-1);
|
|
||||||
mWriter[i]->setEnabled(false);
|
|
||||||
mWriter[i]->setEnabledTimer(180);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Un dia qualsevol de l'any 2000
|
|
||||||
mWriter[0]->setCaption(mLang->getText(27));
|
|
||||||
mWriter[0]->setSpeed(10);
|
|
||||||
|
|
||||||
// Tot esta tranquil a la UPV
|
|
||||||
mWriter[1]->setCaption(mLang->getText(28));
|
|
||||||
mWriter[1]->setSpeed(10);
|
|
||||||
|
|
||||||
// Fins que un desaprensiu...
|
|
||||||
mWriter[2]->setCaption(mLang->getText(29));
|
|
||||||
mWriter[2]->setSpeed(15);
|
|
||||||
|
|
||||||
// HEY! ME ANE A FERME UN CORTAET...
|
|
||||||
mWriter[3]->setCaption(mLang->getText(30));
|
|
||||||
mWriter[3]->setSpeed(10);
|
|
||||||
|
|
||||||
// UAAAAAAAAAAAAA!!!
|
|
||||||
mWriter[4]->setCaption(mLang->getText(31));
|
|
||||||
mWriter[4]->setSpeed(1);
|
|
||||||
|
|
||||||
// Espera un moment...
|
|
||||||
mWriter[5]->setCaption(mLang->getText(32));
|
|
||||||
mWriter[5]->setSpeed(20);
|
|
||||||
|
|
||||||
// Si resulta que no tinc solt!
|
|
||||||
mWriter[6]->setCaption(mLang->getText(33));
|
|
||||||
mWriter[6]->setSpeed(2);
|
|
||||||
|
|
||||||
// MERDA DE MAQUINA!
|
|
||||||
mWriter[7]->setCaption(mLang->getText(34));
|
|
||||||
mWriter[7]->setSpeed(3);
|
|
||||||
|
|
||||||
// Blop... blop... blop...
|
|
||||||
mWriter[8]->setCaption(mLang->getText(35));
|
|
||||||
mWriter[8]->setSpeed(20);
|
|
||||||
|
|
||||||
for (int i = 0; i < INTRO_TOTAL_TEXTS; i++)
|
|
||||||
mWriter[i]->center(SCREEN_CENTER_X);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga los recursos
|
// Dibuja en pantalla
|
||||||
bool Intro::loadMedia()
|
void Intro::render()
|
||||||
{
|
{
|
||||||
bool success = true;
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
|
screen->start();
|
||||||
|
|
||||||
// Texturas
|
// Limpia la pantalla
|
||||||
success &= loadTextureFromFile(mBitmapTexture, mFileList[33], mRenderer);
|
screen->clean();
|
||||||
success &= loadTextureFromFile(mTextTexture, mFileList[28], mRenderer);
|
|
||||||
|
|
||||||
// Musicas
|
// Dibuja los objetos
|
||||||
mMusic = JA_LoadMusic(mFileList[3].c_str());
|
sprite->render();
|
||||||
|
|
||||||
return success;
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
|
screen->blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
section_t Intro::run()
|
section_t Intro::run()
|
||||||
{
|
{
|
||||||
init();
|
while (section.name == SECTION_PROG_INTRO)
|
||||||
|
|
||||||
// Si la música no está sonando la hace sonar
|
|
||||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
|
||||||
JA_PlayMusic(mMusic, 0);
|
|
||||||
|
|
||||||
while (mSection.name == PROG_SECTION_INTRO)
|
|
||||||
{
|
{
|
||||||
// Comprueba los eventos que hay en la cola
|
update();
|
||||||
while (SDL_PollEvent(mEventHandler) != 0)
|
render();
|
||||||
{
|
|
||||||
// Evento de salida de la aplicación
|
|
||||||
if (mEventHandler->type == SDL_QUIT)
|
|
||||||
{
|
|
||||||
mSection.name = PROG_SECTION_QUIT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((mEventHandler->type == SDL_KEYDOWN) || (mEventHandler->type == SDL_JOYBUTTONDOWN))
|
|
||||||
{
|
|
||||||
JA_StopMusic();
|
|
||||||
mSection = {PROG_SECTION_TITLE, TITLE_SECTION_1};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza las variables
|
|
||||||
if (SDL_GetTicks() - mTicks > mTicksSpeed)
|
|
||||||
{
|
|
||||||
// Actualiza el contador de ticks
|
|
||||||
mTicks = SDL_GetTicks();
|
|
||||||
|
|
||||||
// Actualiza los objetos
|
|
||||||
for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++)
|
|
||||||
mBitmap[i]->update();
|
|
||||||
for (int i = 0; i < INTRO_TOTAL_TEXTS; i++)
|
|
||||||
mWriter[i]->update();
|
|
||||||
|
|
||||||
// Guión de eventos
|
|
||||||
// Primera imagen - UPV
|
|
||||||
if (mEvents[BITMAP0] == EVENT_WAITING)
|
|
||||||
{
|
|
||||||
mBitmap[0]->setEnabled(true);
|
|
||||||
mEvents[BITMAP0] = EVENT_RUNNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Primer texto de la primera imagen
|
|
||||||
if ((mEvents[BITMAP0] == EVENT_COMPLETED) && (mEvents[TEXT0] == EVENT_WAITING))
|
|
||||||
{
|
|
||||||
mWriter[0]->setEnabled(true);
|
|
||||||
mEvents[TEXT0] = EVENT_RUNNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Segundo texto de la primera imagen
|
|
||||||
if ((mEvents[TEXT0] == EVENT_COMPLETED) && (mEvents[TEXT1] == EVENT_WAITING))
|
|
||||||
{
|
|
||||||
mWriter[0]->setEnabled(false);
|
|
||||||
mWriter[1]->setEnabled(true);
|
|
||||||
mEvents[TEXT1] = EVENT_RUNNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tercer texto de la primera imagen
|
|
||||||
if ((mEvents[TEXT1] == EVENT_COMPLETED) && (mEvents[TEXT2] == EVENT_WAITING))
|
|
||||||
{
|
|
||||||
mWriter[1]->setEnabled(false);
|
|
||||||
mWriter[2]->setEnabled(true);
|
|
||||||
mEvents[TEXT2] = EVENT_RUNNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Segunda imagen - Máquina
|
|
||||||
if ((mEvents[TEXT2] == EVENT_COMPLETED) && (mEvents[BITMAP1] == EVENT_WAITING))
|
|
||||||
{
|
|
||||||
mBitmap[0]->setEnabled(false);
|
|
||||||
mWriter[2]->setEnabled(false);
|
|
||||||
mBitmap[1]->setEnabled(true);
|
|
||||||
mEvents[BITMAP1] = EVENT_RUNNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Primer texto de la segunda imagen
|
|
||||||
if ((mEvents[BITMAP1] == EVENT_COMPLETED) && (mEvents[TEXT3] == EVENT_WAITING))
|
|
||||||
{
|
|
||||||
mWriter[3]->setEnabled(true);
|
|
||||||
mEvents[TEXT3] = EVENT_RUNNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tercera imagen junto con primer texto - GRITO
|
|
||||||
if ((mEvents[TEXT3] == EVENT_COMPLETED) && (mEvents[BITMAP2] == EVENT_WAITING) && (mEvents[TEXT4] == EVENT_WAITING))
|
|
||||||
{
|
|
||||||
mBitmap[1]->setEnabled(false);
|
|
||||||
mWriter[3]->setEnabled(false);
|
|
||||||
mBitmap[2]->setEnabled(true);
|
|
||||||
mWriter[4]->setEnabled(true);
|
|
||||||
mEvents[BITMAP2] = EVENT_RUNNING;
|
|
||||||
mEvents[TEXT4] = EVENT_RUNNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cuarta imagen junto con primer texto - Reflexión
|
|
||||||
if ((mEvents[TEXT4] == EVENT_COMPLETED) && (mEvents[BITMAP3] == EVENT_WAITING) && (mEvents[TEXT5] == EVENT_WAITING))
|
|
||||||
{
|
|
||||||
mBitmap[2]->setEnabled(false);
|
|
||||||
mWriter[4]->setEnabled(false);
|
|
||||||
mBitmap[3]->setEnabled(true);
|
|
||||||
mWriter[5]->setEnabled(true);
|
|
||||||
mEvents[BITMAP3] = EVENT_RUNNING;
|
|
||||||
mEvents[TEXT5] = EVENT_RUNNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Segundo texto de la cuarta imagen
|
|
||||||
if ((mEvents[TEXT5] == EVENT_COMPLETED) && (mEvents[TEXT6] == EVENT_WAITING))
|
|
||||||
{
|
|
||||||
mWriter[5]->setEnabled(false);
|
|
||||||
mWriter[6]->setEnabled(true);
|
|
||||||
mEvents[TEXT6] = EVENT_RUNNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Quinta imagen - Patada
|
|
||||||
if ((mEvents[TEXT6] == EVENT_COMPLETED) && (mEvents[BITMAP4] == EVENT_WAITING))
|
|
||||||
{
|
|
||||||
mBitmap[3]->setEnabled(false);
|
|
||||||
mWriter[6]->setEnabled(false);
|
|
||||||
mBitmap[4]->setEnabled(true);
|
|
||||||
mEvents[BITMAP4] = EVENT_RUNNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Primer texto de la quinta imagen
|
|
||||||
if ((mEvents[BITMAP4] == EVENT_COMPLETED) && (mEvents[TEXT7] == EVENT_WAITING))
|
|
||||||
{
|
|
||||||
mWriter[7]->setEnabled(true);
|
|
||||||
mEvents[TEXT7] = EVENT_RUNNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sexta imagen junto con texto - Globos de café
|
|
||||||
if ((mEvents[TEXT7] == EVENT_COMPLETED) && (mEvents[BITMAP5] == EVENT_WAITING) && (mEvents[TEXT8] == EVENT_WAITING))
|
|
||||||
{
|
|
||||||
mBitmap[4]->setEnabled(false);
|
|
||||||
mWriter[7]->setEnabled(false);
|
|
||||||
mBitmap[5]->setEnabled(true);
|
|
||||||
mWriter[8]->setEnabled(true);
|
|
||||||
mEvents[BITMAP5] = EVENT_RUNNING;
|
|
||||||
mEvents[TEXT8] = EVENT_RUNNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Acaba el último texto
|
|
||||||
if (mEvents[TEXT8] == EVENT_COMPLETED)
|
|
||||||
{
|
|
||||||
mWriter[8]->setEnabled(false);
|
|
||||||
JA_StopMusic();
|
|
||||||
mSection = {PROG_SECTION_TITLE, TITLE_SECTION_1};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
|
||||||
mScreen->start();
|
|
||||||
|
|
||||||
// Limpia la pantalla
|
|
||||||
mScreen->clean(bgColor);
|
|
||||||
|
|
||||||
// Dibuja los objetos
|
|
||||||
for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++)
|
|
||||||
mBitmap[i]->render();
|
|
||||||
for (int i = 0; i < INTRO_TOTAL_TEXTS; i++)
|
|
||||||
mWriter[i]->render();
|
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
|
||||||
mScreen->blit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mSection;
|
return section;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,70 +1,43 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "ifdefs.h"
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
|
#include "asset.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "smartsprite.h"
|
#include "animatedsprite.h"
|
||||||
#include "writer.h"
|
|
||||||
#include "jail_audio.h"
|
#include "jail_audio.h"
|
||||||
|
|
||||||
#ifndef INTRO_H
|
#ifndef INTRO_H
|
||||||
#define INTRO_H
|
#define INTRO_H
|
||||||
|
|
||||||
// Cantidad de eventos de la intro
|
|
||||||
#define INTRO_TOTAL_BITMAPS 6
|
|
||||||
#define INTRO_TOTAL_TEXTS 9
|
|
||||||
const int INTRO_TOTAL_EVENTS = INTRO_TOTAL_BITMAPS + INTRO_TOTAL_TEXTS;
|
|
||||||
|
|
||||||
// Relaciones de Id con nombres
|
|
||||||
#define BITMAP0 0
|
|
||||||
#define BITMAP1 1
|
|
||||||
#define BITMAP2 2
|
|
||||||
#define BITMAP3 3
|
|
||||||
#define BITMAP4 4
|
|
||||||
#define BITMAP5 5
|
|
||||||
#define TEXT0 6
|
|
||||||
#define TEXT1 7
|
|
||||||
#define TEXT2 8
|
|
||||||
#define TEXT3 9
|
|
||||||
#define TEXT4 10
|
|
||||||
#define TEXT5 11
|
|
||||||
#define TEXT6 12
|
|
||||||
#define TEXT7 13
|
|
||||||
#define TEXT8 14
|
|
||||||
|
|
||||||
// Clase Intro
|
// Clase Intro
|
||||||
class Intro
|
class Intro
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Screen *mScreen; // Objeto encargado de dibujar en pantalla
|
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||||
LTexture *mBitmapTexture; // Textura con los graficos
|
LTexture *texture; // Textura con los graficos
|
||||||
LTexture *mTextTexture; // Textura con los caracteres de texto
|
SDL_Event *eventHandler; // Manejador de eventos
|
||||||
SDL_Event *mEventHandler; // Manejador de eventos
|
Asset *asset; // Objeto con los ficheros de recurso
|
||||||
std::string *mFileList; // Lista de ficheros
|
AnimatedSprite *sprite; // Sprite para dibujar los graficos de la intro
|
||||||
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
|
section_t section; // Estado del bucle principal para saber si continua o se sale
|
||||||
section_t mSection; // Estado del bucle principal para saber si continua o se sale
|
int ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 mTicks; // Contador de ticks para ajustar la velocidad del programa
|
int ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
Uint8 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa
|
|
||||||
SmartSprite *mBitmap[INTRO_TOTAL_BITMAPS]; // Vector con los sprites inteligentes para los dibujos de la intro
|
// Actualiza las variables
|
||||||
Writer *mWriter[INTRO_TOTAL_TEXTS]; // Textos de la intro
|
void update();
|
||||||
Text *mText; // Textos de la intro
|
|
||||||
Uint8 mEvents[INTRO_TOTAL_EVENTS]; // Vector para coordinar los eventos de la intro
|
// Dibuja en pantalla
|
||||||
JA_Music mMusic; // Musica para la intro
|
void render();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Intro(SDL_Renderer *renderer, Screen *screen, std::string *fileList, Lang *lang);
|
Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Intro();
|
~Intro();
|
||||||
|
|
||||||
// Inicializa las variables
|
|
||||||
void init();
|
|
||||||
|
|
||||||
// Carga los recursos
|
|
||||||
bool loadMedia();
|
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
section_t run();
|
section_t run();
|
||||||
};
|
};
|
||||||
|
|||||||
212
source/logo.cpp
212
source/logo.cpp
@@ -1,151 +1,137 @@
|
|||||||
#include "logo.h"
|
#include "logo.h"
|
||||||
#ifdef __MIPSEL__
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define INIT_FADE 100
|
|
||||||
#define END_LOGO 200
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Logo::Logo(SDL_Renderer *renderer, Screen *screen, std::string *fileList)
|
Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
||||||
{
|
{
|
||||||
// Copia la dirección de los objetos
|
// Copia la dirección de los objetos
|
||||||
mRenderer = renderer;
|
this->renderer = renderer;
|
||||||
mScreen = screen;
|
this->screen = screen;
|
||||||
mFileList = fileList;
|
this->asset = asset;
|
||||||
|
|
||||||
// Reserva memoria para los punteros
|
// Reserva memoria para los punteros
|
||||||
mEventHandler = new SDL_Event();
|
eventHandler = new SDL_Event();
|
||||||
mTexture = new LTexture();
|
texture = new LTexture();
|
||||||
mSprite = new Sprite();
|
loadTextureFromFile(texture, asset->get("logo.png"), renderer);
|
||||||
|
sprite = new Sprite(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, texture, renderer);
|
||||||
|
|
||||||
// Crea un backbuffer para el renderizador
|
// Crea un backbuffer para el renderizador
|
||||||
mBackbuffer = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH, SCREEN_HEIGHT);
|
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||||
if (mBackbuffer == NULL)
|
if (backbuffer == NULL)
|
||||||
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||||
|
|
||||||
|
// Inicializa variables
|
||||||
|
counter = 0;
|
||||||
|
section.name = SECTION_PROG_LOGO;
|
||||||
|
section.subsection = 0;
|
||||||
|
ticks = 0;
|
||||||
|
ticksSpeed = 15;
|
||||||
|
initFade = 100;
|
||||||
|
endLogo = 200;
|
||||||
|
postLogo = 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Logo::~Logo()
|
Logo::~Logo()
|
||||||
{
|
{
|
||||||
mRenderer = nullptr;
|
renderer = nullptr;
|
||||||
mScreen = nullptr;
|
screen = nullptr;
|
||||||
mFileList = nullptr;
|
asset = nullptr;
|
||||||
|
|
||||||
mTexture->unload();
|
texture->unload();
|
||||||
delete mTexture;
|
delete texture;
|
||||||
mTexture = nullptr;
|
texture = nullptr;
|
||||||
|
|
||||||
delete mSprite;
|
delete sprite;
|
||||||
mSprite = nullptr;
|
sprite = nullptr;
|
||||||
|
|
||||||
delete mEventHandler;
|
delete eventHandler;
|
||||||
mEventHandler = nullptr;
|
eventHandler = nullptr;
|
||||||
|
|
||||||
SDL_DestroyTexture(mBackbuffer);
|
SDL_DestroyTexture(backbuffer);
|
||||||
mBackbuffer = nullptr;
|
backbuffer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa las variables necesarias para la sección 'Logo'
|
// Actualiza las variables
|
||||||
void Logo::init()
|
void Logo::update()
|
||||||
{
|
{
|
||||||
// Carga los recursos
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||||
loadMedia();
|
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||||
|
{
|
||||||
|
// Actualiza el contador de ticks
|
||||||
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
// Inicializa variables
|
// Comprueba los eventos que hay en la cola
|
||||||
mCounter = 0;
|
while (SDL_PollEvent(eventHandler) != 0)
|
||||||
mSection.name = PROG_SECTION_LOGO;
|
{
|
||||||
mSection.subsection = 0;
|
// Evento de salida de la aplicación
|
||||||
mSprite->init(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, mTexture, mRenderer);
|
if (eventHandler->type == SDL_QUIT)
|
||||||
mTicks = 0;
|
{
|
||||||
mTicksSpeed = 15;
|
section.name = SECTION_PROG_QUIT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cualquier tecla pulsada
|
||||||
|
if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
||||||
|
{
|
||||||
|
section.name = SECTION_PROG_TITLE;
|
||||||
|
section.subsection = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
counter++;
|
||||||
|
|
||||||
|
// Comprueba si ha terminado el logo
|
||||||
|
if (counter == endLogo + postLogo)
|
||||||
|
{
|
||||||
|
section.name = SECTION_PROG_INTRO;
|
||||||
|
section.subsection = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga los recursos necesarios para la sección 'Logo'
|
// Dibuja en pantalla
|
||||||
bool Logo::loadMedia()
|
void Logo::render()
|
||||||
{
|
{
|
||||||
bool success = true;
|
|
||||||
|
|
||||||
success &= loadTextureFromFile(mTexture, mFileList[35], mRenderer);
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
|
screen->start();
|
||||||
|
|
||||||
return success;
|
// Limpia la pantalla
|
||||||
|
screen->clean();
|
||||||
|
|
||||||
|
// Dibuja los objetos
|
||||||
|
sprite->render();
|
||||||
|
|
||||||
|
// Dibuja el fade
|
||||||
|
if (counter >= initFade)
|
||||||
|
{
|
||||||
|
const SDL_Rect rect = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
|
||||||
|
const color_t color = {0xFF, 0xFF, 0xFF};
|
||||||
|
const int fadeLenght = endLogo - initFade;
|
||||||
|
|
||||||
|
int alpha = (255 * (counter - initFade)) / fadeLenght;
|
||||||
|
if (alpha < 256)
|
||||||
|
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, alpha);
|
||||||
|
else
|
||||||
|
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
|
||||||
|
SDL_RenderFillRect(renderer, &rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
|
screen->blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle para el logo del juego
|
// Bucle para el logo del juego
|
||||||
section_t Logo::run()
|
section_t Logo::run()
|
||||||
{
|
{
|
||||||
init();
|
// Detiene la música
|
||||||
const SDL_Rect rect = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
|
JA_StopMusic();
|
||||||
const int fadeLenght = END_LOGO - INIT_FADE;
|
|
||||||
|
|
||||||
while (mSection.name == PROG_SECTION_LOGO)
|
while (section.name == SECTION_PROG_LOGO)
|
||||||
{
|
{
|
||||||
// Comprueba los eventos que hay en la cola
|
update();
|
||||||
while (SDL_PollEvent(mEventHandler) != 0)
|
render();
|
||||||
{
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
|
||||||
mScreen->start();
|
|
||||||
|
|
||||||
// Limpia la pantalla
|
|
||||||
mScreen->clean(bgColor);
|
|
||||||
|
|
||||||
// Dibuja los objetos
|
|
||||||
mSprite->render();
|
|
||||||
|
|
||||||
// Dibuja el fade
|
|
||||||
if (mCounter >= INIT_FADE)
|
|
||||||
{
|
|
||||||
Uint16 alpha = (255 * (mCounter - INIT_FADE)) / fadeLenght;
|
|
||||||
if (alpha < 256)
|
|
||||||
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, alpha);
|
|
||||||
else
|
|
||||||
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
|
||||||
SDL_RenderFillRect(mRenderer, &rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
|
||||||
mScreen->blit();
|
|
||||||
|
|
||||||
// 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 == END_LOGO + 20)
|
|
||||||
{
|
|
||||||
mCounter = 0;
|
|
||||||
mSection.name = PROG_SECTION_INTRO;
|
|
||||||
mSection.subsection = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mCounter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mSection;
|
return section;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "ifdefs.h"
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
|
#include "asset.h"
|
||||||
#include "jail_audio.h"
|
#include "jail_audio.h"
|
||||||
|
|
||||||
#ifndef LOGO_H
|
#ifndef LOGO_H
|
||||||
@@ -13,31 +15,34 @@
|
|||||||
class Logo
|
class Logo
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Screen *mScreen; // Objeto encargado de dibujar en pantalla
|
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||||
std::string *mFileList; // Lista de ficheros
|
Asset *asset; // Objeto con los ficheros de recursos
|
||||||
LTexture *mTexture; // Textura con los graficos
|
LTexture *texture; // Textura con los graficos
|
||||||
SDL_Event *mEventHandler; // Manejador de eventos
|
SDL_Event *eventHandler; // Manejador de eventos
|
||||||
SDL_Texture *mBackbuffer; // Textura para usar como backbuffer
|
SDL_Texture *backbuffer; // Textura para usar como backbuffer
|
||||||
Sprite *mSprite; // Sprite con la textura del logo
|
Sprite *sprite; // Sprite con la textura del logo
|
||||||
Uint16 mCounter; // Contador
|
int counter; // Contador
|
||||||
section_t mSection; // Estado del bucle principal para saber si continua o se sale
|
section_t section; // Estado del bucle principal para saber si continua o se sale
|
||||||
Uint32 mTicks; // Contador de ticks para ajustar la velocidad del programa
|
int ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint8 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa
|
int ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
|
int initFade; // Tiempo del contador cuando inicia el fade a negro
|
||||||
|
int endLogo; // Tiempo del contador para terminar el logo
|
||||||
|
int postLogo; // Tiempo que dura el logo con el fade al maximo
|
||||||
|
|
||||||
|
// Actualiza las variables
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Dibuja en pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Logo(SDL_Renderer *renderer, Screen *screen, std::string *fileList);
|
Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Logo();
|
~Logo();
|
||||||
|
|
||||||
// Inicializa las variables
|
|
||||||
void init();
|
|
||||||
|
|
||||||
// Carga los recursos
|
|
||||||
bool loadMedia();
|
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
section_t run();
|
section_t run();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ Prog::Prog(std::string executablePath)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_GAME;
|
section.name = SECTION_PROG_LOGO;
|
||||||
}
|
}
|
||||||
input = new Input(asset->get("gamecontrollerdb.txt"));
|
input = new Input(asset->get("gamecontrollerdb.txt"));
|
||||||
screen = new Screen(window, renderer, options);
|
screen = new Screen(window, renderer, options);
|
||||||
@@ -182,6 +182,13 @@ bool Prog::setFileList()
|
|||||||
asset->add("/data/actors/enemies/flying_eye_horn.png", bitmap);
|
asset->add("/data/actors/enemies/flying_eye_horn.png", bitmap);
|
||||||
asset->add("/data/actors/enemies/flying_eye_horn.ani", data);
|
asset->add("/data/actors/enemies/flying_eye_horn.ani", data);
|
||||||
|
|
||||||
|
// Ficheros del logo
|
||||||
|
asset->add("/data/logo/logo.png", bitmap);
|
||||||
|
|
||||||
|
// Ficheros de la intro
|
||||||
|
asset->add("/data/intro/intro.png", bitmap);
|
||||||
|
asset->add("/data/intro/intro.ani", data);
|
||||||
|
|
||||||
return asset->check();
|
return asset->check();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,6 +204,21 @@ void Prog::setSection(section_t section)
|
|||||||
this->section = section;
|
this->section = section;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Prog::runLogo()
|
||||||
|
{
|
||||||
|
logo = new Logo(renderer, screen, asset);
|
||||||
|
setSection(logo->run());
|
||||||
|
delete logo;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ejecuta la seccion de juego de la introducción
|
||||||
|
void Prog::runIntro()
|
||||||
|
{
|
||||||
|
intro = new Intro(renderer, screen, asset);
|
||||||
|
setSection(intro->run());
|
||||||
|
delete intro;
|
||||||
|
}
|
||||||
|
|
||||||
void Prog::runGame()
|
void Prog::runGame()
|
||||||
{
|
{
|
||||||
game = new Game(renderer, asset, screen, input);
|
game = new Game(renderer, asset, screen, input);
|
||||||
@@ -212,10 +234,10 @@ void Prog::run()
|
|||||||
switch (getSection())
|
switch (getSection())
|
||||||
{
|
{
|
||||||
case SECTION_PROG_LOGO:
|
case SECTION_PROG_LOGO:
|
||||||
// runLogo();
|
runLogo();
|
||||||
break;
|
break;
|
||||||
case SECTION_PROG_INTRO:
|
case SECTION_PROG_INTRO:
|
||||||
// runIntro();
|
runIntro();
|
||||||
break;
|
break;
|
||||||
case SECTION_PROG_TITLE:
|
case SECTION_PROG_TITLE:
|
||||||
// runTitle();
|
// runTitle();
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
|
#include "logo.h"
|
||||||
|
#include "intro.h"
|
||||||
|
|
||||||
#ifndef PROG_H
|
#ifndef PROG_H
|
||||||
#define PROG_H
|
#define PROG_H
|
||||||
@@ -24,6 +26,8 @@ private:
|
|||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||||
Input *input; // Objeto Input para gestionar las entradas
|
Input *input; // Objeto Input para gestionar las entradas
|
||||||
Game *game; // Objeto para la sección del juego
|
Game *game; // Objeto para la sección del juego
|
||||||
|
Intro *intro; // Objeto encargado de gestionar la intro del juego
|
||||||
|
Logo *logo; // Objeto encargado de gestionar el logo del juego
|
||||||
section_t section; // Sección y subsección actual del programa;
|
section_t section; // Sección y subsección actual del programa;
|
||||||
struct options_t *options; // Contiene las opciones del programa
|
struct options_t *options; // Contiene las opciones del programa
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user