From feab2ebb1fa1ba5b03b0bf96fe898b4488e70019 Mon Sep 17 00:00:00 2001 From: Bill Rossi Date: Sun, 23 Feb 2025 17:28:13 -0500 Subject: [PATCH] Fix different card colors --- card.c | 4 ++-- card.h | 2 +- game.c | 17 ++++++++++------- game.h | 2 +- main.c | 1 - 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/card.c b/card.c index 148b44c..1c417be 100644 --- a/card.c +++ b/card.c @@ -6,7 +6,7 @@ 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" }; Color BRICKRED = (Color) { 136, 12, 2, 255 }; -void draw_card(Card *c, Texture2D **cards_texture, int index) { +void draw_card(Card *c, Texture2D *cards_texture, int index) { int i_vert = c->index % 4; int i_horiz = c->index / 4; int pos_vert = i_vert * CARD_HEIGHT; @@ -16,7 +16,7 @@ void draw_card(Card *c, Texture2D **cards_texture, int index) { if (c->visible) { DrawTexturePro( - *cards_texture[index ? 1 : 0], + *cards_texture, (Rectangle) { pos_horiz, pos_vert, CARD_WIDTH, CARD_HEIGHT }, (Rectangle) { c->position.x, c->position.y, card_size.x, card_size.y }, (Vector2) { 0, 0 }, diff --git a/card.h b/card.h index f57bfbf..23db92f 100644 --- a/card.h +++ b/card.h @@ -73,7 +73,7 @@ struct Hand { HandDisplayType display_type; }; -void draw_card(Card *c, Texture2D **cards_texture, int index); +void draw_card(Card *c, Texture2D *cards_texture, int index); bool point_within_card(Card *c, Vector2 v); void shuffle_hand(Hand *h); void deal(Hand *from, Hand *to, int count, bool up, float deal_speed); diff --git a/game.c b/game.c index 73ce60c..30dc347 100644 --- a/game.c +++ b/game.c @@ -15,13 +15,12 @@ Vector2 mouse_pos; char teyaku_calculation[400]; void initialize_game(Game *g) { - g->cards_texture = malloc(2 * sizeof(Texture)); Image cards_image_red = LoadImage("img/cards_red.png"); - g->cards_texture[0] = LoadTextureFromImage(cards_image_red); + g->cards_texture_red = LoadTextureFromImage(cards_image_red); UnloadImage(cards_image_red); Image cards_image_black = LoadImage("img/cards_black.png"); - g->cards_texture[1] = LoadTextureFromImage(cards_image_black); + g->cards_texture_black = LoadTextureFromImage(cards_image_black); UnloadImage(cards_image_black); g->deck.count = 0; @@ -840,13 +839,17 @@ void run_frame(Game *g) { } } +Texture *cards_texture(Game *g) { + return g->black_card_backs ? &g->cards_texture_black : &g->cards_texture_red; +} + void draw_player_cards(Game *g, Player *p) { for (int i = 0; i < p->hand.count; i++) { - draw_card(p->hand.cards[i], &g->cards_texture, g->black_card_backs); + draw_card(p->hand.cards[i], cards_texture(g), g->black_card_backs); } for (int i = 0; i < p->scored.count; i++) { - draw_card(p->scored.cards[i], &g->cards_texture, g->black_card_backs); + draw_card(p->scored.cards[i], cards_texture(g), g->black_card_backs); } } @@ -855,11 +858,11 @@ void draw_cards(Game *g) { draw_player_cards(g, &g->right); draw_player_cards(g, &g->left); for (int i = 0; i < g->field.count; i++) { - draw_card(g->field.cards[i], &g->cards_texture, g->black_card_backs); + draw_card(g->field.cards[i], cards_texture(g), g->black_card_backs); } for (int i = 0; i < g->deck.count; i++) { - draw_card(g->deck.cards[i], &g->cards_texture, g->black_card_backs); + draw_card(g->deck.cards[i], cards_texture(g), g->black_card_backs); } } diff --git a/game.h b/game.h index 44ccc15..0d6be42 100644 --- a/game.h +++ b/game.h @@ -41,7 +41,7 @@ struct Game { GameState state; bool should_close; Card cards[48]; - Texture2D *cards_texture; + Texture2D cards_texture_red, cards_texture_black; Hand deck, field; FieldMultiplier *field_multiplier; Card *current_play_from_hand, *current_play_target; diff --git a/main.c b/main.c index 69404e0..0d8d2a3 100644 --- a/main.c +++ b/main.c @@ -9,7 +9,6 @@ #include "game.h" char *text = "こんにちわ、 世界!"; -Texture2D cards_texture; int main(int argc, char** argv) { srand(time(NULL));