diff --git a/source/gamestate_sequence.cpp b/source/gamestate_sequence.cpp index b01f6c1..7e9e0ec 100644 --- a/source/gamestate_sequence.cpp +++ b/source/gamestate_sequence.cpp @@ -30,7 +30,7 @@ namespace gamestate uint16_t getWord() { - return (getByte() << 8) + getByte(); + return getByte() + (getByte() << 8); } std::string getString() @@ -46,18 +46,39 @@ namespace gamestate { draw::surface *pic = draw::loadSurface(filename); draw::setSource(pic); + draw::loadPalette(filename); 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) { - + draw::surface *pic = draw::loadSurface("fuente2.gif"); + draw::setSource(pic); + draw::setTrans(0); + draw::setPaletteEntry(64, 255, 255, 255); + draw::setPaletteEntry(65, 255, 0, 0); + draw::setPaletteEntry(66, 0, 255, 0); + draw::setPaletteEntry(67, 0, 0, 255); + draw::setPaletteEntry(68, 0, 0, 0); + draw::swapcol(1, color+64); + draw::swapcol(2, 68); + const int len = text.length(); + for (int i=0;i0 && SDL_GetTicks() < wait_until) + if ( (wait_until > 0) && (SDL_GetTicks() < wait_until) ) { if (input::anyKey() || input::mouseBtn(1)) { @@ -65,44 +86,75 @@ namespace gamestate } else { + draw::render(); return true; } } - const char tipo_diapositiva = *(sequence_file++); switch ( tipo_diapositiva ) { case DIAPO_ESPERAR: - wait_until = SDL_GetTicks() + getWord(); + { + const uint16_t time = getWord(); + wait_until = SDL_GetTicks() + time; + printf("- Esperar(%i)\n", time); break; + } case DIAPO_FADEIN: - drawPic(getString()); + { + std::string filename = getString(); + drawPic(filename); draw::fadein(); - wait_until = SDL_GetTicks() + 250; + draw::render(); + wait_until = SDL_GetTicks() + 500; + printf("- FadeIn('%s')\n", filename.c_str()); break; + } case DIAPO_SHOW: - drawPic(getString()); + { + std::string filename = getString(); + drawPic(filename); + draw::render(); + printf("- Show('%s')\n", filename.c_str()); break; + } case DIAPO_PRINT: - drawText(getWord(), getWord(), getByte(), getString()); + { + const uint16_t x = getWord(); + const uint16_t y = getWord(); + const uint8_t col = getByte(); + std::string text = getString(); + drawText(x, y, col, text); + printf("- Print(%i, %i, %i, '%s')\n", x, y, col, text.c_str()); break; + } case DIAPO_MUSICA: - audio::playMusic(audio::loadMusic(getString())); + { + std::string filename = getString(); + audio::playMusic(audio::loadMusic(filename)); + printf("- PlayMusic('%s')\n", filename.c_str()); break; + } case DIAPO_FADEOUT: + { draw::fadeout(); - wait_until = SDL_GetTicks() + 250; + wait_until = SDL_GetTicks() + 500; + printf("- FadeOut()\n"); break; + } case DIAPO_FADEMUSIC: draw::fadeout(); audio::fadeoutMusic(); - wait_until = SDL_GetTicks() + 250; + wait_until = SDL_GetTicks() + 500; + printf("- FadeOutMusic()\n"); break; } + return true; } void init() { + draw::setTrans(255); const int fase = game::getConfig("fase"); std::string filename; diff --git a/source/main.cpp b/source/main.cpp index 9a8dadc..8209155 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -3,6 +3,8 @@ #include "jinput.h" #include "jaudio.h" +#include "gamestate_sequence.h" + void game::init() { draw::init("Arounders", 320, 200, 3); @@ -12,5 +14,14 @@ void game::init() game::setUpdateTicks(16); game::setConfig("fase", -1); - game::setState(nullptr); + gamestate::sequence::init(); + +/* + draw::surface *pic = draw::loadSurface("sprites.gif"); + draw::setSource(pic); + draw::loadPalette("sprites.gif"); + draw::draw(0, 0, 320, 200, 0, 0); + draw::freeSurface(pic); + draw::render(); +*/ } \ No newline at end of file