- Continua el treball amb el gamestate_sequencia.
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include "jfile.h"
|
#include "jfile.h"
|
||||||
#include "jinput.h"
|
#include "jinput.h"
|
||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
|
#include "jaudio.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
@@ -22,6 +23,38 @@ namespace gamestate
|
|||||||
const char *sequence_file = nullptr;
|
const char *sequence_file = nullptr;
|
||||||
uint32_t wait_until = 0;
|
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()
|
bool loop()
|
||||||
{
|
{
|
||||||
if (wait_until>0 && SDL_GetTicks() < wait_until)
|
if (wait_until>0 && SDL_GetTicks() < wait_until)
|
||||||
@@ -40,23 +73,31 @@ namespace gamestate
|
|||||||
switch ( tipo_diapositiva )
|
switch ( tipo_diapositiva )
|
||||||
{
|
{
|
||||||
case DIAPO_ESPERAR:
|
case DIAPO_ESPERAR:
|
||||||
const uint32_t wait_time = (uint16_t)((uint8_t(*(sequence_file++)) << 8) + uint8_t(*(sequence_file++)));
|
wait_until = SDL_GetTicks() + getWord();
|
||||||
wait_until = SDL_GetTicks() + wait_time;
|
|
||||||
break;
|
break;
|
||||||
case DIAPO_FADEIN:
|
case DIAPO_FADEIN:
|
||||||
{
|
drawPic(getString());
|
||||||
uint8_t tamanyCadena = *(sequence_file++);
|
|
||||||
char *filename = (char *)malloc(tamanyCadena + 1);
|
|
||||||
for (int i=0; i<tamanyCadena; i++) filename[i] = *(sequence_file++);
|
|
||||||
filename[tamanyCadena] = '\0';
|
|
||||||
draw::surface *pic = draw::loadSurface(filename);
|
|
||||||
draw::setSource(pic);
|
|
||||||
draw::draw(0, 0, 320, 200, 0, 0);
|
|
||||||
draw::freeSurface(pic);
|
|
||||||
free(filename);
|
|
||||||
draw::fadein();
|
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;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user