- gamestate_password implementat.
This commit is contained in:
@@ -20,9 +20,9 @@ namespace gamestate
|
|||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
exit = 0;
|
menu::exit = menu::eixir::no;
|
||||||
fondo = draw::loadSurface("menuprin.gif", true);
|
menu::fondo = draw::loadSurface("menuprin.gif", true);
|
||||||
cursor = draw::loadSurface("cursor.gif");
|
menu::cursor = draw::loadSurface("cursor.gif");
|
||||||
|
|
||||||
if (audio::getMusicState() != audio::music_state::MUSIC_PLAYING || audio::whichMusic() != "mus3.ogg") {
|
if (audio::getMusicState() != audio::music_state::MUSIC_PLAYING || audio::whichMusic() != "mus3.ogg") {
|
||||||
audio::playMusic(audio::loadMusic("mus3.ogg"));
|
audio::playMusic(audio::loadMusic("mus3.ogg"));
|
||||||
@@ -40,7 +40,7 @@ namespace gamestate
|
|||||||
draw::freeSurface(fondo);
|
draw::freeSurface(fondo);
|
||||||
draw::freeSurface(cursor);
|
draw::freeSurface(cursor);
|
||||||
if (exit==menu::eixir::sequence) gamestate::sequence::init();
|
if (exit==menu::eixir::sequence) gamestate::sequence::init();
|
||||||
//if (exit==menu::eixir::password) gamestate::password::init();
|
if (exit==menu::eixir::password) gamestate::password::init();
|
||||||
}
|
}
|
||||||
draw::render();
|
draw::render();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
146
source/gamestate_password.cpp
Normal file
146
source/gamestate_password.cpp
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
#include "gamestates.h"
|
||||||
|
#include "jgame.h"
|
||||||
|
#include <string>
|
||||||
|
#include "aux_font.h"
|
||||||
|
#include "proc_mapa.h"
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
|
namespace gamestate
|
||||||
|
{
|
||||||
|
namespace password
|
||||||
|
{
|
||||||
|
namespace eixir
|
||||||
|
{
|
||||||
|
const int no = 0;
|
||||||
|
const int sequence = 1;
|
||||||
|
const int menu = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Variables del gamestate
|
||||||
|
draw::surface *fondo = nullptr;
|
||||||
|
draw::surface *cursor = nullptr;
|
||||||
|
|
||||||
|
int exit = password::eixir::no;
|
||||||
|
char password[11] = " ";
|
||||||
|
uint8_t indice = 0;
|
||||||
|
|
||||||
|
// Mètodes del gamestate
|
||||||
|
bool loop();
|
||||||
|
const int getFaseFromPassword();
|
||||||
|
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
exit = password::eixir::no;
|
||||||
|
|
||||||
|
// Carrega el gif del fondo
|
||||||
|
fondo = draw::loadSurface("prefase.gif", true);
|
||||||
|
cursor = draw::loadSurface("cursor.gif");
|
||||||
|
|
||||||
|
// Pinta el text en el fondo
|
||||||
|
draw::setDestination(fondo);
|
||||||
|
font::selectFont(font::type::normal);
|
||||||
|
font::print(95, 80, "ESCRIU EL PASSWORD");
|
||||||
|
|
||||||
|
draw::setDestination(nullptr);
|
||||||
|
|
||||||
|
// Comencem el bucle
|
||||||
|
draw::fadein();
|
||||||
|
game::setState(gamestate::password::loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool loop()
|
||||||
|
{
|
||||||
|
draw::draw(fondo);
|
||||||
|
font::print(123, 140, password);
|
||||||
|
|
||||||
|
draw::setSource(cursor);
|
||||||
|
draw::draw(input::mouseX(), input::mouseY());
|
||||||
|
|
||||||
|
draw::render();
|
||||||
|
|
||||||
|
if (draw::isfading()) return true;
|
||||||
|
|
||||||
|
if (exit)
|
||||||
|
{
|
||||||
|
if (!draw::isfading()) {
|
||||||
|
draw::freeSurface(fondo);
|
||||||
|
draw::freeSurface(cursor);
|
||||||
|
if (exit==password::eixir::sequence) gamestate::sequence::init();
|
||||||
|
if (exit==password::eixir::menu) gamestate::menu::init();
|
||||||
|
}
|
||||||
|
draw::render();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input::anyKeyPressed())
|
||||||
|
{
|
||||||
|
if (input::keyPressed(SDL_SCANCODE_ESCAPE))
|
||||||
|
{
|
||||||
|
draw::fadeout();
|
||||||
|
game::setConfig("fase", 0);
|
||||||
|
exit = password::eixir::menu;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (input::keyPressed(SDL_SCANCODE_BACKSPACE))
|
||||||
|
{
|
||||||
|
if (indice>0) password[--indice] = 32;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const uint8_t tecla = input::getKeyPressed();
|
||||||
|
if (tecla == SDL_SCANCODE_0) {
|
||||||
|
password[indice++] = '0';
|
||||||
|
}
|
||||||
|
else if (tecla >= SDL_SCANCODE_1 && tecla <= SDL_SCANCODE_9)
|
||||||
|
{
|
||||||
|
password[indice++] = tecla + 18;
|
||||||
|
}
|
||||||
|
else if (tecla >= SDL_SCANCODE_A && tecla <= SDL_SCANCODE_Z)
|
||||||
|
{
|
||||||
|
password[indice++] = tecla + 61;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (indice == 10)
|
||||||
|
{
|
||||||
|
draw::fadeout();
|
||||||
|
game::setConfig("fase", password::getFaseFromPassword());
|
||||||
|
exit = password::eixir::sequence;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int getFaseFromPassword()
|
||||||
|
{
|
||||||
|
int filesize = 0;
|
||||||
|
const char *buffer = file::getFileBuffer("offsets.bal", &filesize);
|
||||||
|
|
||||||
|
int punter = 0;
|
||||||
|
|
||||||
|
bool salir = false;
|
||||||
|
char passFile[11] = " ";
|
||||||
|
int numPassword = 0;
|
||||||
|
|
||||||
|
while ( numPassword < 30 && !salir ) {
|
||||||
|
for (int i=0;i<10;i++) {
|
||||||
|
punter++;
|
||||||
|
passFile[i] = buffer[punter] - (101+i);
|
||||||
|
}
|
||||||
|
punter++;
|
||||||
|
|
||||||
|
salir = true;
|
||||||
|
for (int i=0;i<10;i++) {
|
||||||
|
if (passFile[i] != password[i]) salir = false;
|
||||||
|
}
|
||||||
|
numPassword++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!salir) numPassword = 0;
|
||||||
|
|
||||||
|
return numPassword;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,4 +8,5 @@ namespace gamestate
|
|||||||
namespace play { void init(); }
|
namespace play { void init(); }
|
||||||
namespace postfase { void init(); }
|
namespace postfase { void init(); }
|
||||||
namespace mort { void init(); }
|
namespace mort { void init(); }
|
||||||
|
namespace password { void init(); }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user