diff options
Diffstat (limited to 'game.c')
| -rw-r--r-- | game.c | 82 |
1 files changed, 41 insertions, 41 deletions
@@ -184,34 +184,33 @@ 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}, - } - ); +void init(struct image canvas) { + camera_x = canvas.width / 2; + camera_y = canvas.height / 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[hand_count++] = (struct brick) { + .front = {.val = 4}, + .back = {.val = 1}, }; - 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 = 2}, + .back = {.val = 5}, }; - 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}, }; } @@ -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 -//draw_text( -// -//) +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 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}); } |
