Compare commits
2 Commits
20df5d3935
...
d3f413ebbb
| Author | SHA1 | Date | |
|---|---|---|---|
| d3f413ebbb | |||
| e00e94ce15 |
87
source/gamestate_sequence.cpp
Normal file
87
source/gamestate_sequence.cpp
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
#include "gamestate_sequence.h"
|
||||||
|
#include "jgame.h"
|
||||||
|
#include "jfile.h"
|
||||||
|
#include "jinput.h"
|
||||||
|
#include "jdraw.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;
|
||||||
|
|
||||||
|
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<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();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
source/gamestate_sequence.h
Normal file
9
source/gamestate_sequence.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace gamestate
|
||||||
|
{
|
||||||
|
namespace sequence
|
||||||
|
{
|
||||||
|
void init();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,9 @@ namespace draw
|
|||||||
|
|
||||||
SDL_Rect viewport;
|
SDL_Rect viewport;
|
||||||
|
|
||||||
|
bool fading_out = false;
|
||||||
|
bool fading_in = false;
|
||||||
|
|
||||||
// Inicialització de tot el que fa falta per a carregar gràfics i pintar en pantalla
|
// Inicialització de tot el que fa falta per a carregar gràfics i pintar en pantalla
|
||||||
void init(const std::string &titol, const uint16_t width, const uint16_t height, const int zoom)
|
void init(const std::string &titol, const uint16_t width, const uint16_t height, const int zoom)
|
||||||
{
|
{
|
||||||
@@ -350,6 +353,26 @@ namespace draw
|
|||||||
vline(x+w-1,y,h);
|
vline(x+w-1,y,h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fadein()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void fadeout()
|
||||||
|
{
|
||||||
|
fading_out = false;
|
||||||
|
for (int i=0; i<256; ++i)
|
||||||
|
{
|
||||||
|
// [TODO] ARREGLAR, les entrades en la paleta son uint32_t, hi ha que separar en rgba i decrementar cada canal per separat
|
||||||
|
if (palette[i] > 16) {
|
||||||
|
palette[i] = palette[i]-16;
|
||||||
|
fading_out = true;
|
||||||
|
} else {
|
||||||
|
palette[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void print(const char* text, const int x, const int y, const Uint8 color, const Uint8 borde)
|
void print(const char* text, const int x, const int y, const Uint8 color, const Uint8 borde)
|
||||||
{
|
{
|
||||||
surface* tmp = source;
|
surface* tmp = source;
|
||||||
@@ -384,6 +407,9 @@ namespace draw
|
|||||||
int sdl_pitch; // Ací estarà guardat el pitch de la textura, com es de 32 bits, no m'afecta
|
int sdl_pitch; // Ací estarà guardat el pitch de la textura, com es de 32 bits, no m'afecta
|
||||||
const uint32_t size = screen->w * screen->h; // tamany de la superficie
|
const uint32_t size = screen->w * screen->h; // tamany de la superficie
|
||||||
|
|
||||||
|
if (fading_in) fadein();
|
||||||
|
if (fading_out) fadeout();
|
||||||
|
|
||||||
// Bloquejem la textura SDL i agafem els seus pixels (son enters de 32 bits amb format 0xAARRGGBB)
|
// Bloquejem la textura SDL i agafem els seus pixels (son enters de 32 bits amb format 0xAARRGGBB)
|
||||||
SDL_LockTexture(sdl_texture, NULL, (void **)&sdl_pixels, &sdl_pitch);
|
SDL_LockTexture(sdl_texture, NULL, (void **)&sdl_pixels, &sdl_pitch);
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,9 @@ namespace draw
|
|||||||
void fillrect(const int x, const int y, const int w, const int h);
|
void fillrect(const int x, const int y, const int w, const int h);
|
||||||
void rect(const int x, const int y, const int w, const int h);
|
void rect(const int x, const int y, const int w, const int h);
|
||||||
|
|
||||||
|
void fadein();
|
||||||
|
void fadeout();
|
||||||
|
|
||||||
void print(const char* text, const int x, const int y, const uint8_t color, const uint8_t borde);
|
void print(const char* text, const int x, const int y, const uint8_t color, const uint8_t borde);
|
||||||
|
|
||||||
/// @brief Refresca la pantalla
|
/// @brief Refresca la pantalla
|
||||||
|
|||||||
Reference in New Issue
Block a user