From 0ac20b711be724f81d844ee1fbb90bb9935c7a1a Mon Sep 17 00:00:00 2001 From: orangerot Date: Wed, 15 Oct 2025 15:11:47 +0200 Subject: [PATCH] feat: print description --- characters.h | 4 +-- game.c | 84 ++++++++++++++++++++++++++-------------------------- main.c | 6 ++-- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/characters.h b/characters.h index 679f394..5a2c8cf 100644 --- a/characters.h +++ b/characters.h @@ -46,7 +46,7 @@ uint32_t characters[96] = { 0b111001000011100100001000000000, // F 0b011001000010000101000110000000, // G 0b101001010011100101001010000000, // H - 0b111000100001000010001110000000, // I + 0b011100010000100001000111000000, // I 0b111000010000100101000110000000, // J 0b101001010011000101001010000000, // K 0b100001000010000100001110000000, // L @@ -78,7 +78,7 @@ uint32_t characters[96] = { 0b011000100011100010000100000000, // f 0b000001110010100111000010011100, // g 0b100001000011100101001010000000, // h - 0b100000000010000100001100000000, // i + 0b010000000001000010000110000000, // i 0b010000000001000010000100011000, // j 0b100001000010100110001010000000, // k 0b110000100001000010001110000000, // l diff --git a/game.c b/game.c index 73373c0..e9846b8 100644 --- a/game.c +++ b/game.c @@ -184,34 +184,33 @@ void mouse_button_callback(int button, int action, int mods) { } -void init() { +void init(struct image canvas) { + camera_x = canvas.width / 2; + camera_y = canvas.height / 2; + 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}, + .front = {.x = 0, .y = 0, .val = 3}, + .back = {.x = 1, .y = 0, .val = 2}, } ); - hand_count = 3; - hand[0] = (struct brick) { - .front = {.x = 12, .y = 5, .val = 0}, - .back = {.x = 13, .y = 5, .val = 3}, + hand[hand_count++] = (struct brick) { + .front = {.val = 0}, + .back = {.val = 3}, }; - hand[1] = (struct brick) { - .front = {.x = 12, .y = 5, .val = 4}, - .back = {.x = 13, .y = 5, .val = 1}, + hand[hand_count++] = (struct brick) { + .front = {.val = 4}, + .back = {.val = 1}, }; - hand[2] = (struct brick) { - .front = {.x = 12, .y = 5, .val = 2}, - .back = {.x = 13, .y = 5, .val = 5}, + hand[hand_count++] = (struct brick) { + .front = {.val = 2}, + .back = {.val = 5}, + }; + hand[hand_count++] = (struct brick) { + .front = {.val = 2}, + .back = {.val = 5}, }; } @@ -225,12 +224,7 @@ void draw( struct image canvas, struct image texture, size_t xpos, size_t ypos, } } -void -draw_character( - struct image canvas, - char *character, - size_t xpos, size_t ypos -) { +void draw_glyph( struct image canvas, uint32_t glyph, size_t xpos, size_t ypos, struct color color) { struct image texture = { .width = 5, .height = 6, @@ -238,28 +232,27 @@ draw_character( .buf = (uint32_t[30]) {0} }; - for (size_t i = 0; character[i]; i++) { - const uint32_t bitmask = characters[character[i] - ' ']; - texture.buf = (uint32_t[30]) {0}; + texture.buf = (uint32_t[30]) {0}; - for (size_t y = 0; y < texture.height; y++) { - for (size_t x = 0; x < texture.width; x++) { - if ((bitmask >> ((texture.height - y - 1) * texture.width + (texture.width - x - 1))) & 1) { - texture.buf[y * texture.width + x] = -1; - } + for (size_t y = 0; y < texture.height; y++) { + for (size_t x = 0; x < texture.width; x++) { + if ((glyph >> ((texture.height - y - 1) * texture.width + (texture.width - x - 1))) & 1) { + texture.color[y * texture.width + x] = color; } } - draw(canvas, texture, xpos + i * texture.width, ypos, 0); + } + draw(canvas, texture, xpos, ypos, 0); +} + +void print(struct image canvas, char *string, size_t xpos, size_t ypos, struct color color) { + for (size_t i = 0; string[i]; i++) { + uint32_t glyph = characters[string[i] - ' ']; + draw_glyph(canvas, glyph, xpos + i * 5, ypos, color); } } -//void -//draw_text( -// -//) - void render(struct image canvas) { - for (size_t i = 0; i < canvas.bufsize; i++) canvas.buf[i] = i; + for (size_t i = 0; i < canvas.bufsize; i++) canvas.buf[i] = 0; // domino playground for (size_t i = 0; i < bricks.count; i++) { @@ -280,13 +273,20 @@ 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}); + // active if (has_active) { draw(canvas, red_and_peach_dominoes[active.back.val][active.front.val], CLAMP(mouse_x + active.front.x, 0, canvas.width), CLAMP(mouse_y + active.front.y, 0, canvas.height), active.front.vertical); } // character - draw_character(canvas, "Hallo Welt", 50, 20); // debugging + char title[] = "domino dungeon"; + char inventory[] = "Inventory"; + // 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}); } diff --git a/main.c b/main.c index c6ff1ca..a278597 100644 --- a/main.c +++ b/main.c @@ -22,8 +22,8 @@ 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 render(struct image img); +extern void init(struct image canvas); +extern void render(struct image canvas); uint32_t buffer[256 * 240] = {0}; @@ -252,7 +252,7 @@ int main() { glUseProgram(shader_program); glUniform1i(glGetUniformLocation(shader_program, "texture1"), 0); - init(); + init(canvas); #ifdef __EMSCRIPTEN__ emscripten_set_main_loop(loop, 0, true);