diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2025-04-06 09:15:32 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2025-04-06 09:15:32 +0100 |
commit | 8c4d5838e67d62775983fb46a64813d8b6bceb28 (patch) | |
tree | dbd84695d747253de214f57f882c8e9191158bbe | |
parent | 1c7d286f89592f5ca89557565226869e7ec04bcb (diff) | |
download | ldjam57-8c4d5838e67d62775983fb46a64813d8b6bceb28.tar |
Minor bug fixes
-rw-r--r-- | src/all.c | 40 | ||||
-rw-r--r-- | src/tick.c | 19 |
2 files changed, 40 insertions, 19 deletions
@@ -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) { @@ -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; } |