Back to shtanton's homepage
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2025-04-06 22:26:55 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2025-04-06 22:26:55 +0100
commitbd31dd79eb31b76f3d7276be8dfaff21f615b1da (patch)
treeef1b4edf40d34b3da3928008ce032f5a05e23c32
parentacef84852c11b6e154535251d5e3a4ffb3a2cf8f (diff)
downloadldjam57-bd31dd79eb31b76f3d7276be8dfaff21f615b1da.tar
Adds many new levels
-rw-r--r--src/all.c85
-rw-r--r--src/levels.c279
-rw-r--r--src/tick.c35
-rw-r--r--src/types.c9
4 files changed, 386 insertions, 22 deletions
diff --git a/src/all.c b/src/all.c
index 340b500..b118a16 100644
--- a/src/all.c
+++ b/src/all.c
@@ -105,6 +105,7 @@ static const Button buttons[N_BUTTONS] = {
static int getPlaceAction(int currentColor, int cellx, int celly, float cellWidth, float cellHeight) {
int hoverColor = EMPTY;
+ // TODO yellow when there are no reds available
switch (currentColor) {
case BLACK:
if (cellx < cellWidth / 4 && cellx < celly && cellx < cellHeight - celly) {
@@ -133,6 +134,7 @@ static DrawList *render(State *state, UI *ui, Arena *a) {
float cellWidth = (float) (ui->width - GRID_OFFSET_X) / GRIDWIDTH;
float cellHeight = (float) ui->height / GRIDHEIGHT;
+ // Actual cells
for (int x = 0; x < GRIDWIDTH; x++) {
for (int y = 0; y < GRIDHEIGHT; y++) {
if (colorImages[(int) state->grid[x + GRIDWIDTH * y]]) {
@@ -184,15 +186,51 @@ static DrawList *render(State *state, UI *ui, Arena *a) {
};
}
+ // Spawner
+ if (state->spawnerx != 0 && state->spawnery != 0) {
+ drawList->els[drawList->len++] = (DrawElement) {
+ .x = cellWidth * state->spawnerx + GRID_OFFSET_X,
+ .y = cellHeight * state->spawnery,
+ .w = cellWidth,
+ .h = cellHeight,
+ .fill = {0, 0, 255, 63},
+ .border = {0, 0, 255, 255},
+ };
+ }
+
// Goal
- drawList->els[drawList->len++] = (DrawElement) {
- .x = cellWidth * state->goalx + GRID_OFFSET_X,
- .y = cellHeight * state->goaly,
- .w = cellWidth,
- .h = cellHeight,
- .fill = {255, 0, 0, 63},
- .border = {255, 0, 0, 255},
- };
+ if (state->levelComplete) {
+ drawList->els[drawList->len++] = (DrawElement) {
+ .x = cellWidth * state->goalx + GRID_OFFSET_X,
+ .y = cellHeight * state->goaly,
+ .w = cellWidth,
+ .h = cellHeight,
+ .fill = {0, 255, 0, 63},
+ .border = {0, 255, 0, 255},
+ };
+ } else {
+ drawList->els[drawList->len++] = (DrawElement) {
+ .x = cellWidth * state->goalx + GRID_OFFSET_X,
+ .y = cellHeight * state->goaly,
+ .w = cellWidth,
+ .h = cellHeight,
+ .fill = {255, 0, 0, 63},
+ .border = {255, 0, 0, 255},
+ };
+
+ if (state->need9) {
+ for (int i = 0; i < state->blues; i++) {
+ drawList->els[drawList->len++] = (DrawElement) {
+ .x = cellWidth * state->goalx + GRID_OFFSET_X + cellWidth / 3 * (i % 3),
+ .y = cellHeight * state->goaly + cellHeight / 3 * (i / 3),
+ .w = cellWidth / 3,
+ .h = cellHeight / 3,
+ .fill = {196, 255, 196, 255},
+ .border = {0, 200, 0, 255},
+ };
+ }
+ }
+ }
// Hover
if (ui->mousex >= GRID_OFFSET_X) {
@@ -343,7 +381,12 @@ static void restart_level(Game* game) {
xmemcpy(&game->state.grid, &levels[level].grid, sizeof(game->state.grid));
game->state.goalx = levels[level].goalx;
game->state.goaly = levels[level].goaly;
- game->state.playing = 1;
+ game->state.spawnerx = levels[level].spawnerx;
+ game->state.spawnery = levels[level].spawnery;
+ game->state.spawnerCount = 0;
+ game->state.playing = 0;
+ game->state.blues = 0;
+ game->state.need9 = levels[level].need9;
xmemcpy(&game->state.placeableCells, &levels[level].placeableCells, sizeof(game->state.placeableCells));
}
@@ -417,9 +460,25 @@ static void update(Game *game, uint64_t now, Arena a) {
}
break;
case INPUT_RCLICK:
- x = (game->ui.mousex - GRID_OFFSET_X) * GRIDWIDTH / (game->ui.width - GRID_OFFSET_X);
- y = game->ui.mousey * GRIDHEIGHT / game->ui.height;
- game->state.grid[x + y * GRIDWIDTH] = EMPTY;
+ if (game->ui.mousex > GRID_OFFSET_X) {
+ x = (game->ui.mousex - GRID_OFFSET_X) * GRIDWIDTH / (game->ui.width - GRID_OFFSET_X);
+ y = game->ui.mousey * GRIDHEIGHT / game->ui.height;
+
+ if (game->state.grid[x + y * GRIDWIDTH] != BLACK) {
+ break;
+ }
+
+ for (int i = 0; i < MAX_PLACEABLE_CELLS; i++) {
+ if (game->state.placeableCells[i] == YELLOW) {
+ game->state.grid[x + y * GRIDWIDTH] = YELLOW;
+ for (int j = i; j < MAX_PLACEABLE_CELLS - 1; j++) {
+ game->state.placeableCells[j] = game->state.placeableCells[j + 1];
+ }
+ game->state.placeableCells[MAX_PLACEABLE_CELLS - 1] = EMPTY;
+ break;
+ }
+ }
+ }
break;
case INPUT_PAUSE_PLAY:
game->state.playing = !game->state.playing;
@@ -467,7 +526,7 @@ int main(int argc, char **argv) {
};
Game *game = new(&a, 1, Game);
- game->state.currentLevel = 5;
+ game->state.currentLevel = 0;
restart_level(game);
game->ui = (UI) {
.width = 640,
diff --git a/src/levels.c b/src/levels.c
index f0254d4..a5f1d15 100644
--- a/src/levels.c
+++ b/src/levels.c
@@ -183,9 +183,9 @@ static Level levels[] = {
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
- _ _ _ _ _ _ RU _ _ _ _ _ _ _ _ _ _ _ _ _
- _ _ _ _ _ B _ _ _ _ O B _ _ _ _ _ _ _ _
- _ _ _ _ _ B _ _ _ _ O B _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ B B _ _ _ _ _ _ _
+ _ _ _ _ _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_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ B _ _ _ _ _ _ _ _ RU _ _ _ _ _ _ _ _ _ _
+ _ RU _ _ _ _ _ _ B _ _ _ _ _ _ _ _ _ _ _
+ },
+ .goalx = 8,
+ .goaly = 7,
+ .spawnerx = 13,
+ .spawnery = 7,
+ .need9 = 1,
+ .spawnRate = 3,
+ .placeableCells = {
+ RED,
+ RED,
+ YELLOW,
+ YELLOW,
+ },
+ },
+ {
+ // level 14
+ // An attempt at a red herring
+ // This one has some similarities to level 12 so I didn't want it to be level 13
+ .grid = {
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ B B _ R B _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ B B _ r B _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ B O _ _ _ _ _ _ _ _ _ _ _ RU _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ },
+ .goalx = 10,
+ .goaly = 7,
+ .spawnerx = 15,
+ .spawnery = 7,
+ .need9 = 1,
+ .spawnRate = 3,
+ .placeableCells = {
+ RED,
+ RED_UP,
+ YELLOW,
+ },
+ },
+ {
+ // level 15
+ // This one is a bit tricky
+ .grid = {
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ RU _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ B _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ B _ _ _ _ B _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ B _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ },
+ .goalx = 7,
+ .goaly = 9,
+ .spawnerx = 4,
+ .spawnery = 3,
+ .need9 = 1,
+ .spawnRate = 2,
+ .placeableCells = {
+ RED,
+ RED,
+ YELLOW,
+ YELLOW,
+ BLACK,
+ BLACK,
+ BLACK,
+ BLACK,
+ BLACK,
+ BLACK,
+ },
+ },
+ {
+ // level ?
+ // Must go after blues turning yellows into reds is introduced
+ .grid = {
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ O B B _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ B B _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ B _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ },
+ .need9 = 1,
.goalx = 6,
.goaly = 11,
.placeableCells = {
RED,
RED_UP,
RED_DOWN,
- RED_LEFT,
- RED_RIGHT,
+ YELLOW,
+ BLACK,
+ BLACK,
},
},
};
diff --git a/src/tick.c b/src/tick.c
index a15c1cb..21cf578 100644
--- a/src/tick.c
+++ b/src/tick.c
@@ -27,6 +27,10 @@ static void tick(Game *game, Arena a) {
State *lastState = new(&a, 1, State);
xmemcpy(lastState, game, sizeof(State));
+ if (lastState->spawnerCount > 0) {
+ game->state.spawnerCount = lastState->spawnerCount - 1;
+ }
+
for (int x = 0; x < GRIDWIDTH; x++) {
for (int y = 0; y < GRIDHEIGHT; y++) {
switch (lastState->grid[x + y * GRIDWIDTH]) {
@@ -180,6 +184,20 @@ static void tick(Game *game, Arena a) {
}
break;
case BLUE:
+ // Win condition
+ if (game->state.goalx == x && game->state.goaly == y) {
+ if (!game->state.need9) {
+ game->state.levelComplete = 1;
+ } else {
+ if (game->state.blues < 9) {
+ game->state.blues++;
+ if (game->state.blues == 9) {
+ game->state.levelComplete = 1;
+ }
+ }
+ }
+ game->state.grid[x + y * GRIDWIDTH] = EMPTY;
+ }
blues = 0;
if (
x > 0 && (
@@ -336,14 +354,23 @@ static void tick(Game *game, Arena a) {
} else if (blues >= 2) {
game->state.grid[x + y * GRIDWIDTH] = BLUE;
}
+
+ // Spawner
+ if (
+ game->state.spawnerx != 0 &&
+ game->state.spawnery != 0 &&
+ game->state.grid[x + y * GRIDWIDTH] == EMPTY &&
+ x == game->state.spawnerx &&
+ y == game->state.spawnery &&
+ lastState->spawnerCount == 0
+ ) {
+ game->state.grid[x + y * GRIDWIDTH] = BLUE;
+ game->state.spawnerCount = levels[game->state.currentLevel].spawnRate;
+ }
break;
}
}
}
-
- if (game->state.grid[game->state.goalx + game->state.goaly * GRIDWIDTH] == BLUE) {
- game->state.levelComplete = 1;
- }
}
#endif // INCLUDE_TICK_C
diff --git a/src/types.c b/src/types.c
index b2f1ee6..bf6dcf4 100644
--- a/src/types.c
+++ b/src/types.c
@@ -101,8 +101,12 @@ typedef struct {
} Button;
typedef struct {
+ // 0 if only 1 blue is needed, 1 if 9 are needed
+ char need9;
+ char spawnRate;
char grid[GRIDWIDTH * GRIDHEIGHT];
int goalx, goaly;
+ int spawnerx, spawnery;
char placeableCells[MAX_PLACEABLE_CELLS]; // Color
} Level;
@@ -110,8 +114,13 @@ typedef struct {
uint64_t lastTick;
char playing;
char levelComplete;
+ // How many blues have reached the end
+ char blues;
+ char need9;
char grid[GRIDWIDTH * GRIDHEIGHT];
int goalx, goaly;
+ int spawnerx, spawnery;
+ int spawnerCount;
ButtonState buttonStates[N_BUTTONS];
int currentLevel;
char placeableCells[MAX_PLACEABLE_CELLS];