Back to shtanton's homepage
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2025-04-05 14:36:30 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2025-04-05 14:36:30 +0100
commit721f08c3dbd88575253540206355b9eb8ee55f45 (patch)
treeaacea3f62363ef5b25cd7930af3cf53b0e6f1f1b
parentd229a3f7b851ee9caa7f98c8075f8b4867762f60 (diff)
downloadldjam57-721f08c3dbd88575253540206355b9eb8ee55f45.tar
Add directional reds
-rw-r--r--src/all.c134
1 files changed, 105 insertions, 29 deletions
diff --git a/src/all.c b/src/all.c
index 1373475..a28b8ca 100644
--- a/src/all.c
+++ b/src/all.c
@@ -8,6 +8,10 @@
#define xmemcpy __builtin_memcpy
#endif
+#define MEM_SIZE (1<<24)
+#define GRIDWIDTH 16
+#define GRIDHEIGHT 16
+#define TICK_LENGTH 200
typedef struct {
unsigned char r, g, b, a;
@@ -21,14 +25,9 @@ typedef struct {
typedef struct {
int len;
- DrawElement els[512];
+ DrawElement els[2 * GRIDWIDTH * GRIDHEIGHT * 4];
} DrawList;
-#define MEM_SIZE (1<<16)
-#define GRIDWIDTH 16
-#define GRIDHEIGHT 16
-#define TICK_LENGTH 200
-
typedef struct {
char *start;
char *end;
@@ -78,14 +77,48 @@ enum {
BLACK,
RED,
YELLOW,
+ RED_LEFT,
+ RED_RIGHT,
N_COLORS,
};
-static const Color colors[N_COLORS] = {
- {255, 255, 255, 255},
- {0, 0, 0, 255},
- {255, 0, 0, 255},
- {255, 255, 0, 255}
+static const Color colors[N_COLORS][4] = {
+ {
+ {255, 255, 255, 255},
+ {255, 255, 255, 255},
+ {255, 255, 255, 255},
+ {255, 255, 255, 255},
+ },
+ {
+ {0, 0, 0, 255},
+ {0, 0, 0, 255},
+ {0, 0, 0, 255},
+ {0, 0, 0, 255},
+ },
+ {
+ {255, 0, 0, 255},
+ {255, 0, 0, 255},
+ {255, 0, 0, 255},
+ {255, 0, 0, 255},
+ },
+ {
+ {255, 255, 0, 255},
+ {255, 255, 0, 255},
+ {255, 255, 0, 255},
+ {255, 255, 0, 255},
+ },
+ {
+ {255, 0, 0, 255},
+ {0, 0, 0, 255},
+ {255, 0, 0, 255},
+ {0, 0, 0, 255},
+ },
+ {
+ {0, 0, 0, 255},
+ {255, 0, 0, 255},
+ {0, 0, 0, 255},
+ {255, 0, 0, 255},
+ },
};
static DrawList *render(State *state, UI *ui, Arena *a) {
@@ -103,9 +136,21 @@ static DrawList *render(State *state, UI *ui, Arena *a) {
.y = cellHeight * y,
.w = cellWidth,
.h = cellHeight,
- .fill = colors[state->grid[x + GRIDWIDTH * y]],
+ .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 + subx * cellWidth / 2,
+ .y = cellHeight * y + suby * cellHeight / 2,
+ .w = cellWidth / 2,
+ .h = cellHeight / 2,
+ .fill = colors[state->grid[x + GRIDWIDTH * y]][subx + 2 * suby],
+ .border = {0, 0, 0, 0},
+ };
+ }
+ }
}
}
@@ -134,23 +179,53 @@ static void update(Game *game, uint64_t now, Arena a) {
for (int x = 0; x < GRIDWIDTH; x++) {
for (int y = 0; y < GRIDHEIGHT; y++) {
- if (
- lastState->grid[x + y * GRIDWIDTH] == BLACK && (
- (x > 0 && lastState->grid[x - 1 + y * GRIDWIDTH] == RED) ||
- (x < GRIDWIDTH - 1 && lastState->grid[x + 1 + y * GRIDWIDTH] == RED) ||
- (y > 0 && lastState->grid[x + (y - 1) * GRIDWIDTH] == RED) ||
- (y < GRIDHEIGHT - 1 && lastState->grid[x + (y + 1) * GRIDWIDTH] == RED)
- )
- ) {
- game->state.grid[x + y * GRIDWIDTH] = RED;
- }
-
- if (lastState->grid[x + y * GRIDWIDTH] == RED) {
- game->state.grid[x + y * GRIDWIDTH] = YELLOW;
- }
-
- if (lastState->grid[x + y * GRIDWIDTH] == YELLOW) {
- game->state.grid[x + y * GRIDWIDTH] = BLACK;
+ switch (lastState->grid[x + y * GRIDWIDTH]) {
+ case BLACK:
+ if (
+ x < GRIDWIDTH - 1 &&
+ lastState->grid[x + 1 + y * GRIDWIDTH] == RED_LEFT
+ ) {
+ game->state.grid[x + y * GRIDWIDTH] = RED_LEFT;
+ } else if (
+ x > 0 &&
+ lastState->grid[x - 1 + y * GRIDWIDTH] == RED_RIGHT
+ ) {
+ game->state.grid[x + y * GRIDWIDTH] = RED_RIGHT;
+ } else if (
+ (x > 0 && lastState->grid[x - 1 + y * GRIDWIDTH] == RED) ||
+ (x < GRIDWIDTH - 1 && lastState->grid[x + 1 + y * GRIDWIDTH] == RED) ||
+ (y > 0 && lastState->grid[x + (y - 1) * GRIDWIDTH] == RED) ||
+ (y < GRIDHEIGHT - 1 && lastState->grid[x + (y + 1) * GRIDWIDTH] == RED)
+ ) {
+ game->state.grid[x + y * GRIDWIDTH] = RED;
+ }
+ break;
+ case RED:
+ game->state.grid[x + y * GRIDWIDTH] = YELLOW;
+ break;
+ case RED_LEFT:
+ if (
+ x > 0 &&
+ lastState->grid[x - 1 + y * GRIDWIDTH] == BLACK
+ ) {
+ game->state.grid[x + y * GRIDWIDTH] = YELLOW;
+ } else {
+ game->state.grid[x + y * GRIDWIDTH] = RED_RIGHT;
+ }
+ break;
+ case RED_RIGHT:
+ if (
+ x < GRIDWIDTH - 1 &&
+ lastState->grid[x + 1 + y * GRIDWIDTH] == BLACK
+ ) {
+ game->state.grid[x + y * GRIDWIDTH] = YELLOW;
+ } else {
+ game->state.grid[x + y * GRIDWIDTH] = RED_LEFT;
+ }
+ break;
+ case YELLOW:
+ game->state.grid[x + y * GRIDWIDTH] = BLACK;
+ break;
}
}
}
@@ -191,6 +266,7 @@ int main(int argc, char **argv) {
SDL_SetNumberProperty(renderProps, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER, 1);
SDL_Renderer *r = SDL_CreateRendererWithProperties(renderProps);
SDL_DestroyProperties(renderProps);
+ SDL_SetRenderDrawBlendMode(r, SDL_BLENDMODE_BLEND);
for (;;) {
uint64_t now = SDL_GetTicks();