sm64pc/src/game/behaviors/red_coin.inc.c

82 lines
2.7 KiB
C
Raw Normal View History

2019-12-02 02:52:53 +00: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 04:46:40 +00:00
2019-12-02 02:52:53 +00:00
/**
* Red coin's hitbox details.
*/
2019-08-25 04:46:40 +00: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-02 02:52:53 +00:00
/**
* Red coin initialization function. Sets the coin's hitbox and parent object.
*/
2019-08-25 04:46:40 +00:00
void bhv_red_coin_init(void) {
2019-12-02 02:52:53 +00: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 04:46:40 +00:00
2019-12-02 02:52:53 +00:00
struct Object *hiddenRedCoinStar;
// Set the red coins to have a parent of the closest red coin star.
2020-03-02 03:42:52 +00:00
hiddenRedCoinStar = cur_obj_nearest_object_with_behavior(bhvHiddenRedCoinStar);
2019-12-02 02:52:53 +00:00
if (hiddenRedCoinStar != NULL)
o->parentObj = hiddenRedCoinStar;
2019-08-25 04:46:40 +00:00
else {
2020-03-02 03:42:52 +00:00
hiddenRedCoinStar = cur_obj_nearest_object_with_behavior(bhvBowserCourseRedCoinStar);
2019-12-02 02:52:53 +00:00
if (hiddenRedCoinStar != NULL) {
o->parentObj = hiddenRedCoinStar;
} else {
2019-08-25 04:46:40 +00:00
o->parentObj = NULL;
2019-12-02 02:52:53 +00:00
}
2019-08-25 04:46:40 +00:00
}
2020-03-02 03:42:52 +00:00
obj_set_hitbox(o, &sRedCoinHitbox);
2019-08-25 04:46:40 +00:00
}
2019-12-02 02:52:53 +00:00
/**
* Main behavior for red coins. Primarily controls coin collection noise and spawning
* the orange number counter.
*/
2019-08-25 04:46:40 +00:00
void bhv_red_coin_loop(void) {
2019-12-02 02:52:53 +00:00
// If Mario interacted with the object...
2019-08-25 04:46:40 +00:00
if (o->oInteractStatus & INT_STATUS_INTERACTED) {
2019-12-02 02:52:53 +00:00
// ...and there is a red coin star in the level...
2019-08-25 04:46:40 +00:00
if (o->parentObj != NULL) {
2019-12-02 02:52:53 +00:00
// ...increment the star's counter.
2019-10-05 19:08:05 +00:00
o->parentObj->oHiddenStarTriggerCounter++;
2019-12-02 02:52:53 +00:00
// For JP version, play an identical sound for all coins.
2019-08-25 04:46:40 +00:00
#ifdef VERSION_JP
2019-10-05 19:08:05 +00:00
create_sound_spawner(SOUND_GENERAL_RED_COIN);
2019-08-25 04:46:40 +00:00
#endif
2019-12-02 02:52:53 +00:00
// Spawn the orange number counter, as long as it isn't the last coin.
2019-10-05 19:08:05 +00:00
if (o->parentObj->oHiddenStarTriggerCounter != 8) {
2019-12-02 02:52:53 +00:00
spawn_orange_number(o->parentObj->oHiddenStarTriggerCounter, 0, 0, 0);
2019-08-25 04:46:40 +00:00
}
2019-12-02 02:52:53 +00:00
// On all versions but the JP version, each coin collected plays a higher noise.
2019-08-25 04:46:40 +00:00
#ifndef VERSION_JP
2019-10-05 19:08:05 +00:00
play_sound(SOUND_MENU_COLLECT_RED_COIN
+ (((u8) o->parentObj->oHiddenStarTriggerCounter - 1) << 16),
2019-08-25 04:46:40 +00:00
gDefaultSoundArgs);
#endif
}
2020-03-02 03:42:52 +00:00
coin_collected();
2019-12-02 02:52:53 +00:00
// Despawn the coin.
2019-08-25 04:46:40 +00:00
o->oInteractStatus = 0;
}
}