diff options
| -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: | 
