protomine/src/main.c

69 lines
1.1 KiB
C

#include "game.h"
#include "grid.h"
#include "player.h"
#include "tiles.h"
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/std/stdlib.h>
static void init_rand(void);
/* return 1 to break */
static int main_loop(struct Game *restrict game);
int
main(void)
{
struct Game game;
init_rand();
game = game_init();
while (!main_loop(&game)) {
}
game_deinit(game);
return 1;
}
static void
init_rand(void)
{
dclear(C_BLACK);
dprint(0, 0, C_WHITE, "PRESS SHIFT");
dupdate();
unsigned int seed = 0;
do {
clearevents();
seed += 1;
} while (keydown(KEY_SHIFT));
do {
clearevents();
seed += 1;
} while (!keydown(KEY_SHIFT));
srand(seed);
}
static int
main_loop(struct Game *restrict game)
{
static int scroll_x = 1 << 13;
if (scroll_x == 1 << 13)
scroll_x = 99;
clearevents();
player_update(&game->player, &game->floor);
dclear(C_BLACK);
grid_draw(game->floor, (scroll_x < 0) ? (scroll_x) : (0), 0);
player_draw(game->player, (scroll_x < 0) ? (scroll_x) : (0), 0);
dupdate();
scroll_x -= 1;
return keydown(KEY_EXIT);
}