From dbff88add0518e9ecdb49eb3bf6b472b3d10351e Mon Sep 17 00:00:00 2001 From: theturtlemafia Date: Fri, 1 Aug 2025 10:38:31 -0400 Subject: [PATCH 1/7] Adds XMult, Joker Stencil and Misprint (rebase) --- include/game.h | 11 +++++++---- include/joker.h | 2 +- source/game.c | 43 ++++++++++++++++++++++++++---------------- source/joker.c | 7 ++++++- source/joker_effects.c | 34 +++++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 22 deletions(-) diff --git a/include/game.h b/include/game.h index ed77467..6fdaec1 100644 --- a/include/game.h +++ b/include/game.h @@ -74,9 +74,12 @@ void game_update(); // Utility functions for other files typedef struct CardObject CardObject; // forward declaration, actually declared in card.h -CardObject **get_hand_array(void); -CardObject **get_played_array(void); -int get_hand_top(void); -int get_played_top(void); +typedef struct JokerObject JokerObject; +CardObject** get_hand_array(void); +int get_hand_top(void); +CardObject** get_played_array(void); +int get_played_top(void); +JokerObject** get_jokers(void); +int get_jokers_top(void); #endif // GAME_H \ No newline at end of file diff --git a/include/joker.h b/include/joker.h index a869ed5..a428f25 100644 --- a/include/joker.h +++ b/include/joker.h @@ -39,7 +39,7 @@ typedef struct bool processed; } Joker; -typedef struct // copy of CardObject in card.h +typedef struct JokerObject // copy of CardObject in card.h { Joker *joker; SpriteObject* sprite_object; diff --git a/source/game.c b/source/game.c index 6f3d8de..9323660 100644 --- a/source/game.c +++ b/source/game.c @@ -214,6 +214,31 @@ 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" +// get-functions, for other files to view game state (mainly for jokers) +CardObject **get_hand_array(void) { + return hand; +} + +int get_hand_top(void) { + return hand_top; +} + +CardObject **get_played_array(void) { + return played; +} + +int get_played_top(void) { + return played_top; +} + +JokerObject **get_jokers(void) { + return jokers; +} + +int get_jokers_top(void) { + return jokers_top; +} + // General functions void set_seed(int seed) { @@ -290,22 +315,6 @@ void sort_cards() } } -CardObject **get_hand_array(void) { - return hand; -} - -int get_hand_top(void) { - return hand_top; -} - -CardObject **get_played_array(void) { - return played; -} - -int get_played_top(void) { - return played_top; -} - enum HandType hand_get_type() { enum HandType res_hand_type = NONE; @@ -1813,6 +1822,8 @@ static void game_shop_create_items(JokerObject *shop_jokers[], bool first_time) } u8 joker_id = random() % get_joker_registry_size(); + // TODO: don't pick a joker that we already own + // TODO: weight the random choice by joker rarity shop_jokers[i] = joker_object_new(joker_new(joker_id)); shop_jokers[i]->sprite_object->x = int2fx(120 + i * 32); diff --git a/source/joker.c b/source/joker.c index 02febc5..34b71d5 100644 --- a/source/joker.c +++ b/source/joker.c @@ -229,7 +229,7 @@ bool joker_object_score(JokerObject *joker_object, Card* scored_card, int *chips { *chips += joker_effect.chips; *mult += joker_effect.mult; - // TODO: XMult + *mult *= joker_effect.xmult > 0 ? joker_effect.xmult : 1; // if xmult is zero, DO NOT multiply by it *money += joker_effect.money; // TODO: Retrigger @@ -247,6 +247,11 @@ bool joker_object_score(JokerObject *joker_object, Card* scored_card, int *chips tte_set_special(0xE000); // Red snprintf(score_buffer, sizeof(score_buffer), "+%d", joker_effect.mult); } + else if (joker_effect.xmult > 0) + { + tte_set_special(0xE000); // Red + snprintf(score_buffer, sizeof(score_buffer), "X%d", joker_effect.xmult); + } else if (joker_effect.money > 0) { tte_set_special(0xC000); // Yellow diff --git a/source/joker_effects.c b/source/joker_effects.c index 792970c..1bd8b7d 100644 --- a/source/joker_effects.c +++ b/source/joker_effects.c @@ -1,7 +1,9 @@ #include "joker.h" #include "util.h" #include "hand_analysis.h" +#include +static const int JOKER_STENCIL_ID = 16; static JokerEffect default_joker_effect(Joker *joker, Card *scored_card) { JokerEffect effect = {0}; @@ -184,6 +186,36 @@ static JokerEffect half_joker_effect(Joker *joker, Card *scored_card) { return effect; } +static JokerEffect joker_stencil_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 + + // +1 xmult per empty joker slot... + int jokers_top = get_jokers_top(); + effect.xmult = (MAX_JOKERS_HELD_SIZE-1) - jokers_top; + + // ...and also each stencil_joker adds +1 xmult + JokerObject** jokers = get_jokers(); + for (int i = 0; i < jokers_top; i++ ) + { + if (jokers[i]->joker->id == JOKER_STENCIL_ID) + effect.xmult++; + } + + return effect; +} + +static JokerEffect misprint_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.mult = random() % 24; + + 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 @@ -201,6 +233,8 @@ const JokerInfo joker_registry[] = { { COMMON_JOKER, 4, devious_joker_effect }, { COMMON_JOKER, 4, crafty_joker_effect }, { COMMON_JOKER, 5, half_joker_effect }, + { UNCOMMON_JOKER, 8, joker_stencil_effect }, + { COMMON_JOKER, 4, misprint_joker_effect }, }; static const size_t joker_registry_size = NUM_ELEM_IN_ARR(joker_registry); From 08307d62adaf6d5499681ff84f9dd257a0d6cf0d Mon Sep 17 00:00:00 2001 From: theturtlemafia Date: Sat, 2 Aug 2025 12:25:31 -0400 Subject: [PATCH 2/7] code review feedback --- include/joker.h | 3 ++- source/game.c | 50 +++++++++++++++++++++--------------------- source/joker_effects.c | 2 -- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/include/joker.h b/include/joker.h index a428f25..c3d173f 100644 --- a/include/joker.h +++ b/include/joker.h @@ -29,6 +29,7 @@ #define DEFAULT_JOKER_ID 0 #define GREEDY_JOKER_ID 1 // This is just an example to show the patern of making joker IDs +#define JOKER_STENCIL_ID 16 typedef struct { @@ -39,7 +40,7 @@ typedef struct bool processed; } Joker; -typedef struct JokerObject // copy of CardObject in card.h +typedef struct JokerObject { Joker *joker; SpriteObject* sprite_object; diff --git a/source/game.c b/source/game.c index 9323660..9e5c7b6 100644 --- a/source/game.c +++ b/source/game.c @@ -139,6 +139,31 @@ static inline Card *discard_pop() return discard_pile[discard_top--]; } +// get-functions, for other files to view game state (mainly for jokers) +CardObject **get_hand_array(void) { + return hand; +} + +int get_hand_top(void) { + return hand_top; +} + +CardObject **get_played_array(void) { + return played; +} + +int get_played_top(void) { + return played_top; +} + +JokerObject **get_jokers(void) { + return jokers; +} + +int get_jokers_top(void) { + return jokers_top; +} + // Consts // Rects left top right bottom @@ -214,31 +239,6 @@ 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" -// get-functions, for other files to view game state (mainly for jokers) -CardObject **get_hand_array(void) { - return hand; -} - -int get_hand_top(void) { - return hand_top; -} - -CardObject **get_played_array(void) { - return played; -} - -int get_played_top(void) { - return played_top; -} - -JokerObject **get_jokers(void) { - return jokers; -} - -int get_jokers_top(void) { - return jokers_top; -} - // General functions void set_seed(int seed) { diff --git a/source/joker_effects.c b/source/joker_effects.c index 1bd8b7d..9403fff 100644 --- a/source/joker_effects.c +++ b/source/joker_effects.c @@ -3,8 +3,6 @@ #include "hand_analysis.h" #include -static const int JOKER_STENCIL_ID = 16; - static JokerEffect default_joker_effect(Joker *joker, Card *scored_card) { JokerEffect effect = {0}; if (scored_card == NULL) effect.mult = 4; From 56a211616a8da7037a41c29dfce4b684c1412801 Mon Sep 17 00:00:00 2001 From: MeirGavish Date: Sat, 2 Aug 2025 19:43:44 +0300 Subject: [PATCH 3/7] Removed misprint magic number --- source/joker_effects.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/joker_effects.c b/source/joker_effects.c index 9403fff..5e934ee 100644 --- a/source/joker_effects.c +++ b/source/joker_effects.c @@ -204,12 +204,13 @@ static JokerEffect joker_stencil_effect(Joker *joker, Card *scored_card) { return effect; } +#define MISPRINT_MAX_MULT 23 static JokerEffect misprint_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.mult = random() % 24; + effect.mult = random() % (MISPRINT_MAX_MULT + 1); return effect; } From 4731fea21b6919795a9d17a6ecdc90d6813c759f Mon Sep 17 00:00:00 2001 From: theturtlemafia Date: Sat, 2 Aug 2025 13:08:42 -0400 Subject: [PATCH 4/7] add joker sprites --- graphics/joker_gfx8.grit | 1 + graphics/joker_gfx8.png | Bin 0 -> 1105 bytes include/joker_gfx.h | 1 + source/joker.c | 2 ++ 4 files changed, 4 insertions(+) create mode 100644 graphics/joker_gfx8.grit create mode 100644 graphics/joker_gfx8.png diff --git a/graphics/joker_gfx8.grit b/graphics/joker_gfx8.grit new file mode 100644 index 0000000..a8ac3f6 --- /dev/null +++ b/graphics/joker_gfx8.grit @@ -0,0 +1 @@ +-gB4 -Mw4 -Mh4 -m! -pn 16 \ No newline at end of file diff --git a/graphics/joker_gfx8.png b/graphics/joker_gfx8.png new file mode 100644 index 0000000000000000000000000000000000000000..01dbbdd85b64d862179b0a669682c3727b795f9a GIT binary patch literal 1105 zcmV-X1g`suP)Px(3rR#lRA_0f$k$$S2^e~fW09+CT~rJ50b~R=h7e*LS9WwM={XP# zKKs_z2|k!WERMm@t!Ayf-sd7ns13;Xl^_guKQR$O*nvDTmGdLtJirNC?+ksptB$06$yv zGf%0a#uHkNx+t6WQh1?&7m7`xmhmMpHv-BUPw*KDCJ)wlWA!cC6Z`RE@{~tV4xblI zoxwrszdXNyJio}r-|2v=t4}Dq73S3tlm$A2gT(mRO6!K_bwUdLo4bfW_k#Y-T~y>E zqL1hJWzAJe#f^BGXum#4_0_AbNPU7$|Ae@4^5>ob8|$l}JzR7Z^|?MU7>-is09OXf zml3XBCKs>i7;PM5LuMNM@rS1+)SbeI@y)drU~dP(o1+vxiXsS+?9kxN5t_T((>XI* z_`AW(;K9NSw=fI~hp;|JN0}|4l#0XGrI)@X)T^zSruSX)GqZr0RbWLb!LQ%OS;GpU z_Sc_Iy?~?=91KU0=NAZfw-N4c=Q;$lD?yRJ3?}%l1l2Fgur634DTBW}eFp&e5&(US zl29Lx&DxH*;U0HxTv!UWXzeBFz@|+7U&zmqRx_qJ0J{0FMPbb zUSqH@2hge9>GldcfxhCnzUKG@n+DCIqYTWjFS3H>_ddD@_|VIQ^W%nBDKq>RKac+l X6NdP!yMOx?00000NkvXXu0mjf(jgOx literal 0 HcmV?d00001 diff --git a/include/joker_gfx.h b/include/joker_gfx.h index c549405..92c3edc 100644 --- a/include/joker_gfx.h +++ b/include/joker_gfx.h @@ -9,5 +9,6 @@ #include "joker_gfx5.h" #include "joker_gfx6.h" #include "joker_gfx7.h" +#include "joker_gfx8.h" #endif \ No newline at end of file diff --git a/source/joker.c b/source/joker.c index 34b71d5..c302faf 100644 --- a/source/joker.c +++ b/source/joker.c @@ -104,6 +104,7 @@ void joker_init() joker_gfxTiles[5] = joker_gfx5Tiles; joker_gfxTiles[6] = joker_gfx6Tiles; joker_gfxTiles[7] = joker_gfx7Tiles; + joker_gfxTiles[8] = joker_gfx8Tiles; joker_gfxPal[0] = joker_gfx0Pal; joker_gfxPal[1] = joker_gfx1Pal; @@ -113,6 +114,7 @@ void joker_init() joker_gfxPal[5] = joker_gfx5Pal; joker_gfxPal[6] = joker_gfx6Pal; joker_gfxPal[7] = joker_gfx7Pal; + joker_gfxPal[8] = joker_gfx8Pal; for (int i = 0; i < num_spritesheets; i++) { From a8f429eca35ad73ba4028606ac5055b063668de0 Mon Sep 17 00:00:00 2001 From: MeirGavish Date: Sun, 3 Aug 2025 16:08:41 +0300 Subject: [PATCH 5/7] Moved the price of shop items below the item so it is not obstructed when the card is raised on highlight --- include/sprite.h | 2 ++ source/game.c | 2 +- source/sprite.c | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/sprite.h b/include/sprite.h index 0cd9840..d76f2b5 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -4,6 +4,8 @@ #include #include +#define CARD_SPRITE_SIZE 32 + typedef struct { OBJ_ATTR *obj; diff --git a/source/game.c b/source/game.c index 6f3d8de..db684b0 100644 --- a/source/game.c +++ b/source/game.c @@ -1821,7 +1821,7 @@ static void game_shop_create_items(JokerObject *shop_jokers[], bool first_time) shop_jokers[i]->sprite_object->ty = int2fx(71); int x = fx2int(shop_jokers[i]->sprite_object->tx) + TILE_SIZE - (get_digits_even(shop_jokers[i]->joker->value) - 1) * TILE_SIZE; - int y = fx2int(shop_jokers[i]->sprite_object->ty); + int y = fx2int(shop_jokers[i]->sprite_object->ty) + CARD_SPRITE_SIZE + TILE_SIZE; tte_printf("#{P:%d,%d; cx:0xC000}$%d", x, y, shop_jokers[i]->joker->value); if (first_time == false) diff --git a/source/sprite.c b/source/sprite.c index 5e3edf6..ebb2e37 100644 --- a/source/sprite.c +++ b/source/sprite.c @@ -1,5 +1,6 @@ #include "sprite.h" #include "util.h" +#include "audio_utils.h" #include #include @@ -206,8 +207,7 @@ void sprite_object_shake(SpriteObject* sprite_object, mm_word sound_id) if (sound_id == UNDEFINED) return; // If no sound ID is provided, do nothing - mm_sound_effect sfx_select = { {sound_id}, 1024, 0, 255, 128, }; - mmEffectEx(&sfx_select); + play_sfx(sound_id, MM_BASE_PITCH_RATE); } void sprite_object_set_selected(SpriteObject* sprite_object, bool selected) From bbefff2eb955c9476c8866c9571bfafd0ac41069 Mon Sep 17 00:00:00 2001 From: MeirGavish Date: Sun, 3 Aug 2025 16:51:16 +0300 Subject: [PATCH 6/7] Fixed bug where shop price would continue displaying after the item was purchased --- source/game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/game.c b/source/game.c index dae247b..af14d73 100644 --- a/source/game.c +++ b/source/game.c @@ -2325,7 +2325,7 @@ void game_shop() Rect joker_price_rect; joker_price_rect.left = fx2int(shop_jokers[i]->sprite_object->tx); - joker_price_rect.top = fx2int(shop_jokers[i]->sprite_object->ty) + TILE_SIZE; + joker_price_rect.top = fx2int(shop_jokers[i]->sprite_object->ty) + CARD_SPRITE_SIZE + 2*TILE_SIZE; joker_price_rect.right = joker_price_rect.left + TILE_SIZE * 3; joker_price_rect.bottom = joker_price_rect.top + TILE_SIZE; From ec2aaf245dc6e717a54b8b4519e21aa9031f49a9 Mon Sep 17 00:00:00 2001 From: MeirGavish Date: Sun, 3 Aug 2025 18:15:28 +0300 Subject: [PATCH 7/7] Added clarification comment --- source/game.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/game.c b/source/game.c index af14d73..1f4fd5c 100644 --- a/source/game.c +++ b/source/game.c @@ -2325,6 +2325,7 @@ void game_shop() Rect joker_price_rect; joker_price_rect.left = fx2int(shop_jokers[i]->sprite_object->tx); + // 2*TILE_SIZE because the item is highlighted and raised by 1 additional tile joker_price_rect.top = fx2int(shop_jokers[i]->sprite_object->ty) + CARD_SPRITE_SIZE + 2*TILE_SIZE; joker_price_rect.right = joker_price_rect.left + TILE_SIZE * 3; joker_price_rect.bottom = joker_price_rect.top + TILE_SIZE;