Draw the cards

This commit is contained in:
Bill Rossi 2025-02-01 07:33:52 -05:00
parent 6375f1ec6f
commit ed32f6262d
3 changed files with 66 additions and 17 deletions

20
card.c
View File

@ -2,4 +2,24 @@
void draw_card(Card *c) {
DrawRectangleV(c->position, card_size, RED);
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;
}
}

3
card.h
View File

@ -8,6 +8,7 @@ typedef struct Card Card;
typedef struct Hand Hand;
#define CARD_WIDTH 63
#define CARD_HEIGHT 105
#define CARD_BORDER 5
static Vector2 card_size = (Vector2) { CARD_WIDTH, CARD_HEIGHT };
typedef enum CardType {
@ -39,6 +40,8 @@ typedef enum Month {
DECEMBER
} Month;
static char *month_english_abbr[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
struct Card {
int index;
CardType type;

60
main.c
View File

@ -15,6 +15,7 @@ int main(int argc, char** argv) {
InitWindow(800, 450, "Hanafuda Hachi-Hachi");
SetTargetFPS(60);
/*
Hand h;
h.cards[0] = (Card) { 1, BRIGHT, RIBBON_NONE, NOVEMBER, (Vector2) { 0, 0 } };
h.cards[1] = (Card) { 1, ANIMAL, RIBBON_NONE, NOVEMBER, (Vector2) { 0, 0 } };
@ -26,33 +27,58 @@ int main(int argc, char** argv) {
h.count = 7;
printf("Teyaku: %d\n", calculate_teyaku(h));
*/
Card *c = malloc(sizeof(Card));
c->position = (Vector2) { 200, 200 };
Move *m = malloc(sizeof(Move));
m->origin = c->position;
m->destination = c->position;
m->curve = CURVE_EASE_IN_OUT;
Card cards[48];
for (int i = 0; i < 48; i++) {
CardType t = CHAFF;
RibbonType rt = RIBBON_NONE;
Month month = i / 4;
switch (i) {
case 0:
case 8:
case 28:
case 40:
case 44:
t = BRIGHT; break;
case 1:
case 5:
case 9:
t = RIBBON; rt = RIBBON_POETRY; break;
case 21:
case 33:
case 37:
t = RIBBON; rt = RIBBON_BLUE; break;
case 13:
case 17:
case 25:
case 42:
t = RIBBON; rt = RIBBON_PLAIN; break;
case 4:
case 12:
case 16:
case 20:
case 24:
case 29:
case 32:
case 36:
case 41:
t = ANIMAL; break;
}
cards[i] = (Card) { i, t, rt, month, (Vector2) { month * 65, (i % 4) * 110 } };
}
float delta;
Vector2 mouse_position;
while (!WindowShouldClose()) {
delta = GetFrameTime();
if (IsMouseButtonPressed(0)) {
mouse_position = GetMousePosition();
m->origin = c->position;
m->destination = mouse_position;
m->current_time = 0.;
m->end_time = 1.;
}
c->position = move_position(m, delta);
BeginDrawing();
ClearBackground(RAYWHITE);
draw_card(c);
for (int i = 0; i < 48; i++) {
draw_card(&cards[i]);
}
EndDrawing();
}