summaryrefslogtreecommitdiff
path: root/game.c
diff options
context:
space:
mode:
authororangerot <orangerot@orangerot.dev>2025-10-14 16:32:45 +0200
committerorangerot <orangerot@orangerot.dev>2025-10-14 16:32:45 +0200
commit9efddf8a1a0f4a2e5b17563718346be84486653d (patch)
treeb2723c1cf6927526438fbff4a23b1529b0cf40b5 /game.c
parentd5a89c35f1e2e481a01b151616d5ad9e33da20de (diff)
feat: draw function
Diffstat (limited to 'game.c')
-rw-r--r--game.c55
1 files changed, 40 insertions, 15 deletions
diff --git a/game.c b/game.c
index 56f2a4a..7c788fe 100644
--- a/game.c
+++ b/game.c
@@ -11,11 +11,14 @@
#define MAX(a,b) (((a)>(b))?(a):(b))
#define CLAMP(x,a,b) (MIN(MAX(x,a),b))
-int mouse_x = 0, mouse_y = 0;
+size_t mouse_x = 0, mouse_y = 0;
int eyes_front = 0, eyes_back = 0;
struct bricks bricks = {0};
+struct brick hand[5];
+size_t hand_count = 0;
+
void key_callback(int key, int scancode, int action, int mods) {
if (action != GLFW_PRESS) return;
switch (key) {
@@ -58,26 +61,48 @@ void init() {
.back = {.x = 13, .y = 5, .val = 5},
}
);
+
+ hand_count = 3;
+ hand[0] = (struct brick) {
+ .front = {.x = 12, .y = 5, .val = 2},
+ .back = {.x = 13, .y = 5, .val = 5},
+ };
+ hand[1] = (struct brick) {
+ .front = {.x = 12, .y = 5, .val = 2},
+ .back = {.x = 13, .y = 5, .val = 5},
+ };
+ hand[2] = (struct brick) {
+ .front = {.x = 12, .y = 5, .val = 2},
+ .back = {.x = 13, .y = 5, .val = 5},
+ };
+}
+
+void
+draw(
+ struct image canvas, struct image texture,
+ size_t xpos, size_t ypos
+) {
+ for (size_t y = 0; y < texture.height; y++) {
+ for (size_t x = 0; x < texture.width; x++) {
+ canvas.buf[(ypos + y) * canvas.width + xpos + x] = texture.buf[y * texture.width + x];
+ }
+ }
}
-void draw_image(decoded_image img) {
- for (size_t i = 0; i < img.buf_size; i++) img.buf[i] = i;
+void render(struct image canvas) {
+ for (size_t i = 0; i < canvas.bufsize; i++) canvas.buf[i] = i;
+ // domino playground
for (size_t i = 0; i < bricks.count; i++) {
struct brick *b = &bricks.items.brick[i];
-
- for (int y = 0; y < DOMINO_HEIGHT; y++) {
- for (int x = 0; x < DOMINO_WIDTH; x++) {
- img.buf[(b->front.y * EYE_SIZE + y) * img.width + b->front.x * EYE_SIZE + x] =
- (*(uint32_t*) &domino[b->back.val][b->front.val][y * DOMINO_WIDTH * BYTES_PER_PIXEL + x * BYTES_PER_PIXEL]);
- }
- }
+ draw(canvas, domino[b->back.val][b->front.val], b->front.x * EYE_SIZE, b->front.y * EYE_SIZE);
}
- for (int y = 0; y < DOMINO_HEIGHT; y++) {
- for (int x = 0; x < DOMINO_WIDTH; x++) {
- img.buf[(CLAMP(mouse_y, 0, img.height) + y) * img.width + CLAMP(mouse_x, 0, img.width) + x] =
- (*(uint32_t*) &domino[eyes_front][eyes_back][y * DOMINO_WIDTH * BYTES_PER_PIXEL + x * BYTES_PER_PIXEL]);
- }
+ for (size_t i = 0; i < hand_count; i++) {
+ struct brick *b = &hand[i];
+ draw(canvas, domino[b->back.val][b->front.val], (canvas.width - hand_count *(DOMINO_WIDTH + 4))/2 + i * (DOMINO_WIDTH + 4), canvas.height - DOMINO_WIDTH);
}
+
+ draw(canvas,domino[eyes_front][eyes_back], CLAMP(mouse_x, 0, canvas.width), CLAMP(mouse_y, 0, canvas.height));
}
+