Removed magic numbers for card score length and intmax buffer sizes
This commit is contained in:
@@ -6,6 +6,8 @@
|
|||||||
#define MAX_JOKERS_HELD_SIZE 5 // This doesn't account for negatives right now.
|
#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_SHOP_JOKERS 2 // TODO: Make this dynamic and allow for other items besides jokers
|
||||||
#define MAX_SELECTION_SIZE 5
|
#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)
|
#define FRAMES(x) (((x) + game_speed - 1) / game_speed)
|
||||||
|
|
||||||
// TODO: Turn into enum?
|
// TODO: Turn into enum?
|
||||||
|
|||||||
@@ -43,6 +43,9 @@
|
|||||||
// Tile size in pixels, both height and width as tiles are square
|
// Tile size in pixels, both height and width as tiles are square
|
||||||
#define TILE_SIZE 8
|
#define TILE_SIZE 8
|
||||||
|
|
||||||
|
// By default TTE characters occupy a single tile
|
||||||
|
#define TTE_CHAR_SIZE TILE_SIZE
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int left;
|
int left;
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ static inline int get_digits_even(int n)
|
|||||||
|
|
||||||
#define NUM_ELEM_IN_ARR(arr) (sizeof(arr) / sizeof((arr)[0]))
|
#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);
|
int int_arr_max(int int_arr[], int size);
|
||||||
|
|
||||||
#endif // UTIL_H
|
#endif // UTIL_H
|
||||||
+1
-1
@@ -1619,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
|
tte_set_special(0xD000); // Set text color to blue from background memory
|
||||||
|
|
||||||
// Write the score to a character buffer variable
|
// 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));
|
snprintf(score_buffer, sizeof(score_buffer), "+%d", card_get_value(played[j]->card));
|
||||||
tte_write(score_buffer);
|
tte_write(score_buffer);
|
||||||
|
|
||||||
|
|||||||
+11
-8
@@ -270,42 +270,45 @@ bool joker_object_score(JokerObject *joker_object, Card* scored_card, int *chips
|
|||||||
*money += joker_effect.money;
|
*money += joker_effect.money;
|
||||||
// TODO: Retrigger
|
// TODO: Retrigger
|
||||||
|
|
||||||
|
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
|
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)
|
if (joker_effect.chips > 0)
|
||||||
{
|
{
|
||||||
char score_buffer[12];
|
char score_buffer[INT_MAX_DIGITS + 2]; // For '+' and null terminator
|
||||||
tte_set_pos(cursorPosX, JOKER_SCORE_TEXT_Y);
|
tte_set_pos(cursorPosX, JOKER_SCORE_TEXT_Y);
|
||||||
tte_set_special(0xD000); // Blue
|
tte_set_special(0xD000); // Blue
|
||||||
snprintf(score_buffer, sizeof(score_buffer), "+%d", joker_effect.chips);
|
snprintf(score_buffer, sizeof(score_buffer), "+%d", joker_effect.chips);
|
||||||
tte_write(score_buffer);
|
tte_write(score_buffer);
|
||||||
cursorPosX += 30;
|
cursorPosX += joker_score_display_offset_px;
|
||||||
}
|
}
|
||||||
if (joker_effect.mult > 0)
|
if (joker_effect.mult > 0)
|
||||||
{
|
{
|
||||||
char score_buffer[12];
|
char score_buffer[INT_MAX_DIGITS + 2];
|
||||||
tte_set_pos(cursorPosX, JOKER_SCORE_TEXT_Y);
|
tte_set_pos(cursorPosX, JOKER_SCORE_TEXT_Y);
|
||||||
tte_set_special(0xE000); // Red
|
tte_set_special(0xE000); // Red
|
||||||
snprintf(score_buffer, sizeof(score_buffer), "+%d", joker_effect.mult);
|
snprintf(score_buffer, sizeof(score_buffer), "+%d", joker_effect.mult);
|
||||||
tte_write(score_buffer);
|
tte_write(score_buffer);
|
||||||
cursorPosX += 30;
|
cursorPosX += joker_score_display_offset_px;
|
||||||
}
|
}
|
||||||
if (joker_effect.xmult > 0)
|
if (joker_effect.xmult > 0)
|
||||||
{
|
{
|
||||||
char score_buffer[12];
|
char score_buffer[INT_MAX_DIGITS + 2];
|
||||||
tte_set_pos(cursorPosX, JOKER_SCORE_TEXT_Y);
|
tte_set_pos(cursorPosX, JOKER_SCORE_TEXT_Y);
|
||||||
tte_set_special(0xE000); // Red
|
tte_set_special(0xE000); // Red
|
||||||
snprintf(score_buffer, sizeof(score_buffer), "X%d", joker_effect.xmult);
|
snprintf(score_buffer, sizeof(score_buffer), "X%d", joker_effect.xmult);
|
||||||
tte_write(score_buffer);
|
tte_write(score_buffer);
|
||||||
cursorPosX += 30;
|
cursorPosX += joker_score_display_offset_px;
|
||||||
}
|
}
|
||||||
if (joker_effect.money > 0)
|
if (joker_effect.money > 0)
|
||||||
{
|
{
|
||||||
char score_buffer[12];
|
char score_buffer[INT_MAX_DIGITS + 2];
|
||||||
tte_set_pos(cursorPosX, JOKER_SCORE_TEXT_Y);
|
tte_set_pos(cursorPosX, JOKER_SCORE_TEXT_Y);
|
||||||
tte_set_special(0xC000); // Yellow
|
tte_set_special(0xC000); // Yellow
|
||||||
snprintf(score_buffer, sizeof(score_buffer), "+%d", joker_effect.money);
|
snprintf(score_buffer, sizeof(score_buffer), "+%d", joker_effect.money);
|
||||||
tte_write(score_buffer);
|
tte_write(score_buffer);
|
||||||
cursorPosX += 30;
|
cursorPosX += joker_score_display_offset_px;
|
||||||
}
|
}
|
||||||
|
|
||||||
joker_object->joker->processed = true; // Mark the joker as processed
|
joker_object->joker->processed = true; // Mark the joker as processed
|
||||||
|
|||||||
Reference in New Issue
Block a user