feat: game goal

This commit is contained in:
orangerot 2025-10-15 15:50:18 +02:00
parent 0ac20b711b
commit a65050fbb3

48
game.c
View file

@ -3,6 +3,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h>
#include "game.h" #include "game.h"
#include "domino.h" #include "domino.h"
@ -31,6 +32,10 @@ int camera_x = 0;
int camera_y = 0; int camera_y = 0;
bool is_dragging = 0; bool is_dragging = 0;
int goal_x = 5;
int goal_y = 5;
bool is_goal_reached = 0;
#define DIRECTIONS 6 #define DIRECTIONS 6
struct eye direction[DIRECTIONS] = { struct eye direction[DIRECTIONS] = {
{.x = 0, .y = -1}, {.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].front.vertical = active.front.vertical;
preview[min_dist].back.val = active.back.val; preview[min_dist].back.val = active.back.val;
bricks_append(&bricks, preview[min_dist]); 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]); for (size_t i = 0; i < bricks.count; i++) print_brick(bricks.items.brick[i]);
} else { } else {
hand[hand_count++] = active; hand[hand_count++] = active;
@ -191,27 +204,17 @@ void init(struct image canvas) {
bricks_append( bricks_append(
&bricks, &bricks,
(struct brick) { (struct brick) {
.front = {.x = 0, .y = 0, .val = 3}, .front = {.x = 0, .y = 0, .val = rand() % 6},
.back = {.x = 1, .y = 0, .val = 2}, .back = {.x = 1, .y = 0, .val = rand() % 6},
} }
); );
hand[hand_count++] = (struct brick) { for (size_t i = 0; i < 5; i++) {
.front = {.val = 0}, hand[hand_count++] = (struct brick) {
.back = {.val = 3}, .front = {.val = rand() % 6},
}; .back = {.val = rand() % 6},
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},
};
} }
void draw( struct image canvas, struct image texture, size_t xpos, size_t ypos, bool vertical) { 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(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 // active
if (has_active) { if (has_active) {
@ -281,12 +284,17 @@ void render(struct image canvas) {
} }
// character // character
char title[] = "domino dungeon"; // char title[] = "domino dungeon";
char inventory[] = "Inventory"; 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, 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, 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, "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}); 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});
}
} }