diff --git a/joker_8c_source.html b/joker_8c_source.html index b275917a..77064842 100644 --- a/joker_8c_source.html +++ b/joker_8c_source.html @@ -399,240 +399,239 @@ $(document).ready(function(){initNavTree('joker_8c_source.html',''); initResizab
257
258void joker_object_update(JokerObject* joker_object)
259{
-
260 CardObject* card_object = (CardObject*)joker_object;
-
261 card_object_update(card_object);
-
262}
-
263
-
264void joker_object_shake(JokerObject* joker_object, mm_word sound_id)
-
265{
-
266 sprite_object_shake(joker_object->sprite_object, sound_id);
-
267}
-
268
-
269void set_and_shift_text(char* str, int* cursor_pos_x, int* cursor_pos_y, int color_pb)
-
270{
-
271 tte_set_pos(*cursor_pos_x, *cursor_pos_y);
-
272 tte_set_special(color_pb * TTE_SPECIAL_PB_MULT_OFFSET);
-
273 tte_write(str);
-
274
-
275 // + 1 For space
-
276 const int joker_score_display_offset_px = (MAX_CARD_SCORE_STR_LEN + 1) * TTE_CHAR_SIZE;
-
277 *cursor_pos_x += joker_score_display_offset_px;
-
278}
-
279
-
280bool joker_object_score(
-
281 JokerObject* joker_object,
-
282 CardObject* card_object,
-
283 enum JokerEvent joker_event
-
284)
-
285{
-
286 if (joker_object == NULL)
-
287 {
-
288 return false;
-
289 }
-
290
-
291 JokerEffect* joker_effect = NULL;
-
292 u32 effect_flags_ret =
-
293 joker_get_score_effect(joker_object->joker, card_object->card, joker_event, &joker_effect);
-
294
-
295 if (effect_flags_ret == JOKER_EFFECT_FLAG_NONE)
-
296 {
-
297 return false;
-
298 }
-
299
-
300 u32 chips = get_chips();
-
301 u32 mult = get_mult();
-
302 int money = g_game_vars.money;
-
303
-
304 if (effect_flags_ret & JOKER_EFFECT_FLAG_RETRIGGER)
-
305 {
-
306 set_retrigger(joker_effect->retrigger);
-
307 }
-
308
-
309 // joker_effect.message will have been set if the Joker had anything custom to say
-
310
-
311 int cursorPosX = TILE_SIZE; // Offset of one tile to better center the text on the card
-
312 int cursorPosY = 0;
-
313 if (joker_event == JOKER_EVENT_ON_CARD_HELD)
-
314 {
-
315 // display the text on top of the card instead of below the Joker for Held Cards effects
-
316 // scored_card cannot be NULL here because of the joker event
-
317 cursorPosX += fx2int(card_object->sprite_object->x);
-
318 cursorPosY = HELD_CARD_SCORE_TEXT_Y;
-
319 }
-
320 else
-
321 {
-
322 cursorPosX += fx2int(joker_object->sprite_object->x);
-
323 cursorPosY = JOKER_SCORE_TEXT_Y;
-
324 }
-
325
-
326 mm_word sfx_id;
-
327 if (effect_flags_ret & JOKER_EFFECT_FLAG_CHIPS)
-
328 {
-
329 chips = u32_protected_add(chips, joker_effect->chips);
-
330 char score_buffer[INT_MAX_DIGITS + 2]; // For '+' and null terminator
-
331 snprintf(score_buffer, sizeof(score_buffer), "+%lu", joker_effect->chips);
-
332 set_and_shift_text(score_buffer, &cursorPosX, &cursorPosY, TTE_BLUE_PB);
-
333 sfx_id = SFX_CHIPS_GENERIC; // The joker chips effect is "generic"
-
334 }
-
335 if (effect_flags_ret & JOKER_EFFECT_FLAG_MULT)
-
336 {
-
337 mult = u32_protected_add(mult, joker_effect->mult);
-
338 char score_buffer[INT_MAX_DIGITS + 2];
-
339 snprintf(score_buffer, sizeof(score_buffer), "+%lu", joker_effect->mult);
-
340 set_and_shift_text(score_buffer, &cursorPosX, &cursorPosY, TTE_RED_PB);
-
341 sfx_id = SFX_MULT;
-
342 }
-
343 // if xmult is zero, DO NOT multiply by it
-
344 if (effect_flags_ret & JOKER_EFFECT_FLAG_XMULT && joker_effect->xmult > 0)
-
345 {
-
346 mult = u32_protected_mult(mult, joker_effect->xmult);
-
347 char score_buffer[INT_MAX_DIGITS + 2];
-
348 snprintf(score_buffer, sizeof(score_buffer), "X%lu", joker_effect->xmult);
-
349 set_and_shift_text(score_buffer, &cursorPosX, &cursorPosY, TTE_RED_PB);
-
350 sfx_id = SFX_XMULT;
-
351 }
-
352 if (effect_flags_ret & JOKER_EFFECT_FLAG_MONEY)
-
353 {
-
354 money += joker_effect->money;
-
355 char score_buffer[INT_MAX_DIGITS + 2];
-
356 snprintf(score_buffer, sizeof(score_buffer), "%d$", joker_effect->money);
-
357 set_and_shift_text(score_buffer, &cursorPosX, &cursorPosY, TTE_YELLOW_PB);
-
358 // TODO: Money sound effect
-
359 }
-
360 // custom message for Jokers (including retriggers where Jokers will say "Again!")
-
361 // joker_effect->message will have been set if the Joker had anything custom to say
-
362 if (effect_flags_ret & JOKER_EFFECT_FLAG_MESSAGE)
-
363 {
-
364 set_and_shift_text(joker_effect->message, &cursorPosX, &cursorPosY, TTE_WHITE_PB);
-
365 }
-
366 // this will start the Joker expire animation
-
367 if (effect_flags_ret & JOKER_EFFECT_FLAG_EXPIRE && joker_effect->expire)
-
368 {
-
369 joker_object_shake(joker_object, UNDEFINED);
-
370 list_push_back(get_expired_jokers_list(), joker_object);
-
371 }
-
372
-
373 // Update values
-
374 set_chips(chips);
-
375 set_mult(mult);
-
376 g_game_vars.money = money;
-
377
-
378 // Update displays
-
379 display_chips();
-
380 display_mult();
-
381 display_money();
-
382
-
383 joker_object_shake(joker_object, sfx_id);
-
384
-
385 return true;
-
386}
-
387
-
388Sprite* joker_object_get_sprite(JokerObject* joker_object)
-
389{
-
390 if (joker_object == NULL)
-
391 return NULL;
-
392 return sprite_object_get_sprite(joker_object->sprite_object);
-
393}
-
394
-
395int joker_get_random_rarity()
-
396{
-
397 int joker_rarity = 0;
-
398 int rarity_roll = rng_get_u32() % 100;
-
399 if (rarity_roll < COMMON_JOKER_CHANCE)
-
400 {
-
401 joker_rarity = COMMON_JOKER;
-
402 }
-
403 else if (rarity_roll < COMMON_JOKER_CHANCE + UNCOMMON_JOKER_CHANCE)
-
404 {
-
405 joker_rarity = UNCOMMON_JOKER;
-
406 }
-
407 else if (rarity_roll < COMMON_JOKER_CHANCE + UNCOMMON_JOKER_CHANCE + RARE_JOKER_CHANCE)
-
408 {
-
409 joker_rarity = RARE_JOKER;
-
410 }
-
411 else if (rarity_roll < COMMON_JOKER_CHANCE + UNCOMMON_JOKER_CHANCE + RARE_JOKER_CHANCE +
-
412 LEGENDARY_JOKER_CHANCE)
-
413 {
-
414 joker_rarity = LEGENDARY_JOKER;
-
415 }
-
416
-
417 return joker_rarity;
-
418}
-
419
-
420static int s_get_num_spritesheets()
-
421{
-
422 return MAX_NUM_JOKERS_SPRITESHEETS;
-
423}
-
424
-
425static int s_joker_get_spritesheet_idx(u8 joker_id)
-
426{
-
427 return joker_id_to_sprite_map[joker_id];
-
428}
-
429
-
430static int s_joker_get_sprite_idx_in_sheet(u8 joker_id, int spritesheet_idx)
-
431{
-
432 return joker_id - spritesheet_idx_to_starting_joker_id[joker_id_to_sprite_map[joker_id]];
-
433}
-
434
-
435static void s_joker_pb_add_sprite_user(int pb)
-
436{
-
437 joker_pb_num_sprite_users[pb - JOKER_BASE_PB]++;
-
438}
-
439
-
440static void s_joker_pb_remove_sprite_user(int pb)
-
441{
-
442 int num_sprite_users = joker_pb_num_sprite_users[pb - JOKER_BASE_PB];
-
443 joker_pb_num_sprite_users[pb - JOKER_BASE_PB] = max(0, num_sprite_users - 1);
-
444}
-
445
-
446static int s_joker_pb_get_num_sprite_users(int joker_pb)
-
447{
-
448 return joker_pb_num_sprite_users[joker_pb - JOKER_BASE_PB];
-
449}
-
450
-
451static int s_get_unused_joker_pb()
-
452{
-
453 for (int i = 0; i < NUM_ELEM_IN_ARR(joker_pb_num_sprite_users); i++)
-
454 {
-
455 if (joker_pb_num_sprite_users[i] == 0)
-
456 {
-
457 return (i + JOKER_BASE_PB);
-
458 }
-
459 }
-
460
-
461 return UNDEFINED;
-
462}
-
463
-
464static int s_allocate_pb_if_needed(u8 joker_id)
-
465{
-
466 int joker_spritesheet_idx = s_joker_get_spritesheet_idx(joker_id);
-
467 int joker_pb = joker_spritesheet_pb_map[joker_spritesheet_idx];
-
468 if (joker_pb != UNDEFINED)
-
469 {
-
470 // Already allocated
-
471 return joker_pb;
-
472 }
-
473
-
474 // Allocate a new palette
-
475 joker_pb = s_get_unused_joker_pb();
-
476
-
477 if (joker_pb == UNDEFINED)
-
478 {
-
479 // Ran out of palettes, default to base and pray
-
480 joker_pb = JOKER_BASE_PB;
-
481 }
-
482 else
-
483 {
-
484 joker_spritesheet_pb_map[joker_spritesheet_idx] = joker_pb;
-
485 memcpy16(
-
486 &pal_obj_mem[PAL_ROW_LEN * joker_pb],
-
487 joker_gfxPal[joker_spritesheet_idx],
-
488 NUM_ELEM_IN_ARR(joker_gfx0Pal)
-
489 );
-
490 }
-
491
-
492 return joker_pb;
-
493}
+
260 sprite_object_update(joker_object->sprite_object);
+
261}
+
262
+
263void joker_object_shake(JokerObject* joker_object, mm_word sound_id)
+
264{
+
265 sprite_object_shake(joker_object->sprite_object, sound_id);
+
266}
+
267
+
268void set_and_shift_text(char* str, int* cursor_pos_x, int* cursor_pos_y, int color_pb)
+
269{
+
270 tte_set_pos(*cursor_pos_x, *cursor_pos_y);
+
271 tte_set_special(color_pb * TTE_SPECIAL_PB_MULT_OFFSET);
+
272 tte_write(str);
+
273
+
274 // + 1 For space
+
275 const int joker_score_display_offset_px = (MAX_CARD_SCORE_STR_LEN + 1) * TTE_CHAR_SIZE;
+
276 *cursor_pos_x += joker_score_display_offset_px;
+
277}
+
278
+
279bool joker_object_score(
+
280 JokerObject* joker_object,
+
281 CardObject* card_object,
+
282 enum JokerEvent joker_event
+
283)
+
284{
+
285 if (joker_object == NULL)
+
286 {
+
287 return false;
+
288 }
+
289
+
290 JokerEffect* joker_effect = NULL;
+
291 u32 effect_flags_ret =
+
292 joker_get_score_effect(joker_object->joker, card_object->card, joker_event, &joker_effect);
+
293
+
294 if (effect_flags_ret == JOKER_EFFECT_FLAG_NONE)
+
295 {
+
296 return false;
+
297 }
+
298
+
299 u32 chips = get_chips();
+
300 u32 mult = get_mult();
+
301 int money = g_game_vars.money;
+
302
+
303 if (effect_flags_ret & JOKER_EFFECT_FLAG_RETRIGGER)
+
304 {
+
305 set_retrigger(joker_effect->retrigger);
+
306 }
+
307
+
308 // joker_effect.message will have been set if the Joker had anything custom to say
+
309
+
310 int cursorPosX = TILE_SIZE; // Offset of one tile to better center the text on the card
+
311 int cursorPosY = 0;
+
312 if (joker_event == JOKER_EVENT_ON_CARD_HELD)
+
313 {
+
314 // display the text on top of the card instead of below the Joker for Held Cards effects
+
315 // scored_card cannot be NULL here because of the joker event
+
316 cursorPosX += fx2int(card_object->sprite_object->x);
+
317 cursorPosY = HELD_CARD_SCORE_TEXT_Y;
+
318 }
+
319 else
+
320 {
+
321 cursorPosX += fx2int(joker_object->sprite_object->x);
+
322 cursorPosY = JOKER_SCORE_TEXT_Y;
+
323 }
+
324
+
325 mm_word sfx_id;
+
326 if (effect_flags_ret & JOKER_EFFECT_FLAG_CHIPS)
+
327 {
+
328 chips = u32_protected_add(chips, joker_effect->chips);
+
329 char score_buffer[INT_MAX_DIGITS + 2]; // For '+' and null terminator
+
330 snprintf(score_buffer, sizeof(score_buffer), "+%lu", joker_effect->chips);
+
331 set_and_shift_text(score_buffer, &cursorPosX, &cursorPosY, TTE_BLUE_PB);
+
332 sfx_id = SFX_CHIPS_GENERIC; // The joker chips effect is "generic"
+
333 }
+
334 if (effect_flags_ret & JOKER_EFFECT_FLAG_MULT)
+
335 {
+
336 mult = u32_protected_add(mult, joker_effect->mult);
+
337 char score_buffer[INT_MAX_DIGITS + 2];
+
338 snprintf(score_buffer, sizeof(score_buffer), "+%lu", joker_effect->mult);
+
339 set_and_shift_text(score_buffer, &cursorPosX, &cursorPosY, TTE_RED_PB);
+
340 sfx_id = SFX_MULT;
+
341 }
+
342 // if xmult is zero, DO NOT multiply by it
+
343 if (effect_flags_ret & JOKER_EFFECT_FLAG_XMULT && joker_effect->xmult > 0)
+
344 {
+
345 mult = u32_protected_mult(mult, joker_effect->xmult);
+
346 char score_buffer[INT_MAX_DIGITS + 2];
+
347 snprintf(score_buffer, sizeof(score_buffer), "X%lu", joker_effect->xmult);
+
348 set_and_shift_text(score_buffer, &cursorPosX, &cursorPosY, TTE_RED_PB);
+
349 sfx_id = SFX_XMULT;
+
350 }
+
351 if (effect_flags_ret & JOKER_EFFECT_FLAG_MONEY)
+
352 {
+
353 money += joker_effect->money;
+
354 char score_buffer[INT_MAX_DIGITS + 2];
+
355 snprintf(score_buffer, sizeof(score_buffer), "%d$", joker_effect->money);
+
356 set_and_shift_text(score_buffer, &cursorPosX, &cursorPosY, TTE_YELLOW_PB);
+
357 // TODO: Money sound effect
+
358 }
+
359 // custom message for Jokers (including retriggers where Jokers will say "Again!")
+
360 // joker_effect->message will have been set if the Joker had anything custom to say
+
361 if (effect_flags_ret & JOKER_EFFECT_FLAG_MESSAGE)
+
362 {
+
363 set_and_shift_text(joker_effect->message, &cursorPosX, &cursorPosY, TTE_WHITE_PB);
+
364 }
+
365 // this will start the Joker expire animation
+
366 if (effect_flags_ret & JOKER_EFFECT_FLAG_EXPIRE && joker_effect->expire)
+
367 {
+
368 joker_object_shake(joker_object, UNDEFINED);
+
369 list_push_back(get_expired_jokers_list(), joker_object);
+
370 }
+
371
+
372 // Update values
+
373 set_chips(chips);
+
374 set_mult(mult);
+
375 g_game_vars.money = money;
+
376
+
377 // Update displays
+
378 display_chips();
+
379 display_mult();
+
380 display_money();
+
381
+
382 joker_object_shake(joker_object, sfx_id);
+
383
+
384 return true;
+
385}
+
386
+
387Sprite* joker_object_get_sprite(JokerObject* joker_object)
+
388{
+
389 if (joker_object == NULL)
+
390 return NULL;
+
391 return sprite_object_get_sprite(joker_object->sprite_object);
+
392}
+
393
+
394int joker_get_random_rarity()
+
395{
+
396 int joker_rarity = 0;
+
397 int rarity_roll = rng_get_u32() % 100;
+
398 if (rarity_roll < COMMON_JOKER_CHANCE)
+
399 {
+
400 joker_rarity = COMMON_JOKER;
+
401 }
+
402 else if (rarity_roll < COMMON_JOKER_CHANCE + UNCOMMON_JOKER_CHANCE)
+
403 {
+
404 joker_rarity = UNCOMMON_JOKER;
+
405 }
+
406 else if (rarity_roll < COMMON_JOKER_CHANCE + UNCOMMON_JOKER_CHANCE + RARE_JOKER_CHANCE)
+
407 {
+
408 joker_rarity = RARE_JOKER;
+
409 }
+
410 else if (rarity_roll < COMMON_JOKER_CHANCE + UNCOMMON_JOKER_CHANCE + RARE_JOKER_CHANCE +
+
411 LEGENDARY_JOKER_CHANCE)
+
412 {
+
413 joker_rarity = LEGENDARY_JOKER;
+
414 }
+
415
+
416 return joker_rarity;
+
417}
+
418
+
419static int s_get_num_spritesheets()
+
420{
+
421 return MAX_NUM_JOKERS_SPRITESHEETS;
+
422}
+
423
+
424static int s_joker_get_spritesheet_idx(u8 joker_id)
+
425{
+
426 return joker_id_to_sprite_map[joker_id];
+
427}
+
428
+
429static int s_joker_get_sprite_idx_in_sheet(u8 joker_id, int spritesheet_idx)
+
430{
+
431 return joker_id - spritesheet_idx_to_starting_joker_id[joker_id_to_sprite_map[joker_id]];
+
432}
+
433
+
434static void s_joker_pb_add_sprite_user(int pb)
+
435{
+
436 joker_pb_num_sprite_users[pb - JOKER_BASE_PB]++;
+
437}
+
438
+
439static void s_joker_pb_remove_sprite_user(int pb)
+
440{
+
441 int num_sprite_users = joker_pb_num_sprite_users[pb - JOKER_BASE_PB];
+
442 joker_pb_num_sprite_users[pb - JOKER_BASE_PB] = max(0, num_sprite_users - 1);
+
443}
+
444
+
445static int s_joker_pb_get_num_sprite_users(int joker_pb)
+
446{
+
447 return joker_pb_num_sprite_users[joker_pb - JOKER_BASE_PB];
+
448}
+
449
+
450static int s_get_unused_joker_pb()
+
451{
+
452 for (int i = 0; i < NUM_ELEM_IN_ARR(joker_pb_num_sprite_users); i++)
+
453 {
+
454 if (joker_pb_num_sprite_users[i] == 0)
+
455 {
+
456 return (i + JOKER_BASE_PB);
+
457 }
+
458 }
+
459
+
460 return UNDEFINED;
+
461}
+
462
+
463static int s_allocate_pb_if_needed(u8 joker_id)
+
464{
+
465 int joker_spritesheet_idx = s_joker_get_spritesheet_idx(joker_id);
+
466 int joker_pb = joker_spritesheet_pb_map[joker_spritesheet_idx];
+
467 if (joker_pb != UNDEFINED)
+
468 {
+
469 // Already allocated
+
470 return joker_pb;
+
471 }
+
472
+
473 // Allocate a new palette
+
474 joker_pb = s_get_unused_joker_pb();
+
475
+
476 if (joker_pb == UNDEFINED)
+
477 {
+
478 // Ran out of palettes, default to base and pray
+
479 joker_pb = JOKER_BASE_PB;
+
480 }
+
481 else
+
482 {
+
483 joker_spritesheet_pb_map[joker_spritesheet_idx] = joker_pb;
+
484 memcpy16(
+
485 &pal_obj_mem[PAL_ROW_LEN * joker_pb],
+
486 joker_gfxPal[joker_spritesheet_idx],
+
487 NUM_ELEM_IN_ARR(joker_gfx0Pal)
+
488 );
+
489 }
+
490
+
491 return joker_pb;
+
492}
game_variables.h
Game global game variables struct definition.
graphic_utils.h
Graphic utility functions.
TILE_SIZE
#define TILE_SIZE
Tile size in pixels, both height and width as tiles are square.
Definition graphic_utils.h:44
@@ -651,6 +650,7 @@ $(document).ready(function(){initNavTree('joker_8c_source.html',''); initResizab
sprite_object_shake
void sprite_object_shake(SpriteObject *sprite_object, mm_word sound_id)
Shake SpriteObject on screen and play a sound.
Definition sprite.c:303
sprite_get_layer
int sprite_get_layer(Sprite *sprite)
Get index of Sprite in the GBA object buffer.
Definition sprite.c:106
sprite_object_get_sprite
Sprite * sprite_object_get_sprite(SpriteObject *sprite_object)
Get a SpriteObject's registered Sprite.
Definition sprite.c:317
+
sprite_object_update
IWRAM_CODE void sprite_object_update(SpriteObject *sprite_object)
Update a SpriteObject, to be called once per frame per active SpriteObject.
Definition sprite.c:229
CardObject
Definition card.h:56
Card
Definition card.h:50
JokerEffect
Definition joker.h:120
diff --git a/joker_8h.html b/joker_8h.html index f774f0a3..dabe9a85 100644 --- a/joker_8h.html +++ b/joker_8h.html @@ -1026,7 +1026,7 @@ Functions
-

Definition at line 395 of file joker.c.

+

Definition at line 394 of file joker.c.

@@ -1237,7 +1237,7 @@ Functions
-

Definition at line 388 of file joker.c.

+

Definition at line 387 of file joker.c.

@@ -1293,7 +1293,7 @@ Functions
-

Definition at line 280 of file joker.c.

+

Definition at line 279 of file joker.c.

@@ -1323,7 +1323,7 @@ Functions
-

Definition at line 264 of file joker.c.

+

Definition at line 263 of file joker.c.