diff options
author | ostanton <114495956+ostanton@users.noreply.github.com> | 2025-04-06 12:07:10 +0100 |
---|---|---|
committer | ostanton <114495956+ostanton@users.noreply.github.com> | 2025-04-06 12:07:10 +0100 |
commit | af06f8718558683aa717bc98bcba1ed1a30e3737 (patch) | |
tree | 4fa20c40ccbb8adf05f7a406ef812e07d3f7e806 /src | |
parent | 88f5faa946944e6e5f46aba429bba1b2916cf1df (diff) | |
download | ldjam57-af06f8718558683aa717bc98bcba1ed1a30e3737.tar |
Functional continue and retry buttons
Diffstat (limited to 'src')
-rw-r--r-- | src/all.c | 25 |
1 files changed, 22 insertions, 3 deletions
@@ -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: |