#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; int state = 0; init_rand(); do { game = game_init(); do { state = main_loop(&game); } while (!state); game_deinit(game); } while (state == -1); return 1; } static void init_rand(void) { dclear(C_BLACK); dprint(16, 16, C_WHITE, "Instructions:"); dprint(16, 48, C_WHITE, "Move to the right to outrun scrolling."); dprint(16, 64, C_WHITE, "Destroy gold (yellow blocs) for money."); dprint(16, 80, C_WHITE, "Rest rooms freeze time and propose two deals."); dprint(16, 96, C_WHITE, "(NB: they impact scrolling speed and money)"); dprint(16, 112, C_WHITE, "Have fun!"); dprint(48, 128, C_WHITE, "-- KikooDX"); dprint_opt(DWIDTH / 2, DHEIGHT - 16, C_WHITE, C_NONE, DTEXT_CENTER, DTEXT_BOTTOM, "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, &game->player_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: if (keydown(KEY_SHIFT)) { scroll_x = 99.0; scroll_speed = 0.6; return -1; } 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(16, 16 + 0, C_WHITE, "Scrolling killed you :("); dprint(16, 16 + 16, C_WHITE, "Collected $%d", *game->player.cash); dprint(16, 16 + 32, C_WHITE, "Survived %d feets", -(int)(scroll_x / 4)); dprint(16, 16 + 48, C_WHITE, "Thanks for playing :)"); dprint(16, 16 + 64, C_WHITE, "Press SHIFT to play again or EXIT to quit"); break; default: break; } dupdate(); return keydown(KEY_EXIT); }