Fix some spacing and some layout

This commit is contained in:
Bill Rossi 2025-02-05 21:19:05 -05:00
parent 417544321c
commit 9701cc9e61
4 changed files with 33 additions and 13 deletions

12
card.c
View File

@ -45,16 +45,26 @@ void shuffle_hand(Hand *h) {
} }
void add_to_hand(Hand *h, Card *c) { void add_to_hand(Hand *h, Card *c) {
h->cards[h->count++] = c; h->cards[h->count] = c;
c->move.position = &c->position; c->move.position = &c->position;
c->move.origin.x = c->position.x; c->move.origin.x = c->position.x;
c->move.origin.y = c->position.y; c->move.origin.y = c->position.y;
switch (h->display_type) {
case HAND_DISPLAY_ROW:
c->move.destination.x = h->position.x + (h->count * (CARD_WIDTH + 10)); c->move.destination.x = h->position.x + (h->count * (CARD_WIDTH + 10));
c->move.destination.y = h->position.y; c->move.destination.y = h->position.y;
break;
case HAND_DISPLAY_FIELD:
c->move.destination.x = h->position.x + ((h->count / 2) * (CARD_WIDTH + 10));
c->move.destination.y = h->position.y + (h->count % 2 * (CARD_HEIGHT + 10));
break;
}
c->move.curve = CURVE_EASE_IN_OUT; c->move.curve = CURVE_EASE_IN_OUT;
c->move.current_time = 0.; c->move.current_time = 0.;
c->move.end_time = 0.5; c->move.end_time = 0.5;
h->count++;
} }
bool card_done_moving(Card *c) { bool card_done_moving(Card *c) {

6
card.h
View File

@ -58,10 +58,16 @@ struct Card {
Move move; Move move;
}; };
typedef enum HandDisplayType {
HAND_DISPLAY_ROW,
HAND_DISPLAY_FIELD,
} HandDisplayType;
struct Hand { struct Hand {
Card *cards[48]; Card *cards[48];
int count; int count;
Vector2 position; Vector2 position;
HandDisplayType display_type;
}; };
void draw_card(Card *c, Texture2D *cards_texture); void draw_card(Card *c, Texture2D *cards_texture);

22
game.c
View File

@ -56,7 +56,7 @@ void initialize_game(Game *g) {
g->cards[i] = (Card) { i, t, rt, month, { 800, 100 }, false, false }; g->cards[i] = (Card) { i, t, rt, month, { 800, 100 }, false, false };
g->cards[i].move.end_time = 0.; g->cards[i].move.end_time = 0.;
g->cards[i].move.position = &g->cards[i].position; g->cards[i].move.position = &g->cards[i].position;
g->cards[i].move.destination = (Vector2) { 800, 200 }; g->cards[i].move.destination = (Vector2) { 800, 300 };
g->deck.cards[i] = &g->cards[i]; g->deck.cards[i] = &g->cards[i];
g->deck.count++; g->deck.count++;
} }
@ -64,13 +64,17 @@ void initialize_game(Game *g) {
shuffle_hand(&g->deck); shuffle_hand(&g->deck);
g->player_hand.count = 0; g->player_hand.count = 0;
g->player_hand.position = (Vector2) { 20, 475 }; g->player_hand.position = (Vector2) { 300, 550 };
g->player_hand.display_type = HAND_DISPLAY_ROW;
g->right_hand.count = 0; g->right_hand.count = 0;
g->right_hand.position = (Vector2) { 20, 100 }; g->right_hand.position = (Vector2) { 20, 100 };
g->right_hand.display_type = HAND_DISPLAY_ROW;
g->left_hand.count = 0; g->left_hand.count = 0;
g->left_hand.position = (Vector2) { 20, 225 }; g->left_hand.position = (Vector2) { 600, 100 };
g->left_hand.display_type = HAND_DISPLAY_ROW;
g->field.count = 0; g->field.count = 0;
g->field.position = (Vector2) { 20, 350 }; g->field.position = (Vector2) { 400, 250 };
g->field.display_type = HAND_DISPLAY_FIELD;
strcpy(teyaku_calculation, ""); strcpy(teyaku_calculation, "");
@ -119,18 +123,18 @@ void run_calculation(Game *g) {
void run_frame_dealing(Game *g) { void run_frame_dealing(Game *g) {
if (g->player_hand.count < 4) { if (g->player_hand.count < 4) {
deal(&g->deck, &g->player_hand, 4, true); deal(&g->deck, &g->player_hand, 4, true);
} else if (g->right_hand.count < 4) {
deal(&g->deck, &g->right_hand, 4, false);
} else if (g->left_hand.count < 4) { } else if (g->left_hand.count < 4) {
deal(&g->deck, &g->left_hand, 4, false); deal(&g->deck, &g->left_hand, 4, false);
} else if (g->right_hand.count < 4) {
deal(&g->deck, &g->right_hand, 4, false);
} else if (g->field.count < 3) { } else if (g->field.count < 3) {
deal(&g->deck, &g->field, 3, true); deal(&g->deck, &g->field, 3, true);
} else if (g->player_hand.count < 7) { } else if (g->player_hand.count < 7) {
deal(&g->deck, &g->player_hand, 3, true); deal(&g->deck, &g->player_hand, 3, true);
} else if (g->right_hand.count < 7) {
deal(&g->deck, &g->right_hand, 3, false);
} else if (g->left_hand.count < 7) { } else if (g->left_hand.count < 7) {
deal(&g->deck, &g->left_hand, 3, false); deal(&g->deck, &g->left_hand, 3, false);
} else if (g->right_hand.count < 7) {
deal(&g->deck, &g->right_hand, 3, false);
} else if (g->field.count < 6) { } else if (g->field.count < 6) {
deal(&g->deck, &g->field, 3, true); deal(&g->deck, &g->field, 3, true);
} else { } else {
@ -182,7 +186,7 @@ void draw_frame(Game *g) {
draw_card(&g->cards[i], &g->cards_texture); draw_card(&g->cards[i], &g->cards_texture);
} }
if (g->field_multiplier) DrawText(g->field_multiplier->name, 600, 385, 40, BLACK); if (g->field_multiplier) DrawText(g->field_multiplier->name, 60, 385, 40, BLACK);
if (g->player_teyaku.calculated) { if (g->player_teyaku.calculated) {
char s[200]; char s[200];
teyaku_to_string(&g->player_teyaku, s); teyaku_to_string(&g->player_teyaku, s);

2
main.c
View File

@ -13,7 +13,7 @@ Texture2D cards_texture;
int main(int argc, char** argv) { int main(int argc, char** argv) {
srand(time(NULL)); srand(time(NULL));
InitWindow(900, 600, "Hanafuda Hachi-Hachi"); InitWindow(1200, 700, "Hanafuda Hachi-Hachi");
SetTargetFPS(60); SetTargetFPS(60);
Game g; Game g;