summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororangerot <orangerot@orangerot.dev>2025-10-14 14:48:54 +0200
committerorangerot <orangerot@orangerot.dev>2025-10-14 14:48:54 +0200
commite7bfbbc35c02711929575b5bbbd6f07c9f953fd4 (patch)
tree0b3704f5f04f0892c5807325c1c7892a398e05f2
parent1be303f6f6927165f1fb804b790763a95529baed (diff)
feat: data structure for domino blocks
-rw-r--r--Makefile5
-rw-r--r--game.c34
-rw-r--r--main.c3
3 files changed, 39 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 3f40477..bbccd19 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,8 @@
-CFLAGS := -Wall -Wextra
+CFLAGS := -ggdb -Wall -Wextra
+# -fsanitize=address
LDFLAGS = -lglfw -lm -lGL -I./glad/include
-SOURCES = main.c game.c game.h glad/src/glad.c assets/dominos.h
+SOURCES = main.c game.c game.h glad/src/glad.c assets/dominos.h domino.c domino.h
domino-dungeon: ${SOURCES}
$(CC) ${CFLAGS} ${LDFLAGS} -o $@ $^
diff --git a/game.c b/game.c
index e50defb..14a8e67 100644
--- a/game.c
+++ b/game.c
@@ -1,8 +1,10 @@
#include <GLFW/glfw3.h>
+#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include "game.h"
+#include "domino.h"
#include "assets/dominos.h"
#define MIN(a,b) (((a)<(b))?(a):(b))
@@ -12,6 +14,8 @@
int mouse_x = 0, mouse_y = 0;
int eyes_front = 0, eyes_back = 0;
+struct bricks bricks = {0};
+
void key_callback(int key, int scancode, int action, int mods) {
if (action != GLFW_PRESS) return;
switch (key) {
@@ -38,8 +42,36 @@ void mouse_button_callback(int button, int action, int mods) {
}
}
+void init() {
+ bricks_append(
+ &bricks,
+ (struct brick) {
+ .front = {.x = 10, .y = 5, .val = 3},
+ .back = {.x = 11, .y = 5, .val = 2},
+ }
+ );
+ bricks_append(
+ &bricks,
+ (struct brick) {
+ .front = {.x = 12, .y = 5, .val = 2},
+ .back = {.x = 13, .y = 5, .val = 5},
+ }
+ );
+}
+
void draw_image(decoded_image img) {
- for (int i = 0; i < img.buf_size; i++) img.buf[i] = i;
+ for (size_t i = 0; i < img.buf_size; i++) img.buf[i] = i;
+
+ 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 * 10 + y) * img.width + b->front.x * 10 + x] =
+ (*(uint32_t*) &domino[b->front.val][b->back.val][y * DOMINO_WIDTH * BYTES_PER_PIXEL + x * BYTES_PER_PIXEL]);
+ }
+ }
+ }
for (int y = 0; y < DOMINO_HEIGHT; y++) {
for (int x = 0; x < DOMINO_WIDTH; x++) {
diff --git a/main.c b/main.c
index 5ecb5f5..65c70c4 100644
--- a/main.c
+++ b/main.c
@@ -22,6 +22,7 @@ unsigned int VAO;
extern void key_callback(int key, int scancode, int action, int mods);
extern void cursor_position_callback(int xpos, int ypos);
extern void mouse_button_callback(int button, int action, int mods);
+extern void init();
extern void draw_image(decoded_image img);
uint32_t buffer[256 * 240] = {0};
@@ -251,6 +252,8 @@ int main() {
glUseProgram(shader_program);
glUniform1i(glGetUniformLocation(shader_program, "texture1"), 0);
+ init();
+
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, 0, true);
#else