Compare commits
2 Commits
907fccf69c
...
572dff8dbb
| Author | SHA1 | Date | |
|---|---|---|---|
| 572dff8dbb | |||
| 6e3a0e513e |
160
source/gamestate_postfase.cpp
Normal file
160
source/gamestate_postfase.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
#include "gamestates.h"
|
||||
#include "jgame.h"
|
||||
#include <string>
|
||||
|
||||
#define POSTFASE_INITIAL 0
|
||||
#define POSTFASE_VICTORIA 1
|
||||
#define POSTFASE_PASSWORD 2
|
||||
|
||||
namespace gamestate
|
||||
{
|
||||
namespace postfase
|
||||
{
|
||||
// Variables del gamestate
|
||||
static int sub_state = POSTFASE_INITIAL;
|
||||
|
||||
void init_victoria();
|
||||
void init_password();
|
||||
bool loop();
|
||||
void drawText(const int x, const int y, const uint8_t color, std::string text);
|
||||
char *ObtenerPasswordDeFase();
|
||||
|
||||
|
||||
void init()
|
||||
{
|
||||
sub_state = POSTFASE_INITIAL;
|
||||
|
||||
if (game::getConfig("fase") == 30) {
|
||||
gamestate::sequence::init();
|
||||
return;
|
||||
} else {
|
||||
audio::loadMusic("mus3.mp3");
|
||||
audio::playMusic();
|
||||
}
|
||||
|
||||
if (game::getConfig("fase") % 5 == 0) {
|
||||
gamestate::postfase::init_victoria();
|
||||
} else {
|
||||
gamestate::postfase::init_password();
|
||||
}
|
||||
}
|
||||
|
||||
void init_victoria()
|
||||
{
|
||||
sub_state = POSTFASE_VICTORIA;
|
||||
draw::surface *fondo = nullptr;
|
||||
|
||||
switch (game::getConfig("fase")) {
|
||||
case 5:
|
||||
fondo = draw::loadSurface("final01.GIF", true);
|
||||
break;
|
||||
case 10:
|
||||
fondo = draw::loadSurface("final02.GIF", true);
|
||||
break;
|
||||
case 15:
|
||||
fondo = draw::loadSurface("final03.GIF", true);
|
||||
break;
|
||||
case 20:
|
||||
fondo = draw::loadSurface("final04.GIF", true);
|
||||
break;
|
||||
case 25:
|
||||
fondo = draw::loadSurface("final05.GIF", true);
|
||||
break;
|
||||
}
|
||||
draw::setSource(fondo);
|
||||
draw::draw(0,0,320,200,0,0);
|
||||
draw::freeSurface(fondo);
|
||||
|
||||
draw::fadein();
|
||||
game::setState(gamestate::postfase::loop);
|
||||
}
|
||||
|
||||
void init_password()
|
||||
{
|
||||
sub_state = POSTFASE_PASSWORD;
|
||||
draw::surface *fondo = draw::loadSurface("postfase.gif", true);
|
||||
|
||||
char *password = ObtenerPasswordDeFase();
|
||||
|
||||
draw::setSource(fondo);
|
||||
draw::draw(0,0,320,200,0,0);
|
||||
draw::freeSurface(fondo);
|
||||
|
||||
drawText(175, 166, 1, password);
|
||||
free(password);
|
||||
|
||||
draw::fadein();
|
||||
game::setState(gamestate::postfase::loop);
|
||||
}
|
||||
|
||||
bool loop()
|
||||
{
|
||||
static bool salir = false;
|
||||
|
||||
draw::render();
|
||||
|
||||
if (draw::isfading()) return true;
|
||||
|
||||
if (salir)
|
||||
{
|
||||
salir = false;
|
||||
if (sub_state == POSTFASE_VICTORIA) {
|
||||
gamestate::postfase::init_password();
|
||||
} else {
|
||||
gamestate::sequence::init();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (input::anyKeyPressed() || input::mouseBtn(1))
|
||||
{
|
||||
draw::fadeout();
|
||||
salir = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
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;i<len;++i)
|
||||
{
|
||||
char chr = text[i];
|
||||
draw::draw(x+i*7, y, 6, 6, (int(chr)-32)*7, 0);
|
||||
}
|
||||
draw::setTrans(255);
|
||||
draw::restorecol(1);
|
||||
draw::restorecol(2);
|
||||
draw::freeSurface(pic);
|
||||
draw::render();
|
||||
}
|
||||
|
||||
char *ObtenerPasswordDeFase()
|
||||
{
|
||||
int filesize = 0;
|
||||
const char *buffer = file::getFileBuffer("offsets.bal", filesize);
|
||||
|
||||
int punter = (game::getConfig("fase")-1)*11;
|
||||
|
||||
char *passFile = (char*)malloc(11);
|
||||
|
||||
for (int i=0;i<10;i++) {
|
||||
punter++;
|
||||
passFile[i] = uint8_t(buffer[punter]) - (101+i);
|
||||
}
|
||||
|
||||
return passFile;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ namespace gamestate
|
||||
case 20: filename = "seq20.txt"; break;
|
||||
case 25: filename = "seq25.txt"; break;
|
||||
case 30: filename = "seq30.txt"; break;
|
||||
default: gamestate::prefase::init();
|
||||
}
|
||||
|
||||
int filesize;
|
||||
@@ -106,7 +107,8 @@ namespace gamestate
|
||||
|
||||
} else if (command=="PLAYMUSIC") {
|
||||
int res = fscanf(sequence_file, " '%[^']'", text);
|
||||
audio::playMusic(audio::loadMusic(text));
|
||||
audio::loadMusic(text);
|
||||
audio::playMusic();
|
||||
|
||||
} else if (command=="FADEOUT") {
|
||||
draw::fadeout();
|
||||
|
||||
@@ -5,4 +5,5 @@ namespace gamestate
|
||||
namespace sequence { void init(); }
|
||||
namespace menu { void init(); }
|
||||
namespace prefase { void init(); }
|
||||
namespace postfase { void init(); }
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ namespace audio
|
||||
{
|
||||
}; // Dummy structs
|
||||
|
||||
static char *buffer = nullptr;
|
||||
static Mix_Music *music = nullptr;
|
||||
|
||||
// Inicialitza el sistema de só
|
||||
void init()
|
||||
{
|
||||
@@ -32,25 +35,25 @@ namespace audio
|
||||
}
|
||||
|
||||
// Carrega un arxiu de música en format OGG
|
||||
music *loadMusic(const std::string filename)
|
||||
const bool loadMusic(const std::string filename)
|
||||
{
|
||||
if (music != nullptr) {
|
||||
Mix_FreeMusic(music);
|
||||
free(buffer);
|
||||
}
|
||||
int filesize=0;
|
||||
char *buffer = file::getFileBuffer(filename, filesize);
|
||||
const Mix_Music* m = Mix_LoadMUS_RW(SDL_RWFromMem(buffer, filesize), 1);
|
||||
buffer = file::getFileBuffer(filename, filesize);
|
||||
music = Mix_LoadMUS_RW(SDL_RWFromMem(buffer, filesize), 1);
|
||||
|
||||
if (m==nullptr) return nullptr;
|
||||
if (music==nullptr) return false;
|
||||
|
||||
music *mus = (music *)malloc(sizeof(music));
|
||||
mus->buffer = buffer;
|
||||
mus->music = (void*)m;
|
||||
|
||||
return mus;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Comença a reproduïr la música en questió
|
||||
void playMusic(const music *mus, const int loop)
|
||||
void playMusic(const int loop)
|
||||
{
|
||||
if (Mix_PlayMusic((Mix_Music *)mus->music, loop) == -1) {
|
||||
if (Mix_PlayMusic(music, loop) == -1) {
|
||||
printf("Failed Mix_PlayMusic()\n");
|
||||
}
|
||||
}
|
||||
@@ -96,14 +99,6 @@ namespace audio
|
||||
}
|
||||
}
|
||||
|
||||
// Allibera una música
|
||||
void deleteMusic(music *mus)
|
||||
{
|
||||
Mix_FreeMusic((Mix_Music *)mus->music);
|
||||
free(mus->buffer);
|
||||
free(mus);
|
||||
}
|
||||
|
||||
// Carrega un só des d'un arxiu WAV
|
||||
const sound *loadSound(const std::string filename)
|
||||
{
|
||||
|
||||
@@ -23,11 +23,6 @@ namespace audio
|
||||
|
||||
// Estructures per a gestionar música i só
|
||||
struct sound;
|
||||
struct music
|
||||
{
|
||||
char *buffer;
|
||||
void *music;
|
||||
};
|
||||
|
||||
/// @brief Inicialitza el sistema de só
|
||||
void init();
|
||||
@@ -37,13 +32,12 @@ namespace audio
|
||||
|
||||
/// @brief Carrega un arxiu de música en format OGG
|
||||
/// @param filename nom de l'arxiu
|
||||
/// @return punter a la música
|
||||
music *loadMusic(const std::string filename);
|
||||
/// @return true si tot be, false si ha fallat
|
||||
const bool loadMusic(const std::string filename);
|
||||
|
||||
/// @brief Comença a reproduïr la música en questió
|
||||
/// @param mus punter a la música
|
||||
/// @param loop quants bucles farà (-1=infinit, 0=no repeteix, 1=repeteix 1 vegada...)
|
||||
void playMusic(const music *mus, const int loop = -1);
|
||||
void playMusic(const int loop = -1);
|
||||
|
||||
/// @brief Pausa la música que està sonant ara
|
||||
void pauseMusic();
|
||||
@@ -61,10 +55,6 @@ namespace audio
|
||||
/// @return estat actual de la música (MUSIC_INVALID, MUSIC_PLAYING, MUSIC_PAUSED o MUSIC_STOPPED)
|
||||
const music_state getMusicState();
|
||||
|
||||
/// @brief Allibera una música
|
||||
/// @param mus punter a la música a alliberar
|
||||
void deleteMusic(music *mus);
|
||||
|
||||
/// @brief Carrega un só des d'un arxiu WAV
|
||||
/// @param filename nom de l'arxiu
|
||||
/// @return un punter al só
|
||||
|
||||
Reference in New Issue
Block a user