diff --git a/graphics/joker_gfx10.grit b/graphics/joker_gfx10.grit new file mode 100644 index 0000000..a8ac3f6 --- /dev/null +++ b/graphics/joker_gfx10.grit @@ -0,0 +1 @@ +-gB4 -Mw4 -Mh4 -m! -pn 16 \ No newline at end of file diff --git a/graphics/joker_gfx10.png b/graphics/joker_gfx10.png new file mode 100644 index 0000000..aca51bc Binary files /dev/null and b/graphics/joker_gfx10.png differ diff --git a/graphics/joker_gfx11.grit b/graphics/joker_gfx11.grit new file mode 100644 index 0000000..a8ac3f6 --- /dev/null +++ b/graphics/joker_gfx11.grit @@ -0,0 +1 @@ +-gB4 -Mw4 -Mh4 -m! -pn 16 \ No newline at end of file diff --git a/graphics/joker_gfx11.png b/graphics/joker_gfx11.png new file mode 100644 index 0000000..07b537c Binary files /dev/null and b/graphics/joker_gfx11.png differ diff --git a/graphics/joker_gfx8.png b/graphics/joker_gfx8.png index 01dbbdd..eaf2fbc 100644 Binary files a/graphics/joker_gfx8.png and b/graphics/joker_gfx8.png differ diff --git a/graphics/joker_gfx9.grit b/graphics/joker_gfx9.grit new file mode 100644 index 0000000..a8ac3f6 --- /dev/null +++ b/graphics/joker_gfx9.grit @@ -0,0 +1 @@ +-gB4 -Mw4 -Mh4 -m! -pn 16 \ No newline at end of file diff --git a/graphics/joker_gfx9.png b/graphics/joker_gfx9.png new file mode 100644 index 0000000..298f796 Binary files /dev/null and b/graphics/joker_gfx9.png differ diff --git a/include/game.h b/include/game.h index 6fdaec1..55e8730 100644 --- a/include/game.h +++ b/include/game.h @@ -6,6 +6,8 @@ #define MAX_JOKERS_HELD_SIZE 5 // This doesn't account for negatives right now. #define MAX_SHOP_JOKERS 2 // TODO: Make this dynamic and allow for other items besides jokers #define MAX_SELECTION_SIZE 5 +#define MAX_CARD_SCORE_DIGITS 2 // Current digit limit for score received from cards including mult etc. from jokers +#define MAX_CARD_SCORE_STR_LEN (MAX_CARD_SCORE_DIGITS + 1) // For the '+' or 'X' #define FRAMES(x) (((x) + game_speed - 1) / game_speed) // TODO: Turn into enum? @@ -77,9 +79,12 @@ typedef struct CardObject CardObject; // forward declaration, actually declared typedef struct JokerObject JokerObject; CardObject** get_hand_array(void); int get_hand_top(void); +int hand_get_size(void); CardObject** get_played_array(void); int get_played_top(void); JokerObject** get_jokers(void); int get_jokers_top(void); +int get_num_discards_remaining(void); + #endif // GAME_H \ No newline at end of file diff --git a/include/graphic_utils.h b/include/graphic_utils.h index 6c169c7..2791791 100644 --- a/include/graphic_utils.h +++ b/include/graphic_utils.h @@ -43,6 +43,9 @@ // Tile size in pixels, both height and width as tiles are square #define TILE_SIZE 8 +// By default TTE characters occupy a single tile +#define TTE_CHAR_SIZE TILE_SIZE + typedef struct { int left; diff --git a/include/joker_gfx.h b/include/joker_gfx.h index 92c3edc..75cfbbc 100644 --- a/include/joker_gfx.h +++ b/include/joker_gfx.h @@ -10,5 +10,8 @@ #include "joker_gfx6.h" #include "joker_gfx7.h" #include "joker_gfx8.h" +#include "joker_gfx9.h" +#include "joker_gfx10.h" +#include "joker_gfx11.h" #endif \ No newline at end of file diff --git a/include/util.h b/include/util.h index 5b3160e..7d9b915 100644 --- a/include/util.h +++ b/include/util.h @@ -37,6 +37,8 @@ static inline int get_digits_even(int n) #define NUM_ELEM_IN_ARR(arr) (sizeof(arr) / sizeof((arr)[0])) +#define INT_MAX_DIGITS 10 // strlen(str(INT_MAX)) = strlen("2147483647") + int int_arr_max(int int_arr[], int size); #endif // UTIL_H \ No newline at end of file diff --git a/source/game.c b/source/game.c index 6fbb685..8acd864 100644 --- a/source/game.c +++ b/source/game.c @@ -148,6 +148,11 @@ int get_hand_top(void) { return hand_top; } +int hand_get_size(void) +{ + return hand_top + 1; +} + CardObject **get_played_array(void) { return played; } @@ -239,6 +244,10 @@ static const Rect SHOP_REROLL_RECT = {88, 96, UNDEFINED, UNDEFI #define PITCH_STEP_UNDISCARD_SFX 2*PITCH_STEP_DRAW_SFX // Naming the stage where cards return from the discard pile to the deck "undiscard" +int get_num_discards_remaining(void) { + return discards; +} + // General functions void set_seed(int seed) { @@ -849,11 +858,6 @@ void hand_change_sort() sort_cards(); } -int hand_get_size() -{ - return hand_top + 1; -} - int hand_get_max_size() { return hand_size; @@ -1615,7 +1619,7 @@ static void played_cards_update_loop(bool* discarded_card, int* played_selection tte_set_special(0xD000); // Set text color to blue from background memory // Write the score to a character buffer variable - char score_buffer[5]; // Assuming the maximum score is 99, we need 4 characters (2 digits + null terminator) + char score_buffer[INT_MAX_DIGITS + 2]; // for '+' and null terminator snprintf(score_buffer, sizeof(score_buffer), "+%d", card_get_value(played[j]->card)); tte_write(score_buffer); diff --git a/source/joker.c b/source/joker.c index de376b0..6b30061 100644 --- a/source/joker.c +++ b/source/joker.c @@ -127,6 +127,9 @@ void joker_init() joker_gfxTiles[6] = joker_gfx6Tiles; joker_gfxTiles[7] = joker_gfx7Tiles; joker_gfxTiles[8] = joker_gfx8Tiles; + joker_gfxTiles[9] = joker_gfx9Tiles; + joker_gfxTiles[10] = joker_gfx10Tiles; + joker_gfxTiles[11] = joker_gfx11Tiles; joker_gfxPal[0] = joker_gfx0Pal; joker_gfxPal[1] = joker_gfx1Pal; @@ -137,6 +140,9 @@ void joker_init() joker_gfxPal[6] = joker_gfx6Pal; joker_gfxPal[7] = joker_gfx7Pal; joker_gfxPal[8] = joker_gfx8Pal; + joker_gfxPal[9] = joker_gfx9Pal; + joker_gfxPal[10] = joker_gfx10Pal; + joker_gfxPal[11] = joker_gfx11Pal; for (int i = 0; i < num_spritesheets; i++) { @@ -264,33 +270,47 @@ bool joker_object_score(JokerObject *joker_object, Card* scored_card, int *chips *money += joker_effect.money; // TODO: Retrigger - tte_set_pos(fx2int(joker_object->sprite_object->x) + 8, JOKER_SCORE_TEXT_Y); // Offset of 16 pixels to center the text on the card - - char score_buffer[12]; + const int joker_score_display_offset_px = (MAX_CARD_SCORE_STR_LEN + 1)*TTE_CHAR_SIZE; + // + 1 For space + int cursorPosX = fx2int(joker_object->sprite_object->x) + 8; // Offset of 16 pixels to center the text on the card if (joker_effect.chips > 0) { + char score_buffer[INT_MAX_DIGITS + 2]; // For '+' and null terminator + tte_set_pos(cursorPosX, JOKER_SCORE_TEXT_Y); tte_set_special(0xD000); // Blue snprintf(score_buffer, sizeof(score_buffer), "+%d", joker_effect.chips); + tte_write(score_buffer); + cursorPosX += joker_score_display_offset_px; } - else if (joker_effect.mult > 0) + if (joker_effect.mult > 0) { + char score_buffer[INT_MAX_DIGITS + 2]; + tte_set_pos(cursorPosX, JOKER_SCORE_TEXT_Y); tte_set_special(0xE000); // Red snprintf(score_buffer, sizeof(score_buffer), "+%d", joker_effect.mult); + tte_write(score_buffer); + cursorPosX += joker_score_display_offset_px; } - else if (joker_effect.xmult > 0) + if (joker_effect.xmult > 0) { + char score_buffer[INT_MAX_DIGITS + 2]; + tte_set_pos(cursorPosX, JOKER_SCORE_TEXT_Y); tte_set_special(0xE000); // Red snprintf(score_buffer, sizeof(score_buffer), "X%d", joker_effect.xmult); + tte_write(score_buffer); + cursorPosX += joker_score_display_offset_px; } - else if (joker_effect.money > 0) + if (joker_effect.money > 0) { + char score_buffer[INT_MAX_DIGITS + 2]; + tte_set_pos(cursorPosX, JOKER_SCORE_TEXT_Y); tte_set_special(0xC000); // Yellow snprintf(score_buffer, sizeof(score_buffer), "+%d", joker_effect.money); + tte_write(score_buffer); + cursorPosX += joker_score_display_offset_px; } - tte_write(score_buffer); - joker_object->joker->processed = true; // Mark the joker as processed joker_object_shake(joker_object, SFX_CARD_SELECT); // TODO: Add a sound effect for scoring the joker diff --git a/source/joker_effects.c b/source/joker_effects.c index 5e934ee..bab4512 100644 --- a/source/joker_effects.c +++ b/source/joker_effects.c @@ -1,3 +1,4 @@ +#include "game.h" #include "joker.h" #include "util.h" #include "hand_analysis.h" @@ -178,7 +179,8 @@ static JokerEffect half_joker_effect(Joker *joker, Card *scored_card) { if (scored_card != NULL) return effect; // if card != null, we are not at the end-phase of scoring yet - if (get_played_top() + 1 <= 3) // game.c has hand_get_size() but it's not accesible here + int played_size = get_played_top() + 1; + if (played_size <= 3) effect.mult = 20; return effect; @@ -190,12 +192,13 @@ static JokerEffect joker_stencil_effect(Joker *joker, Card *scored_card) { return effect; // if card != null, we are not at the end-phase of scoring yet // +1 xmult per empty joker slot... - int jokers_top = get_jokers_top(); - effect.xmult = (MAX_JOKERS_HELD_SIZE-1) - jokers_top; + int num_jokers = get_jokers_top() + 1; + + effect.xmult = (MAX_JOKERS_HELD_SIZE) - num_jokers; // ...and also each stencil_joker adds +1 xmult JokerObject** jokers = get_jokers(); - for (int i = 0; i < jokers_top; i++ ) + for (int i = 0; i < num_jokers; i++ ) { if (jokers[i]->joker->id == JOKER_STENCIL_ID) effect.xmult++; @@ -215,6 +218,78 @@ static JokerEffect misprint_joker_effect(Joker *joker, Card *scored_card) { return effect; } +static JokerEffect walkie_talkie_joker_effect(Joker *joker, Card *scored_card) { + JokerEffect effect = {0}; + if (scored_card == NULL) + return effect; + + if (scored_card->rank == TEN || scored_card->rank == FOUR) { + effect.chips = 10; + effect.mult = 4; + } + + return effect; +} + +static JokerEffect fibonnaci_joker_effect(Joker *joker, Card *scored_card) { + JokerEffect effect = {0}; + if (scored_card == NULL) + return effect; + + switch (scored_card->rank) { + case ACE: case TWO: case THREE: case FIVE: case EIGHT: + effect.mult = 8; + default: + break; + } + + return effect; +} + +static JokerEffect banner_joker_effect(Joker *joker, Card *scored_card) { + JokerEffect effect = {0}; + if (scored_card != NULL) + return effect; // if card != null, we are not at the end-phase of scoring yet + + effect.chips = 30 * get_num_discards_remaining(); + + return effect; +} + +static JokerEffect mystic_summit_joker_effect(Joker *joker, Card *scored_card) { + JokerEffect effect = {0}; + if (scored_card != NULL) + return effect; // if card != null, we are not at the end-phase of scoring yet + + if (get_num_discards_remaining() == 0) + effect.mult = 15; + + return effect; +} + +static JokerEffect blackboard_joker_effect(Joker *joker, Card *scored_card) { + JokerEffect effect = {0}; + if (scored_card != NULL) + return effect; // if card != null, we are not at the end-phase of scoring yet + + bool all_cards_are_spades_or_clubs = true; + CardObject** hand = get_hand_array(); + int hand_size = hand_get_size(); + for (int i = 0; i < hand_size; i++ ) + { + u8 suit = hand[i]->card->suit; + if (suit == HEARTS || suit == DIAMONDS) { + all_cards_are_spades_or_clubs = false; + break; + } + } + + if (all_cards_are_spades_or_clubs) + effect.xmult = 3; + + return effect; +} + const JokerInfo joker_registry[] = { { COMMON_JOKER, 2, default_joker_effect }, // DEFAULT_JOKER_ID = 0 { COMMON_JOKER, 5, greedy_joker_effect }, // GREEDY_JOKER_ID = 1 @@ -233,6 +308,11 @@ const JokerInfo joker_registry[] = { { COMMON_JOKER, 4, crafty_joker_effect }, { COMMON_JOKER, 5, half_joker_effect }, { UNCOMMON_JOKER, 8, joker_stencil_effect }, + { COMMON_JOKER, 5, banner_joker_effect }, + { COMMON_JOKER, 4, walkie_talkie_joker_effect }, + { UNCOMMON_JOKER, 8, fibonnaci_joker_effect }, + { UNCOMMON_JOKER, 6, blackboard_joker_effect }, + { COMMON_JOKER, 5, mystic_summit_joker_effect }, { COMMON_JOKER, 4, misprint_joker_effect }, };