functional basic gameplay

This commit is contained in:
cellos51
2025-06-12 01:44:54 -04:00
parent af27a26cdd
commit 5055c9abc7
3 changed files with 96 additions and 51 deletions
+5
View File
@@ -86,6 +86,7 @@ typedef struct
// Card methods // Card methods
Card *card_new(u8 suit, u8 rank); Card *card_new(u8 suit, u8 rank);
void card_destroy(Card **card); void card_destroy(Card **card);
u8 card_get_value(Card *card);
// CardObject methods // CardObject methods
CardObject *card_object_new(Card *card); CardObject *card_object_new(Card *card);
@@ -107,6 +108,10 @@ enum HandState hand_get_state(); // This gets the current state of the hand
bool hand_discard(); // This discards the selected cards bool hand_discard(); // This discards the selected cards
bool hand_play(); // This plays the selected cards bool hand_play(); // This plays the selected cards
// Play functions
enum PlayState play_get_state(); // This gets the current state of the play
Card *play_get_scored_card(); // This gets the card that was scored in the last play
// Deck functions // Deck functions
int deck_get_size(); // This gets the size of the deck int deck_get_size(); // This gets the size of the deck
int deck_get_max_size(); // This gets the maximum size of the deck (this doesn't get the array max, it gets the total amount of cards that you have) int deck_get_max_size(); // This gets the maximum size of the deck (this doesn't get the array max, it gets the total amount of cards that you have)
+18
View File
@@ -26,6 +26,7 @@ static enum HandType hand_type = NONE;
static CardObject *played[MAX_SELECTION_SIZE] = {NULL}; static CardObject *played[MAX_SELECTION_SIZE] = {NULL};
static CardObject *hand[MAX_HAND_SIZE] = {NULL}; static CardObject *hand[MAX_HAND_SIZE] = {NULL};
static Card *deck[MAX_DECK_SIZE] = {NULL}; static Card *deck[MAX_DECK_SIZE] = {NULL};
static Card *scored_card = NULL;
static int played_top = -1; static int played_top = -1;
static int hand_top = -1; static int hand_top = -1;
@@ -587,6 +588,8 @@ void card_update() // This whole function is currently pretty unoptimized due to
mm_sound_effect sfx_select = {{SFX_CARD_SELECT}, 1024, 0, 255, 128,}; mm_sound_effect sfx_select = {{SFX_CARD_SELECT}, 1024, 0, 255, 128,};
mmEffectEx(&sfx_select); mmEffectEx(&sfx_select);
scored_card = played[played_top - j]->card; // Set the scored card to the one that was just scored. This allows us to get the value of the card later in game.c
break; break;
} }
} }
@@ -597,6 +600,7 @@ void card_update() // This whole function is currently pretty unoptimized due to
play_state = PLAY_ENDING; play_state = PLAY_ENDING;
timer = 1; timer = 1;
played_selections = played_top + 1; // Reset the played selections to the top of the played stack played_selections = played_top + 1; // Reset the played selections to the top of the played stack
scored_card = NULL; // Reset the scored card
break; break;
} }
} }
@@ -918,6 +922,20 @@ bool hand_play()
return true; return true;
} }
// Play functions
enum PlayState play_get_state()
{
return play_state;
}
Card *play_get_scored_card()
{
// Return value and set old reference to NULL
Card *scored_card_temp = scored_card;
scored_card = NULL; // Reset the scored card so it doesn't get returned again
return scored_card_temp;
}
// Deck functions // Deck functions
int deck_get_size() int deck_get_size()
{ {
+73 -51
View File
@@ -14,6 +14,8 @@
static int hand = 4; static int hand = 4;
static int discard = 4; static int discard = 4;
static int score = 0;
static int temp_score = 0; // This is the score that shows in the same spot as the hand type.
static int chips = 0; static int chips = 0;
static int mult = 0; static int mult = 0;
@@ -29,56 +31,46 @@ void change_background(int id)
{ {
memcpy(&se_mem[30][0], background_gfxMap, background_gfxMapLen); memcpy(&se_mem[30][0], background_gfxMap, background_gfxMapLen);
// tte_printf("#{P:128,128; cx:0}%d/%d", hand_get_size(), hand_get_max_size()); // Hand size/max size
// tte_printf("#{P:200,152}%d/%d", deck_get_size(), deck_get_max_size()); // Deck size/max size
// tte_printf("#{P:32,48;}*%d", 0); // Score
// tte_printf("#{P:24,80;}%d", 0); // Chips
// tte_printf("#{P:40,80;}%d", 0); // Mult
// tte_printf("#{P:16,104; cx:0x2000}%d", hand); // Hand
// tte_printf("#{P:48,104; cx:0x3000}%d", discard); // Discard
// tte_printf("#{P:24,120; cx:0x1000}$%d", 4); // Money
// tte_printf("#{P:48,144}%d", 1); // Round
// tte_printf("#{P:8,144}%d#{cx:0}/%d", 1, 8); // Ante
tte_erase_rect(128, 152, 152, 160); tte_erase_rect(128, 152, 152, 160);
} }
else if (id == 2) // playing else if (id == 2) // playing
{ {
memcpy(&se_mem[30][0], background_play_gfxMap, background_play_gfxMapLen); memcpy(&se_mem[30][0], background_play_gfxMap, background_play_gfxMapLen);
// tte_printf("#{P:128,128; cx:0}%d/%d", hand_get_size(), hand_get_max_size()); // Hand size/max size
// tte_printf("#{P:200,152}%d/%d", deck_get_size(), deck_get_max_size()); // Deck size/max size
// tte_printf("#{P:32,48;}*%d", 0); // Score
// tte_printf("#{P:24,80;}%d", 0); // Chips
// tte_printf("#{P:40,80;}%d", 0); // Mult
// tte_printf("#{P:16,104; cx:0x2000}%d", hand); // Hand
// tte_printf("#{P:48,104; cx:0x3000}%d", discard); // Discard
// tte_printf("#{P:24,120; cx:0x1000}$%d", 4); // Money
// tte_printf("#{P:48,144}%d", 1); // Round
// tte_printf("#{P:8,144}%d#{cx:0}/%d", 1, 8); // Ante
tte_erase_rect(128, 128, 152, 136); tte_erase_rect(128, 128, 152, 136);
} }
background = id; background = id;
} }
void set_chips()
{
tte_erase_rect(8, 80, 32, 88);
if (chips < 10)
{
tte_printf("#{cx:0; P:24,80;}%d", chips); // Chips
}
else if (chips < 100)
{
tte_printf("#{cx:0; P:16,80;}%d", chips);
}
else
{
tte_printf("#{cx:0; P:8,80;}%d", chips);
}
}
void set_mult()
{
tte_erase_rect(40, 80, 64, 88);
tte_printf("#{cx:0; P:40,80;}%d", mult); // Mult
}
void set_hand() void set_hand()
{ {
tte_erase_rect(8, 64, 64, 72); tte_erase_rect(8, 64, 64, 72); // Hand type
tte_erase_rect(8, 80, 32, 88);
tte_erase_rect(40, 80, 64, 88);
switch (hand_get_type()) switch (hand_get_type())
{ {
@@ -153,20 +145,8 @@ void set_hand()
break; break;
} }
if (chips < 10) set_chips();
{ set_mult();
tte_printf("#{P:24,80;}%d", chips); // Chips
}
else if (chips < 100)
{
tte_printf("#{P:16,80;}%d", chips);
}
else
{
tte_printf("#{P:8,80;}%d", chips);
}
tte_printf("#{P:40,80;}%d", mult); // Mult
} }
void game_init() void game_init()
@@ -228,7 +208,6 @@ void game_update()
set_hand(); set_hand();
discard--; discard--;
tte_printf("#{P:48,104; cx:0x3000}%d", discard); tte_printf("#{P:48,104; cx:0x3000}%d", discard);
} }
if (key_hit(KEY_START) && hand > 0 && hand_play()) if (key_hit(KEY_START) && hand > 0 && hand_play())
@@ -237,6 +216,49 @@ void game_update()
tte_printf("#{P:16,104; cx:0x2000}%d", hand); tte_printf("#{P:16,104; cx:0x2000}%d", hand);
} }
} }
else if (play_get_state() == PLAY_SCORING)
{
Card *scored_card = play_get_scored_card();
if (scored_card != NULL)
{
chips += card_get_value(scored_card);
set_chips();
}
}
else if (play_get_state() == PLAY_ENDING)
{
if (mult > 0)
{
temp_score = chips * mult;
tte_erase_rect(8, 64, 64, 72);
tte_printf("#{P:8,64;}%d", temp_score); // Score
chips = 0;
mult = 0;
set_mult();
set_chips();
}
}
else if (play_get_state() == PLAY_ENDED)
{
if (temp_score > 0)
{
score += temp_score;
temp_score = 0;
tte_erase_rect(8, 64, 64, 72);
tte_printf("#{P:8,64;}%d", temp_score); // Score
tte_erase_rect(32, 48, 64, 56);
tte_printf("#{P:32,48;}%d", score); // Score
if (temp_score <= 0)
{
tte_erase_rect(8, 64, 64, 72);
}
}
}
static int last_hand_size = 0; static int last_hand_size = 0;
static int last_deck_size = 0; static int last_deck_size = 0;