diff options
Diffstat (limited to 'game.c')
| -rw-r--r-- | game.c | 54 |
1 files changed, 48 insertions, 6 deletions
@@ -5,8 +5,9 @@ #include "game.h" #include "domino.h" -#include "assets/dominos.h" #include "characters.h" +#include "assets/white_and_blue_dominoes.h" +#include "assets/red_and_peach_dominoes.h" #define MIN(a,b) (((a)<(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b)) @@ -22,6 +23,13 @@ size_t hand_count = 0; struct brick active = {0}; int has_active = 0; +struct eye direction[4] = { + {.x = 0, .y = -1}, + {.x = -2, .y = 0}, + {.x = 1, .y = 0}, + {.x = 0, .y = 1}, +}; + void key_callback(int key, int scancode, int action, int mods) { if (action != GLFW_PRESS) return; switch (key) { @@ -59,8 +67,10 @@ void mouse_button_callback(int button, int action, int mods) { printf("click!\n"); if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_RELEASE) { - has_active = 0; - hand[hand_count++] = active; + if (has_active) { + has_active = 0; + hand[hand_count++] = active; + } } } @@ -148,7 +158,39 @@ void render(struct image canvas) { // domino playground for (size_t i = 0; i < bricks.count; i++) { struct brick *b = &bricks.items.brick[i]; - draw(canvas, domino[b->back.val][b->front.val], b->front.x * EYE_SIZE, b->front.y * EYE_SIZE); + draw(canvas, red_and_peach_dominoes[b->back.val][b->front.val], b->front.x * EYE_SIZE, b->front.y * EYE_SIZE); + } + + if (has_active) { + for (size_t i = 0; i < bricks.count * 2; i++) { + struct eye e = bricks.items.eye[i]; + if (e.val != active.front.val) continue; + + struct brick p = active; + p.front.x = e.x; + p.front.y = e.y; + p.back.x = e.x + 1; + p.back.y = e.y; + struct brick previews[4] = {p, p, p, p}; + for (size_t ii = 0; ii < 4; ii++) { + previews[ii].front.x += direction[ii].x; + previews[ii].front.y += direction[ii].y; + previews[ii].front.val = 0; + + previews[ii].back.x += direction[ii].x; + previews[ii].back.y += direction[ii].y; + + for (size_t iii = 0; iii < bricks.count * 2; iii++) { + previews[ii].front.val |= ((bricks.items.eye[iii].x == previews[ii].back.x && bricks.items.eye[iii].y == previews[ii].back.y) || + (bricks.items.eye[iii].x == previews[ii].front.x && bricks.items.eye[iii].y == previews[ii].front.y)); + } + } + + for (size_t ii = 0; ii < 4; ii++) { + if (!previews[ii].front.val) + draw(canvas, white_and_blue_dominoes[active.back.val][active.front.val], previews[ii].front.x * EYE_SIZE, previews[ii].front.y * EYE_SIZE); + } + } } // hand @@ -156,12 +198,12 @@ void render(struct image canvas) { struct brick *b = &hand[i]; b->front.x = (canvas.width - hand_count *(DOMINO_WIDTH + 4))/2 + i * (DOMINO_WIDTH + 4); b->front.y = canvas.height - DOMINO_WIDTH; - draw(canvas, domino[b->back.val][b->front.val], b->front.x, b->front.y); + draw(canvas, red_and_peach_dominoes[b->back.val][b->front.val], b->front.x, b->front.y); } // active if (has_active) { - draw(canvas,domino[active.back.val][active.front.val], CLAMP(mouse_x + active.front.x, 0, canvas.width), CLAMP(mouse_y + active.front.y, 0, canvas.height)); + 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)); } // character |
