diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2025-04-05 17:27:22 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2025-04-05 17:27:22 +0100 |
commit | d36583ad6ae53708f1ae11bb7e4f4939e6ac3b4d (patch) | |
tree | b56533e4bdb81864e80771e1a3a2e16347328684 /src/all.c | |
parent | fa9bffcc842eb5973829d46436d3435993de9510 (diff) | |
download | ldjam57-d36583ad6ae53708f1ae11bb7e4f4939e6ac3b4d.tar |
allow cloning blues
Diffstat (limited to 'src/all.c')
-rw-r--r-- | src/all.c | 49 |
1 files changed, 48 insertions, 1 deletions
@@ -89,6 +89,16 @@ enum { N_COLORS, }; +static int isRed(int cell) { + return ( + cell == RED || + cell == RED_LEFT || + cell == RED_RIGHT || + cell == RED_UP || + cell == RED_DOWN + ); +} + static const Color colors[N_COLORS][4] = { { {255, 255, 255, 255}, @@ -372,7 +382,16 @@ static void update(Game *game, uint64_t now, Arena a) { } break; case YELLOW: - game->state.grid[x + y * GRIDWIDTH] = BLACK; + if ( + (x > 0 && lastState->grid[x - 1 + y * GRIDWIDTH] == BLUE_RIGHT) || + (x < GRIDWIDTH - 1 && lastState->grid[x + 1 + y * GRIDWIDTH] == BLUE_LEFT) || + (y > 0 && lastState->grid[x + (y - 1) * GRIDWIDTH] == BLUE_DOWN) || + (y < GRIDHEIGHT - 1 && lastState->grid[x + (y + 1) * GRIDWIDTH] == BLUE_UP) + ) { + game->state.grid[x + y * GRIDWIDTH] = RED; + } else { + game->state.grid[x + y * GRIDWIDTH] = BLACK; + } break; case BLUE: blues = 0; @@ -430,6 +449,13 @@ static void update(Game *game, uint64_t now, Arena a) { break; case BLUE_LEFT: if ( + (x > 0 && isRed(lastState->grid[x - 1 + y * GRIDWIDTH])) || + (x < GRIDWIDTH - 1 && isRed(lastState->grid[x + 1 + y * GRIDWIDTH])) || + (y > 0 && isRed(lastState->grid[x + (y - 1) * GRIDWIDTH])) || + (y < GRIDHEIGHT - 1 && isRed(lastState->grid[x + (y + 1) * GRIDWIDTH])) + ) { + game->state.grid[x + y * GRIDWIDTH] = BLUE; + } else if ( x > 0 && lastState->grid[x - 1 + y * GRIDWIDTH] == EMPTY ) { @@ -440,6 +466,13 @@ static void update(Game *game, uint64_t now, Arena a) { break; case BLUE_RIGHT: if ( + (x > 0 && isRed(lastState->grid[x - 1 + y * GRIDWIDTH])) || + (x < GRIDWIDTH - 1 && isRed(lastState->grid[x + 1 + y * GRIDWIDTH])) || + (y > 0 && isRed(lastState->grid[x + (y - 1) * GRIDWIDTH])) || + (y < GRIDHEIGHT - 1 && isRed(lastState->grid[x + (y + 1) * GRIDWIDTH])) + ) { + game->state.grid[x + y * GRIDWIDTH] = BLUE; + } else if ( x < GRIDWIDTH - 1 && lastState->grid[x + 1 + y * GRIDWIDTH] == EMPTY ) { @@ -450,6 +483,13 @@ static void update(Game *game, uint64_t now, Arena a) { break; case BLUE_UP: if ( + (x > 0 && isRed(lastState->grid[x - 1 + y * GRIDWIDTH])) || + (x < GRIDWIDTH - 1 && isRed(lastState->grid[x + 1 + y * GRIDWIDTH])) || + (y > 0 && isRed(lastState->grid[x + (y - 1) * GRIDWIDTH])) || + (y < GRIDHEIGHT - 1 && isRed(lastState->grid[x + (y + 1) * GRIDWIDTH])) + ) { + game->state.grid[x + y * GRIDWIDTH] = BLUE; + } else if ( y > 0 && lastState->grid[x + (y - 1) * GRIDWIDTH] == EMPTY ) { @@ -460,6 +500,13 @@ static void update(Game *game, uint64_t now, Arena a) { break; case BLUE_DOWN: if ( + (x > 0 && isRed(lastState->grid[x - 1 + y * GRIDWIDTH])) || + (x < GRIDWIDTH - 1 && isRed(lastState->grid[x + 1 + y * GRIDWIDTH])) || + (y > 0 && isRed(lastState->grid[x + (y - 1) * GRIDWIDTH])) || + (y < GRIDHEIGHT - 1 && isRed(lastState->grid[x + (y + 1) * GRIDWIDTH])) + ) { + game->state.grid[x + y * GRIDWIDTH] = BLUE; + } else if ( y < GRIDHEIGHT - 1 && lastState->grid[x + (y + 1) * GRIDWIDTH] == EMPTY ) { |