#include "game.h" #include "grid.h" #include "player.h" #include "tiles.h" #include #include #include 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 float scroll_x = 99.0; static float scroll_speed = 0.6; clearevents(); switch (game->state) { case GameFloor: if (player_update(&game->player, &game->floor)) { game->state = GameRest; grid_shop(&game->rest); } scroll_x -= scroll_speed; scroll_speed += 0.0003; break; case GameRest: switch (player_update(&game->player_rest, &game->rest)) { case -1: scroll_speed += 0.2; break; case -2: scroll_speed -= 0.6; if (scroll_speed < 0.6) scroll_speed = 0.6; break; case 1: game->state = GameFloor; break; default: break; } break; case GameDead: default: break; } dclear(C_BLACK); switch (game->state) { case GameFloor: grid_draw(game->floor, (scroll_x < 0) ? (scroll_x) : (0), 0); if (!player_draw(game->player, (scroll_x < 0) ? (scroll_x) : (0), 0)) game->state = GameDead; break; case GameRest: grid_draw(game->rest, -2, 0); if (!player_draw(game->player_rest, -2, 0)) game->state = GameDead; break; case GameDead: dprint(0, 0, C_WHITE, "You died :("); dprint(0, 16, C_WHITE, "Collected $%d", *game->player.cash); dprint(0, 32, C_WHITE, "Survived %d feets", -(int)(scroll_x / 4)); dprint(0, 48, C_WHITE, "Thanks for playing :)"); dprint(0, 64, C_WHITE, "(Press EXIT)"); break; default: break; } dupdate(); return keydown(KEY_EXIT); }