skip level & ask before exiting
This commit is contained in:
parent
fca6140c10
commit
067ac12c8c
|
@ -8,6 +8,7 @@ enum Key {
|
|||
K_JUMP,
|
||||
K_POLARITY,
|
||||
K_EXIT,
|
||||
K_SKIP,
|
||||
K_EDITOR,
|
||||
K_SCROLL_UP,
|
||||
K_SCROLL_DOWN,
|
||||
|
|
|
@ -7,3 +7,4 @@ float maxf(float, float);
|
|||
int min(int, int);
|
||||
int max(int, int);
|
||||
void dputs_outline(int x, int y, int halign, int valign, const char *);
|
||||
int ask_confirm(char *);
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
static struct Input input;
|
||||
static const int default_map[K_COUNT] = {
|
||||
KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN, KEY_SHIFT,
|
||||
KEY_ALPHA, KEY_EXIT, KEY_F3, KEY_F2, KEY_F1};
|
||||
KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN, KEY_SHIFT, KEY_ALPHA,
|
||||
KEY_EXIT, KEY_TAN, KEY_F3, KEY_F2, KEY_F1};
|
||||
|
||||
void
|
||||
input_init(void)
|
||||
|
|
10
src/main.c
10
src/main.c
|
@ -4,6 +4,7 @@
|
|||
#include "level.h"
|
||||
#include "player.h"
|
||||
#include "time.h"
|
||||
#include "util.h"
|
||||
#include <gint/cpu.h>
|
||||
#include <gint/display.h>
|
||||
#include <gint/timer.h>
|
||||
|
@ -27,7 +28,7 @@ main(void)
|
|||
init();
|
||||
level_load(0);
|
||||
|
||||
do {
|
||||
for (;;) {
|
||||
int i;
|
||||
draw();
|
||||
for (i = 0; i < frameskip; i++) {
|
||||
|
@ -39,8 +40,13 @@ main(void)
|
|||
has_ticked = 0;
|
||||
}
|
||||
update();
|
||||
if (input_pressed(K_EXIT) && ask_confirm("exit game"))
|
||||
goto game_loop_end;
|
||||
if (input_pressed(K_SKIP) && ask_confirm("skip level"))
|
||||
level_next();
|
||||
}
|
||||
} while (input_up(K_EXIT));
|
||||
};
|
||||
game_loop_end:
|
||||
|
||||
deinit();
|
||||
return 0;
|
||||
|
|
19
src/util.c
19
src/util.c
|
@ -1,5 +1,6 @@
|
|||
#include "util.h"
|
||||
#include <gint/display.h>
|
||||
#include <gint/keyboard.h>
|
||||
|
||||
int
|
||||
sign(int x)
|
||||
|
@ -50,3 +51,21 @@ dputs_outline(int x, int y, int halign, int valign, const char *text)
|
|||
}
|
||||
dprint_opt(x, y, C_BLACK, C_NONE, halign, valign, "%s", text);
|
||||
}
|
||||
|
||||
int
|
||||
ask_confirm(char *prompt)
|
||||
{
|
||||
extern volatile int has_ticked;
|
||||
dclear(C_BLACK);
|
||||
dprint_opt(DWIDTH / 2, DHEIGHT / 2, C_WHITE, C_NONE, DTEXT_CENTER,
|
||||
DTEXT_MIDDLE, "%s? EXE confirm, any other key cancel",
|
||||
prompt);
|
||||
dupdate();
|
||||
for (;;) {
|
||||
const key_event_t e = getkey();
|
||||
if (e.type == KEYEV_DOWN) {
|
||||
has_ticked = 0;
|
||||
return e.key == KEY_EXE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue