From a65050fbb3475e94f842fe35cca2652c02cb339d Mon Sep 17 00:00:00 2001 From: orangerot Date: Wed, 15 Oct 2025 15:50:18 +0200 Subject: [PATCH] feat: game goal --- game.c | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/game.c b/game.c index e9846b8..e05f39b 100644 --- a/game.c +++ b/game.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "game.h" #include "domino.h" @@ -31,6 +32,10 @@ int camera_x = 0; int camera_y = 0; bool is_dragging = 0; +int goal_x = 5; +int goal_y = 5; +bool is_goal_reached = 0; + #define DIRECTIONS 6 struct eye direction[DIRECTIONS] = { {.x = 0, .y = -1}, @@ -173,6 +178,14 @@ void mouse_button_callback(int button, int action, int mods) { preview[min_dist].front.vertical = active.front.vertical; preview[min_dist].back.val = active.back.val; bricks_append(&bricks, preview[min_dist]); + hand[hand_count++] = (struct brick) { + .front = {.val = rand() % 6}, + .back = {.val = rand() % 6}, + }; + if ((preview[min_dist].front.x == goal_x && preview[min_dist].front.y == goal_y) || + (preview[min_dist].back.x == goal_x && preview[min_dist].back.y == goal_y)) { + is_goal_reached = 1; + } for (size_t i = 0; i < bricks.count; i++) print_brick(bricks.items.brick[i]); } else { hand[hand_count++] = active; @@ -191,27 +204,17 @@ void init(struct image canvas) { bricks_append( &bricks, (struct brick) { - .front = {.x = 0, .y = 0, .val = 3}, - .back = {.x = 1, .y = 0, .val = 2}, + .front = {.x = 0, .y = 0, .val = rand() % 6}, + .back = {.x = 1, .y = 0, .val = rand() % 6}, } ); - hand[hand_count++] = (struct brick) { - .front = {.val = 0}, - .back = {.val = 3}, - }; - hand[hand_count++] = (struct brick) { - .front = {.val = 4}, - .back = {.val = 1}, - }; - hand[hand_count++] = (struct brick) { - .front = {.val = 2}, - .back = {.val = 5}, - }; - hand[hand_count++] = (struct brick) { - .front = {.val = 2}, - .back = {.val = 5}, - }; + for (size_t i = 0; i < 5; i++) { + hand[hand_count++] = (struct brick) { + .front = {.val = rand() % 6}, + .back = {.val = rand() % 6}, + }; + } } void draw( struct image canvas, struct image texture, size_t xpos, size_t ypos, bool vertical) { @@ -273,7 +276,7 @@ void render(struct image canvas) { draw(canvas, red_and_peach_dominoes[b->back.val][b->front.val], b->front.x, b->front.y, b->front.vertical); } - draw_glyph(canvas, (uint32_t) 0b00011000111001100010000100011100, 50, 50, (struct color) {255, 255, 0, 255}); + draw_glyph(canvas, (uint32_t) 0b00011000111001100010000100011100, camera_x + goal_x * EYE_SIZE + 3, camera_y + goal_y * EYE_SIZE + 3, (struct color) {255, 255, 0, 255}); // active if (has_active) { @@ -281,12 +284,17 @@ void render(struct image canvas) { } // character - char title[] = "domino dungeon"; + // char title[] = "domino dungeon"; char inventory[] = "Inventory"; + char game_over[] = "You reached the goal!"; // print(canvas, title, (canvas.width - (sizeof(title)-1) * 5) / 2, 5, (struct color) {255, 255, 255, 255}); print(canvas, inventory, (canvas.width - (sizeof(inventory)-1) * 5) / 2, canvas.height - DOMINO_WIDTH - 10, (struct color) {255, 255, 255, 255}); print(canvas, "Drag Dominos from your inventory onto the chain to", 3, 2, (struct color) {255, 255, 255, 255}); print(canvas, "reach the goal. Press [R] to rotate", 3, 9, (struct color) {255, 255, 255, 255}); + if (is_goal_reached) { + print(canvas, game_over, (canvas.width - (sizeof(game_over)-1) * 5) / 2, 20, (struct color) {255, 255, 255, 255}); + } + }