mystnb/src/main.c

113 lines
1.7 KiB
C

#include <gint/display.h>
#include <gint/keyboard.h>
#include "engine.h"
static void draw_menu(int selected)
{
extern bopti_image_t img_title;
extern bopti_image_t img_levels;
dclear(C_WHITE);
dimage(0, 2, &img_title);
for(int i = 1; i <= 8; i++)
{
int x = 20 + 11*(i-1);
int y = 36;
if(i != 8)
{
dsubimage(x, y, &img_levels, 0,0,10,10, DIMAGE_NONE);
dprint(x+3, y+2, C_BLACK, "%d", i);
}
else
{
dsubimage(x, y, &img_levels, 11,0,10,10, DIMAGE_NONE);
}
if(i == selected)
{
drect(x+1, y+1, x+8, y+8, C_INVERT);
}
}
}
static int main_menu(void)
{
extern font_t font_mystere;
dfont(&font_mystere);
int selected = 1;
int key = 0;
while(key != KEY_EXE)
{
draw_menu(selected);
dupdate();
key = getkey().key;
if(key == KEY_LEFT && selected > 1)
selected--;
if(key == KEY_RIGHT && selected < 8)
selected++;
}
return selected;
}
/* Returns a direction to move in */
static int get_inputs(void)
{
int opt = GETKEY_DEFAULT & ~GETKEY_REP_ARROWS;
while(1)
{
int key = getkey_opt(opt, NULL).key;
if(key == KEY_DOWN) return DIR_DOWN;
if(key == KEY_RIGHT) return DIR_RIGHT;
if(key == KEY_UP) return DIR_UP;
if(key == KEY_LEFT) return DIR_LEFT;
}
}
int main(void)
{
GUNUSED int level = main_menu();
struct player singleplayer = {
.x = 2,
.y = 3
};
struct map map = {
.w = 13,
.h = 7
};
struct game game = {
.map = &map,
.players = { &singleplayer, NULL },
.time = 0,
};
int level_finished = 0;
while(!level_finished)
{
int turn_finished = 0;
while(!turn_finished)
{
engine_draw(&game);
dupdate();
int dir = get_inputs();
turn_finished = engine_move(&game, &singleplayer, dir);
}
/* Update doors, etc */
}
return 1;
}