129 lines
3.6 KiB
C++
129 lines
3.6 KiB
C++
#include "gamestate_sequence.h"
|
|
#include "jgame.h"
|
|
#include "jfile.h"
|
|
#include "jinput.h"
|
|
#include "jdraw.h"
|
|
#include "jaudio.h"
|
|
#include <string>
|
|
#include <SDL2/SDL.h>
|
|
|
|
#define DIAPO_ESPERAR 0
|
|
#define DIAPO_FADEIN 1
|
|
#define DIAPO_SHOW 2
|
|
#define DIAPO_PRINT 3
|
|
#define DIAPO_MUSICA 4
|
|
#define DIAPO_FADEOUT 5
|
|
#define DIAPO_FADEMUSIC 6
|
|
|
|
namespace gamestate
|
|
{
|
|
namespace sequence
|
|
{
|
|
int num_diapositives = 0;
|
|
const char *sequence_file = nullptr;
|
|
uint32_t wait_until = 0;
|
|
|
|
uint8_t getByte()
|
|
{
|
|
return *(sequence_file++);
|
|
}
|
|
|
|
uint16_t getWord()
|
|
{
|
|
return (getByte() << 8) + getByte();
|
|
}
|
|
|
|
std::string getString()
|
|
{
|
|
uint8_t tamanyCadena = getByte();
|
|
char filename[256];
|
|
for (int i=0; i<tamanyCadena; i++) filename[i] = getByte();
|
|
filename[tamanyCadena] = '\0';
|
|
return std::string(filename);
|
|
}
|
|
|
|
void drawPic(std::string filename)
|
|
{
|
|
draw::surface *pic = draw::loadSurface(filename);
|
|
draw::setSource(pic);
|
|
draw::draw(0, 0, 320, 200, 0, 0);
|
|
draw::freeSurface(pic);
|
|
}
|
|
|
|
void drawText(const int x, const int y, const uint8_t color, std::string text)
|
|
{
|
|
|
|
}
|
|
|
|
bool loop()
|
|
{
|
|
if (wait_until>0 && SDL_GetTicks() < wait_until)
|
|
{
|
|
if (input::anyKey() || input::mouseBtn(1))
|
|
{
|
|
wait_until=0;
|
|
}
|
|
else
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
const char tipo_diapositiva = *(sequence_file++);
|
|
switch ( tipo_diapositiva )
|
|
{
|
|
case DIAPO_ESPERAR:
|
|
wait_until = SDL_GetTicks() + getWord();
|
|
break;
|
|
case DIAPO_FADEIN:
|
|
drawPic(getString());
|
|
draw::fadein();
|
|
wait_until = SDL_GetTicks() + 250;
|
|
break;
|
|
case DIAPO_SHOW:
|
|
drawPic(getString());
|
|
break;
|
|
case DIAPO_PRINT:
|
|
drawText(getWord(), getWord(), getByte(), getString());
|
|
break;
|
|
case DIAPO_MUSICA:
|
|
audio::playMusic(audio::loadMusic(getString()));
|
|
break;
|
|
case DIAPO_FADEOUT:
|
|
draw::fadeout();
|
|
wait_until = SDL_GetTicks() + 250;
|
|
break;
|
|
case DIAPO_FADEMUSIC:
|
|
draw::fadeout();
|
|
audio::fadeoutMusic();
|
|
wait_until = SDL_GetTicks() + 250;
|
|
break;
|
|
}
|
|
}
|
|
|
|
void init()
|
|
{
|
|
const int fase = game::getConfig("fase");
|
|
std::string filename;
|
|
|
|
switch (fase)
|
|
{
|
|
case -1: filename = "seqIN.seq"; break;
|
|
case 0: filename = "seq00.seq"; break;
|
|
case 5: filename = "seq05.seq"; break;
|
|
case 10: filename = "seq10.seq"; break;
|
|
case 15: filename = "seq15.seq"; break;
|
|
case 20: filename = "seq20.seq"; break;
|
|
case 25: filename = "seq25.seq"; break;
|
|
case 30: filename = "seq30.seq"; break;
|
|
}
|
|
|
|
int filesize;
|
|
sequence_file = file::getFileBuffer(filename, filesize);
|
|
num_diapositives = *(sequence_file++);
|
|
|
|
game::setState(&gamestate::sequence::loop);
|
|
}
|
|
}
|
|
}
|