From 1d422015dc353a5a5e62cd2413c1e05b0972b7ad Mon Sep 17 00:00:00 2001 From: Bill Rossi Date: Sun, 2 Feb 2025 05:21:20 -0500 Subject: [PATCH] Draw card images --- card.c | 37 ++++++++++++++++--------------------- card.h | 2 +- main.c | 6 +++++- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/card.c b/card.c index 7c7652f..5074afc 100644 --- a/card.c +++ b/card.c @@ -3,27 +3,22 @@ static Vector2 card_size = (Vector2) { CARD_WIDTH, CARD_HEIGHT }; static char *month_english_abbr[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; -void draw_card(Card *c) { - DrawRectangleV(c->position, card_size, c->selected ? RED : BLACK); - DrawRectangle(c->position.x + CARD_BORDER, c->position.y + CARD_BORDER, card_size.x - (CARD_BORDER * 2), card_size.y - (CARD_BORDER * 2) , WHITE); - DrawText(month_english_abbr[c->month], c->position.x + CARD_BORDER + 2, c->position.y + CARD_BORDER + 2, 14, BLACK); - switch (c->type) { - case CHAFF: - break; - case RIBBON: - Color ribbon_color = RED; - if (c->ribbon_type == RIBBON_BLUE) ribbon_color = BLUE; - DrawRectangle(c->position.x + 26, c->position.y + 35, 10, 45 , ribbon_color); - if (c->ribbon_type == RIBBON_POETRY) { - DrawRectangle(c->position.x + 29, c->position.y + 38, 4, 39 , BLACK); - } - break; - case ANIMAL: - DrawRectangle(c->position.x + 10, c->position.y + 45, 40, 25 , BLACK); - break; - case BRIGHT: - DrawCircle(c->position.x + 31, c->position.y + 65, 25 , YELLOW); - break; +void draw_card(Card *c, Texture2D *cards_texture) { + int i_vert = c->index % 4; + int i_horiz = c->index / 4; + int pos_vert = i_vert * 240; + int pos_horiz = i_horiz * 146; + + DrawTexturePro( + *cards_texture, + (Rectangle) { pos_horiz, pos_vert, 146, 240 }, + (Rectangle) { c->position.x, c->position.y, card_size.x, card_size.y }, + (Vector2) { 0, 0 }, + 0., + RAYWHITE + ); + if (c->selected) { + DrawCircle(c->position.x + 10, c->position.y + 10, 10, BLUE); } } diff --git a/card.h b/card.h index 76b6602..c9bf09c 100644 --- a/card.h +++ b/card.h @@ -53,7 +53,7 @@ struct Hand { int count; }; -void draw_card(Card *c); +void draw_card(Card *c, Texture2D *cards_texture); bool point_within_card(Card *c, Vector2 v); #endif diff --git a/main.c b/main.c index 90a1876..a278944 100644 --- a/main.c +++ b/main.c @@ -16,6 +16,10 @@ int main(int argc, char** argv) { InitWindow(800, 550, "Hanafuda Hachi-Hachi"); SetTargetFPS(60); + Image cards_image = LoadImage("img/cards.png"); + Texture2D cards_texture = LoadTextureFromImage(cards_image); + UnloadImage(cards_image); + /* Hand h; h.cards[0] = (Card) { 1, BRIGHT, RIBBON_NONE, NOVEMBER, (Vector2) { 0, 0 } }; @@ -95,7 +99,7 @@ int main(int argc, char** argv) { int num_selected = 0; for (int i = 0; i < 48; i++) { num_selected += cards[i].selected; - draw_card(&cards[i]); + draw_card(&cards[i], &cards_texture); } if (strlen(teyaku_calculation) == 0) {