From af06f8718558683aa717bc98bcba1ed1a30e3737 Mon Sep 17 00:00:00 2001 From: ostanton <114495956+ostanton@users.noreply.github.com> Date: Sun, 6 Apr 2025 12:07:10 +0100 Subject: Functional continue and retry buttons --- src/all.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'src/all.c') diff --git a/src/all.c b/src/all.c index 2b0b850..9948b4b 100644 --- a/src/all.c +++ b/src/all.c @@ -225,7 +225,9 @@ static void update(Game *game, uint64_t now, Arena a) { case INPUT_CLICK: x = (game->mousex - GRID_OFFSET_X) * GRIDWIDTH / offset_width; y = game->mousey * GRIDHEIGHT / game->ui.height; - game->state.grid[x + y * GRIDWIDTH] = (game->state.grid[x + y * GRIDWIDTH] + 1) % (sizeof(colors) / sizeof(colors[0])); + if (x >= 0) + game->state.grid[x + y * GRIDWIDTH] = (game->state.grid[x + y * GRIDWIDTH] + 1) % (sizeof(colors) / sizeof(colors[0])); + for (int i = 0; i < N_BUTTONS; i++) { if ( game->mousex > buttons[i].x && game->mousex < buttons[i].x + buttons[i].w && @@ -235,10 +237,27 @@ static void update(Game *game, uint64_t now, Arena a) { // TODO - CLICK THINGS //game->state.buttonStates[i] = BUTTON_STATE_PRESSED; switch (i) { - case BUTTON_RETRY: + case BUTTON_RETRY: { + // reset to initial values + int currentLevel = game->state.currentLevel; + xmemcpy(&game->state.grid, &levels[currentLevel].grid, sizeof(game->state.grid)); + game->state.goalx = levels[currentLevel].goalx; + game->state.goaly = levels[currentLevel].goaly; + game->state.playing = 0; break; - case BUTTON_CONTINUE: + } + case BUTTON_CONTINUE: { + // TODO - don't allow if level has not been completed + if (game->state.currentLevel + 1 >= 2) // TODO - get size of levels array + break; + game->state.currentLevel++; + int currentLevel = game->state.currentLevel; + xmemcpy(&game->state.grid, &levels[currentLevel].grid, sizeof(game->state.grid)); + game->state.goalx = levels[currentLevel].goalx; + game->state.goaly = levels[currentLevel].goaly; + game->state.playing = 0; break; + } case BUTTON_BACK: break; case BUTTON_PLAY: -- cgit v1.2.3