- [NEW] Mogut tot el codi de lloc

This commit is contained in:
2025-07-02 13:36:48 +02:00
parent 4670b52378
commit 81c5011bc7
34 changed files with 52 additions and 52 deletions

View File

@@ -0,0 +1,134 @@
#include "gamestates.h"
#include "../japi/game.h"
#include <string>
#include <SDL3/SDL.h>
#include "../aux/font.h"
namespace gamestate
{
namespace sequence
{
FILE *sequence_file = nullptr;
uint32_t wait_until = 0;
void drawPic(std::string filename);
bool loop();
void init()
{
font::selectFont(font::type::colored);
std::string filename;
switch (game::getConfig("fase"))
{
case -1: filename = "seqIN.txt"; break;
case 0: filename = "seq00.txt"; break;
case 5: filename = "seq05.txt"; break;
case 10: filename = "seq10.txt"; break;
case 15: filename = "seq15.txt"; break;
case 20: filename = "seq20.txt"; break;
case 25: filename = "seq25.txt"; break;
case 30: filename = "seq30.txt"; break;
default: gamestate::prefase::init(); return; break;
}
int size;
sequence_file = file::getFilePointer(filename.c_str(), size);
game::setState(&gamestate::sequence::loop);
}
bool loop()
{
if (draw::isfading()) {
draw::render();
return true;
}
if ( (wait_until > 0) && (SDL_GetTicks() < wait_until) )
{
if (input::anyKeyPressed() || input::mouseBtn(1)) {
wait_until=0;
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) fseek(sequence_file, 0, SEEK_END);
} else {
draw::render();
return true;
}
}
if (feof(sequence_file))
{
fclose(sequence_file);
const int fase = game::getConfig("fase");
if ( fase == -1 || fase == 30) {
gamestate::menu::init();
} else {
gamestate::prefase::init();
}
return true;
} else {
char text[100];
int x, y, val;
int res = fscanf(sequence_file, "%s", text);
if (res==1)
{
std::string command(text);
if (command=="ESPERAR") {
fscanf(sequence_file, "%i", &val);
wait_until = SDL_GetTicks() + val;
} else if (command=="FADEIN") {
fscanf(sequence_file, " '%[^']'", text);
drawPic(text);
draw::fadein();
} else if (command=="SHOW") {
fscanf(sequence_file, " '%[^']'", text);
drawPic(text);
draw::render();
} else if (command=="PRINT") {
fscanf(sequence_file, " %i %i %i '%[^']'", &x, &y, &val, text);
font::setColor(val);
font::print(x, y, text);
} else if (command=="PLAYMUSIC") {
fscanf(sequence_file, " '%[^']'", text);
audio::loadAndPlayMusic(text);
} else if (command=="FADEOUT") {
draw::fadeout();
} else if (command=="FADEOUTMUSIC") {
draw::fadeout();
audio::fadeOutMusic();
} else if (command=="END") {
fclose(sequence_file);
const int fase = game::getConfig("fase");
if ( fase == -1 || fase == 30) {
gamestate::menu::init();
} else {
gamestate::prefase::init();
}
return true;
}
}
}
return true;
}
void drawPic(std::string filename)
{
draw::surface *pic = draw::loadSurface(filename.c_str(), true);
draw::draw(pic);
draw::freeSurface(pic);
}
}
}