summaryrefslogtreecommitdiff
path: root/game.c
diff options
context:
space:
mode:
authororangerot <orangerot@orangerot.dev>2025-10-14 06:17:32 +0200
committerorangerot <orangerot@orangerot.dev>2025-10-14 06:17:32 +0200
commit2d359fb932c245267d3da8edbb479b549fc6cebb (patch)
tree125b93953833588cc98821cd73b7c6c91e9c74d9 /game.c
parent06aaf6e0bab748c2b491c8a56715c9ac74f1e36e (diff)
feat: draw dominos
Diffstat (limited to 'game.c')
-rw-r--r--game.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/game.c b/game.c
index 1cfc1a1..77ce70c 100644
--- a/game.c
+++ b/game.c
@@ -1,13 +1,17 @@
#include <glad/glad.h>
#include <GLFW/glfw3.h>
+#include <stdint.h>
+#include <stdio.h>
#include "game.h"
+#include "assets/dominos.h"
#define MIN(a,b) (((a)<(b))?(a):(b))
#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;
+int eyes_front = 0, eyes_back = 0;
void key_callback(int key, int scancode, int action, int mods) {
if (action != GLFW_PRESS) return;
@@ -25,11 +29,23 @@ void cursor_position_callback(int xpos, int ypos) {
}
void mouse_button_callback(int button, int action, int mods) {
- if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) {}
+ printf("click!\n");
+
+ if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) {
+ if (++eyes_back >= NUM_DOMINO_X) {
+ eyes_back = 0;
+ eyes_front = (eyes_front+1)%NUM_DOMINO_Y;
+ }
+ }
}
void draw_image(decoded_image img) {
// for (int i = 0; i < img.buf_size; i++) img.buf[i] = i;
- img.buf[CLAMP(mouse_y, 0, img.height) * img.width +
- CLAMP(mouse_x, 0, img.width)] = -1;
+
+ 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]);
+ }
+ }
}