Draw card images

This commit is contained in:
Bill Rossi 2025-02-02 05:21:20 -05:00
parent 37bb1b47d0
commit 1d422015dc
3 changed files with 22 additions and 23 deletions

37
card.c
View File

@ -3,27 +3,22 @@
static Vector2 card_size = (Vector2) { CARD_WIDTH, CARD_HEIGHT }; 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" }; static char *month_english_abbr[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
void draw_card(Card *c) { void draw_card(Card *c, Texture2D *cards_texture) {
DrawRectangleV(c->position, card_size, c->selected ? RED : BLACK); int i_vert = c->index % 4;
DrawRectangle(c->position.x + CARD_BORDER, c->position.y + CARD_BORDER, card_size.x - (CARD_BORDER * 2), card_size.y - (CARD_BORDER * 2) , WHITE); int i_horiz = c->index / 4;
DrawText(month_english_abbr[c->month], c->position.x + CARD_BORDER + 2, c->position.y + CARD_BORDER + 2, 14, BLACK); int pos_vert = i_vert * 240;
switch (c->type) { int pos_horiz = i_horiz * 146;
case CHAFF:
break; DrawTexturePro(
case RIBBON: *cards_texture,
Color ribbon_color = RED; (Rectangle) { pos_horiz, pos_vert, 146, 240 },
if (c->ribbon_type == RIBBON_BLUE) ribbon_color = BLUE; (Rectangle) { c->position.x, c->position.y, card_size.x, card_size.y },
DrawRectangle(c->position.x + 26, c->position.y + 35, 10, 45 , ribbon_color); (Vector2) { 0, 0 },
if (c->ribbon_type == RIBBON_POETRY) { 0.,
DrawRectangle(c->position.x + 29, c->position.y + 38, 4, 39 , BLACK); RAYWHITE
} );
break; if (c->selected) {
case ANIMAL: DrawCircle(c->position.x + 10, c->position.y + 10, 10, BLUE);
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;
} }
} }

2
card.h
View File

@ -53,7 +53,7 @@ struct Hand {
int count; int count;
}; };
void draw_card(Card *c); void draw_card(Card *c, Texture2D *cards_texture);
bool point_within_card(Card *c, Vector2 v); bool point_within_card(Card *c, Vector2 v);
#endif #endif

6
main.c
View File

@ -16,6 +16,10 @@ int main(int argc, char** argv) {
InitWindow(800, 550, "Hanafuda Hachi-Hachi"); InitWindow(800, 550, "Hanafuda Hachi-Hachi");
SetTargetFPS(60); SetTargetFPS(60);
Image cards_image = LoadImage("img/cards.png");
Texture2D cards_texture = LoadTextureFromImage(cards_image);
UnloadImage(cards_image);
/* /*
Hand h; Hand h;
h.cards[0] = (Card) { 1, BRIGHT, RIBBON_NONE, NOVEMBER, (Vector2) { 0, 0 } }; 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; int num_selected = 0;
for (int i = 0; i < 48; i++) { for (int i = 0; i < 48; i++) {
num_selected += cards[i].selected; num_selected += cards[i].selected;
draw_card(&cards[i]); draw_card(&cards[i], &cards_texture);
} }
if (strlen(teyaku_calculation) == 0) { if (strlen(teyaku_calculation) == 0) {