Draw the cards
This commit is contained in:
parent
6375f1ec6f
commit
ed32f6262d
20
card.c
20
card.c
@ -2,4 +2,24 @@
|
|||||||
|
|
||||||
void draw_card(Card *c) {
|
void draw_card(Card *c) {
|
||||||
DrawRectangleV(c->position, card_size, RED);
|
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
3
card.h
@ -8,6 +8,7 @@ typedef struct Card Card;
|
|||||||
typedef struct Hand Hand;
|
typedef struct Hand Hand;
|
||||||
#define CARD_WIDTH 63
|
#define CARD_WIDTH 63
|
||||||
#define CARD_HEIGHT 105
|
#define CARD_HEIGHT 105
|
||||||
|
#define CARD_BORDER 5
|
||||||
static Vector2 card_size = (Vector2) { CARD_WIDTH, CARD_HEIGHT };
|
static Vector2 card_size = (Vector2) { CARD_WIDTH, CARD_HEIGHT };
|
||||||
|
|
||||||
typedef enum CardType {
|
typedef enum CardType {
|
||||||
@ -39,6 +40,8 @@ typedef enum Month {
|
|||||||
DECEMBER
|
DECEMBER
|
||||||
} Month;
|
} Month;
|
||||||
|
|
||||||
|
static char *month_english_abbr[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
|
||||||
|
|
||||||
struct Card {
|
struct Card {
|
||||||
int index;
|
int index;
|
||||||
CardType type;
|
CardType type;
|
||||||
|
60
main.c
60
main.c
@ -15,6 +15,7 @@ int main(int argc, char** argv) {
|
|||||||
InitWindow(800, 450, "Hanafuda Hachi-Hachi");
|
InitWindow(800, 450, "Hanafuda Hachi-Hachi");
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
|
/*
|
||||||
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 } };
|
||||||
h.cards[1] = (Card) { 1, ANIMAL, 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;
|
h.count = 7;
|
||||||
|
|
||||||
printf("Teyaku: %d\n", calculate_teyaku(h));
|
printf("Teyaku: %d\n", calculate_teyaku(h));
|
||||||
|
*/
|
||||||
|
|
||||||
Card *c = malloc(sizeof(Card));
|
Card cards[48];
|
||||||
c->position = (Vector2) { 200, 200 };
|
for (int i = 0; i < 48; i++) {
|
||||||
|
CardType t = CHAFF;
|
||||||
Move *m = malloc(sizeof(Move));
|
RibbonType rt = RIBBON_NONE;
|
||||||
m->origin = c->position;
|
Month month = i / 4;
|
||||||
m->destination = c->position;
|
switch (i) {
|
||||||
m->curve = CURVE_EASE_IN_OUT;
|
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;
|
float delta;
|
||||||
Vector2 mouse_position;
|
Vector2 mouse_position;
|
||||||
|
|
||||||
while (!WindowShouldClose()) {
|
while (!WindowShouldClose()) {
|
||||||
delta = GetFrameTime();
|
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();
|
BeginDrawing();
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
draw_card(c);
|
for (int i = 0; i < 48; i++) {
|
||||||
|
draw_card(&cards[i]);
|
||||||
|
}
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user