2019-12-01 21:52:53 -05:00
|
|
|
/**
|
|
|
|
* This file contains the initialization and behavior for red coins.
|
|
|
|
* Behavior controls audio and the orange number spawned, as well as interacting with
|
|
|
|
* the course's red coin star.
|
|
|
|
*/
|
2019-08-25 00:46:40 -04:00
|
|
|
|
2019-12-01 21:52:53 -05:00
|
|
|
/**
|
|
|
|
* Red coin's hitbox details.
|
|
|
|
*/
|
2019-08-25 00:46:40 -04:00
|
|
|
static struct ObjectHitbox sRedCoinHitbox = {
|
|
|
|
/* interactType: */ INTERACT_COIN,
|
|
|
|
/* downOffset: */ 0,
|
|
|
|
/* damageOrCoinValue: */ 2,
|
|
|
|
/* health: */ 0,
|
|
|
|
/* numLootCoins: */ 0,
|
|
|
|
/* radius: */ 100,
|
|
|
|
/* height: */ 64,
|
|
|
|
/* hurtboxRadius: */ 0,
|
|
|
|
/* hurtboxHeight: */ 0,
|
|
|
|
};
|
|
|
|
|
2019-12-01 21:52:53 -05:00
|
|
|
/**
|
|
|
|
* Red coin initialization function. Sets the coin's hitbox and parent object.
|
|
|
|
*/
|
2019-08-25 00:46:40 -04:00
|
|
|
void bhv_red_coin_init(void) {
|
2019-12-01 21:52:53 -05:00
|
|
|
// This floor and floor height are unused. Perhaps for orange number spawns originally?
|
|
|
|
struct Surface *dummyFloor;
|
|
|
|
UNUSED f32 floorHeight = find_floor(o->oPosX, o->oPosY, o->oPosZ, &dummyFloor);
|
2019-08-25 00:46:40 -04:00
|
|
|
|
2019-12-01 21:52:53 -05:00
|
|
|
struct Object *hiddenRedCoinStar;
|
|
|
|
|
|
|
|
// Set the red coins to have a parent of the closest red coin star.
|
2020-03-01 22:42:52 -05:00
|
|
|
hiddenRedCoinStar = cur_obj_nearest_object_with_behavior(bhvHiddenRedCoinStar);
|
2019-12-01 21:52:53 -05:00
|
|
|
if (hiddenRedCoinStar != NULL)
|
|
|
|
o->parentObj = hiddenRedCoinStar;
|
2019-08-25 00:46:40 -04:00
|
|
|
else {
|
2020-03-01 22:42:52 -05:00
|
|
|
hiddenRedCoinStar = cur_obj_nearest_object_with_behavior(bhvBowserCourseRedCoinStar);
|
2019-12-01 21:52:53 -05:00
|
|
|
if (hiddenRedCoinStar != NULL) {
|
|
|
|
o->parentObj = hiddenRedCoinStar;
|
|
|
|
} else {
|
2019-08-25 00:46:40 -04:00
|
|
|
o->parentObj = NULL;
|
2019-12-01 21:52:53 -05:00
|
|
|
}
|
2019-08-25 00:46:40 -04:00
|
|
|
}
|
|
|
|
|
2020-03-01 22:42:52 -05:00
|
|
|
obj_set_hitbox(o, &sRedCoinHitbox);
|
2019-08-25 00:46:40 -04:00
|
|
|
}
|
|
|
|
|
2019-12-01 21:52:53 -05:00
|
|
|
/**
|
|
|
|
* Main behavior for red coins. Primarily controls coin collection noise and spawning
|
|
|
|
* the orange number counter.
|
|
|
|
*/
|
2019-08-25 00:46:40 -04:00
|
|
|
void bhv_red_coin_loop(void) {
|
2019-12-01 21:52:53 -05:00
|
|
|
// If Mario interacted with the object...
|
2019-08-25 00:46:40 -04:00
|
|
|
if (o->oInteractStatus & INT_STATUS_INTERACTED) {
|
2019-12-01 21:52:53 -05:00
|
|
|
// ...and there is a red coin star in the level...
|
2019-08-25 00:46:40 -04:00
|
|
|
if (o->parentObj != NULL) {
|
2019-12-01 21:52:53 -05:00
|
|
|
// ...increment the star's counter.
|
2019-10-05 15:08:05 -04:00
|
|
|
o->parentObj->oHiddenStarTriggerCounter++;
|
2019-12-01 21:52:53 -05:00
|
|
|
|
|
|
|
// For JP version, play an identical sound for all coins.
|
2019-08-25 00:46:40 -04:00
|
|
|
#ifdef VERSION_JP
|
2019-10-05 15:08:05 -04:00
|
|
|
create_sound_spawner(SOUND_GENERAL_RED_COIN);
|
2019-08-25 00:46:40 -04:00
|
|
|
#endif
|
2019-12-01 21:52:53 -05:00
|
|
|
// Spawn the orange number counter, as long as it isn't the last coin.
|
2019-10-05 15:08:05 -04:00
|
|
|
if (o->parentObj->oHiddenStarTriggerCounter != 8) {
|
2019-12-01 21:52:53 -05:00
|
|
|
spawn_orange_number(o->parentObj->oHiddenStarTriggerCounter, 0, 0, 0);
|
2019-08-25 00:46:40 -04:00
|
|
|
}
|
|
|
|
|
2019-12-01 21:52:53 -05:00
|
|
|
// On all versions but the JP version, each coin collected plays a higher noise.
|
2019-08-25 00:46:40 -04:00
|
|
|
#ifndef VERSION_JP
|
2019-10-05 15:08:05 -04:00
|
|
|
play_sound(SOUND_MENU_COLLECT_RED_COIN
|
|
|
|
+ (((u8) o->parentObj->oHiddenStarTriggerCounter - 1) << 16),
|
2019-08-25 00:46:40 -04:00
|
|
|
gDefaultSoundArgs);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-03-01 22:42:52 -05:00
|
|
|
coin_collected();
|
2019-12-01 21:52:53 -05:00
|
|
|
// Despawn the coin.
|
2019-08-25 00:46:40 -04:00
|
|
|
o->oInteractStatus = 0;
|
|
|
|
}
|
|
|
|
}
|