Back to shtanton's homepage
summaryrefslogtreecommitdiff
path: root/src/all.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/all.c')
-rw-r--r--src/all.c85
1 files changed, 72 insertions, 13 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,