From 8c4d5838e67d62775983fb46a64813d8b6bceb28 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Sun, 6 Apr 2025 09:15:32 +0100 Subject: Minor bug fixes --- src/all.c | 40 ++++++++++++++++++++++++++-------------- src/tick.c | 19 ++++++++++++++----- 2 files changed, 40 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/all.c b/src/all.c index 15f2558..82f1360 100644 --- a/src/all.c +++ b/src/all.c @@ -104,34 +104,47 @@ static DrawList *render(State *state, UI *ui, Arena *a) { DrawList *drawList = new(a, 1, DrawList); - int cellWidth = (ui->width - GRID_OFFSET_X) / GRIDWIDTH; - int cellHeight = ui->height / GRIDHEIGHT; + float cellWidth = (float) (ui->width - GRID_OFFSET_X) / GRIDWIDTH; + float cellHeight = (float) ui->height / GRIDHEIGHT; for (int x = 0; x < GRIDWIDTH; x++) { for (int y = 0; y < GRIDHEIGHT; y++) { - drawList->els[drawList->len++] = (DrawElement) { - .x = cellWidth * x + GRID_OFFSET_X, - .y = cellHeight * y, - .w = cellWidth, - .h = cellHeight, - .fill = {0, 0, 0, 0}, - .border = {0, 0, 0, 255}, - }; for (int subx = 0; subx < 2; subx++) { for (int suby = 0; suby < 2; suby++) { drawList->els[drawList->len++] = (DrawElement) { .x = cellWidth * x + GRID_OFFSET_X + subx * cellWidth / 2, .y = cellHeight * y + suby * cellHeight / 2, - .w = cellWidth / 2, - .h = cellHeight / 2, + .w = cellWidth / 2 + (1 - subx), + .h = cellHeight / 2 + (1 - suby), .fill = colors[state->grid[x + GRIDWIDTH * y]][subx + 2 * suby], - .border = {0, 0, 0, 0}, }; } } } } + // Vertical grid lines + for (int x = 1; x < GRIDWIDTH; x++) { + drawList->els[drawList->len++] = (DrawElement) { + .x = cellWidth * x + GRID_OFFSET_X, + .y = 0, + .w = 1, + .h = ui->height, + .fill = {0, 0, 0, 255}, + }; + } + + // Horizontal grid lines + for (int y = 1; y < GRIDHEIGHT; y++) { + drawList->els[drawList->len++] = (DrawElement) { + .x = GRID_OFFSET_X, + .y = y * cellHeight, + .w = ui->width - GRID_OFFSET_X, + .h = 1, + .fill = {0, 0, 0, 255}, + }; + } + drawList->els[drawList->len++] = (DrawElement) { .x = cellWidth * state->goalx + GRID_OFFSET_X, .y = cellHeight * state->goaly, @@ -139,7 +152,6 @@ static DrawList *render(State *state, UI *ui, Arena *a) { .h = cellHeight, .fill = {255, 0, 0, 63}, .border = {255, 0, 0, 255}, - .image = 1, }; drawList->els[drawList->len++] = (DrawElement) { diff --git a/src/tick.c b/src/tick.c index 4b255df..598087a 100644 --- a/src/tick.c +++ b/src/tick.c @@ -302,30 +302,39 @@ static void tick(Game *game, Arena a) { } break; case EMPTY: - // TODO: same as multiple reds + blues = 0; if ( x > 0 && lastState->grid[x - 1 + y * GRIDWIDTH] == BLUE_RIGHT ) { - game->state.grid[x + y * GRIDWIDTH] = BLUE_RIGHT; + blues++; + blue = BLUE_RIGHT; } if ( x < GRIDWIDTH - 1 && lastState->grid[x + 1 + y * GRIDWIDTH] == BLUE_LEFT ) { - game->state.grid[x + y * GRIDWIDTH] = BLUE_LEFT; + blues++; + blue = BLUE_LEFT; } if ( y > 0 && lastState->grid[x + (y - 1) * GRIDWIDTH] == BLUE_DOWN ) { - game->state.grid[x + y * GRIDWIDTH] = BLUE_DOWN; + blues++; + blue = BLUE_DOWN; } if ( y < GRIDHEIGHT - 1 && lastState->grid[x + (y + 1) * GRIDWIDTH] == BLUE_UP ) { - game->state.grid[x + y * GRIDWIDTH] = BLUE_UP; + blues++; + blue = BLUE_UP; + } + if (blues == 1) { + game->state.grid[x + y * GRIDWIDTH] = blue; + } else if (blues >= 2) { + game->state.grid[x + y * GRIDWIDTH] = BLUE; } break; } -- cgit v1.2.3