Compare commits
5 Commits
65589d6ff1
...
183c095f6d
| Author | SHA1 | Date | |
|---|---|---|---|
| 183c095f6d | |||
| 9f623b249f | |||
| 5cb9caa966 | |||
| ea618d6e7e | |||
| 74eb5ede58 |
BIN
data/cursor.gif
BIN
data/cursor.gif
Binary file not shown.
|
Before Width: | Height: | Size: 57 B After Width: | Height: | Size: 838 B |
78
source/gamestate_menu.cpp
Normal file
78
source/gamestate_menu.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#include "gamestates.h"
|
||||
#include "jgame.h"
|
||||
#include "jdraw.h"
|
||||
#include "jaudio.h"
|
||||
#include "jinput.h"
|
||||
|
||||
namespace gamestate
|
||||
{
|
||||
namespace menu
|
||||
{
|
||||
draw::surface *fondo = nullptr;
|
||||
draw::surface *cursor = nullptr;
|
||||
int exit = 0;
|
||||
|
||||
bool loop()
|
||||
{
|
||||
if (exit) {
|
||||
if (!draw::isfading()) {
|
||||
draw::freeSurface(fondo);
|
||||
draw::freeSurface(cursor);
|
||||
if (exit==1) gamestate::sequence::init();
|
||||
//if (exit==2) gamestate::password::init();
|
||||
}
|
||||
draw::render();
|
||||
return true;
|
||||
}
|
||||
const int x = input::mouseX();
|
||||
const int y = input::mouseY();
|
||||
|
||||
draw::setTrans(255);
|
||||
draw::setSource(fondo);
|
||||
draw::draw(0, 0, 320, 200, 0, 0);
|
||||
|
||||
draw::setTrans(0);
|
||||
draw::setSource(cursor);
|
||||
draw::draw(x, y, cursor->w, cursor->h, 0, 0);
|
||||
|
||||
draw::render();
|
||||
|
||||
if (input::mouseClk(1))
|
||||
{
|
||||
if (x >= 200 && y >= 100 && x <= 270 && y <= 120) {
|
||||
draw::fadeout();
|
||||
game::setConfig("fase", 0);
|
||||
exit = 1;
|
||||
return true;
|
||||
} else if (x >= 175 && y >= 125 && x <= 290 && y <= 145) {
|
||||
draw::fadeout();
|
||||
game::setConfig("fase", 0);
|
||||
exit = 2;
|
||||
return true;
|
||||
} else if (x >= 200 && y >= 150 && x <= 265 && y <= 170) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
exit = 0;
|
||||
fondo = draw::loadSurface("menuprin.gif");
|
||||
draw::loadPalette("menuprin.gif");
|
||||
cursor = draw::loadSurface("cursor.gif");
|
||||
|
||||
if (audio::getMusicState() != audio::music_state::MUSIC_PLAYING) {
|
||||
audio::playMusic(audio::loadMusic("mus3.ogg"));
|
||||
}
|
||||
|
||||
draw::setSource(fondo);
|
||||
draw::draw(0,0,320,200,0,0);
|
||||
draw::fadein();
|
||||
|
||||
game::setState(&gamestate::menu::loop);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "gamestate_sequence.h"
|
||||
#include "gamestates.h"
|
||||
#include "jgame.h"
|
||||
#include "jfile.h"
|
||||
#include "jinput.h"
|
||||
@@ -20,7 +20,8 @@ namespace gamestate
|
||||
namespace sequence
|
||||
{
|
||||
int num_diapositives = 0;
|
||||
const char *sequence_file = nullptr;
|
||||
char *sequence_file = nullptr;
|
||||
char *sfpointer = nullptr;
|
||||
uint32_t wait_until = 0;
|
||||
|
||||
uint8_t getByte()
|
||||
@@ -80,16 +81,20 @@ namespace gamestate
|
||||
{
|
||||
if ( (wait_until > 0) && (SDL_GetTicks() < wait_until) )
|
||||
{
|
||||
if (input::anyKey() || input::mouseBtn(1))
|
||||
{
|
||||
if (!draw::isfading() && (input::anyKeyPressed() || input::mouseBtn(1))) {
|
||||
wait_until=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) num_diapositives=0;
|
||||
} else {
|
||||
draw::render();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (num_diapositives==0) {
|
||||
gamestate::menu::init();
|
||||
free(sfpointer);
|
||||
return true;
|
||||
}
|
||||
|
||||
const char tipo_diapositiva = *(sequence_file++);
|
||||
switch ( tipo_diapositiva )
|
||||
{
|
||||
@@ -149,6 +154,7 @@ namespace gamestate
|
||||
printf("- FadeOutMusic()\n");
|
||||
break;
|
||||
}
|
||||
num_diapositives--;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -172,6 +178,7 @@ namespace gamestate
|
||||
|
||||
int filesize;
|
||||
sequence_file = file::getFileBuffer(filename, filesize);
|
||||
sfpointer = sequence_file;
|
||||
num_diapositives = *(sequence_file++);
|
||||
|
||||
game::setState(&gamestate::sequence::loop);
|
||||
|
||||
@@ -6,4 +6,9 @@ namespace gamestate
|
||||
{
|
||||
void init();
|
||||
}
|
||||
|
||||
namespace menu
|
||||
{
|
||||
void init();
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,7 @@ namespace draw
|
||||
sel_color = transparent = 0;
|
||||
for (int i=0;i<256;++i) color_indices[i] = i;
|
||||
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
//textsurf = loadSurface("font.gif");
|
||||
}
|
||||
|
||||
@@ -416,6 +417,11 @@ namespace draw
|
||||
for (int i=0; i<256; ++i) if (decPalEntry(i, 8)) fading_out = true;
|
||||
}
|
||||
|
||||
bool isfading()
|
||||
{
|
||||
return fading_in || fading_out;
|
||||
}
|
||||
|
||||
// Refresca la pantalla
|
||||
void render()
|
||||
{
|
||||
|
||||
@@ -102,6 +102,7 @@ namespace draw
|
||||
|
||||
void fadein();
|
||||
void fadeout();
|
||||
bool isfading();
|
||||
|
||||
//void print(const char* text, const int x, const int y, const uint8_t color, const uint8_t borde);
|
||||
|
||||
|
||||
@@ -35,6 +35,11 @@ namespace input
|
||||
return keydown != 0;
|
||||
}
|
||||
|
||||
bool anyKeyPressed()
|
||||
{
|
||||
return keypressed != 0;
|
||||
}
|
||||
|
||||
// Torna el codi de la tecla que està sent polsada ara mateix
|
||||
const uint8_t whichKey()
|
||||
{
|
||||
|
||||
@@ -21,6 +21,10 @@ namespace input
|
||||
/// @return true si hi ha alguna tecla polsada, false si no
|
||||
bool anyKey();
|
||||
|
||||
/// @brief El equivalent a anykey per a keypressed
|
||||
/// @return true si hi ha alguna tecla polsada, false si no
|
||||
bool anyKeyPressed();
|
||||
|
||||
/// @brief Torna el codi de la tecla que està sent polsada ara mateix
|
||||
/// @return Quina tecla està sent polsada
|
||||
const uint8_t whichKey();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "jinput.h"
|
||||
#include "jaudio.h"
|
||||
|
||||
#include "gamestate_sequence.h"
|
||||
#include "gamestates.h"
|
||||
|
||||
void game::init()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user