From d3f413ebbbcecfa24563aecad53a611ffbf7add9 Mon Sep 17 00:00:00 2001 From: JailDoctor Date: Wed, 11 Oct 2023 20:04:39 +0200 Subject: [PATCH] - Comencem a treballar en el gamestate de les sequencies --- source/gamestate_sequence.cpp | 87 +++++++++++++++++++++++++++++++++++ source/gamestate_sequence.h | 9 ++++ 2 files changed, 96 insertions(+) create mode 100644 source/gamestate_sequence.cpp create mode 100644 source/gamestate_sequence.h diff --git a/source/gamestate_sequence.cpp b/source/gamestate_sequence.cpp new file mode 100644 index 0000000..f895407 --- /dev/null +++ b/source/gamestate_sequence.cpp @@ -0,0 +1,87 @@ +#include "gamestate_sequence.h" +#include "jgame.h" +#include "jfile.h" +#include "jinput.h" +#include "jdraw.h" +#include +#include + +#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; + + 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: + const uint32_t wait_time = (uint16_t)((uint8_t(*(sequence_file++)) << 8) + uint8_t(*(sequence_file++))); + wait_until = SDL_GetTicks() + wait_time; + break; + case DIAPO_FADEIN: + { + uint8_t tamanyCadena = *(sequence_file++); + char *filename = (char *)malloc(tamanyCadena + 1); + for (int i=0; i