Path: blob/master/src/game/behaviors/blue_coin.inc.c
7861 views
/**1* Behavior for bhvHiddenBlueCoin and bhvBlueCoinSwitch.2* bhvHiddenBlueCoin are the stationary blue coins that appear when3* you press a blue coin switch (a.k.a. bhvBlueCoinSwitch).4*/56/**7* Update function for bhvHiddenBlueCoin.8*/9void bhv_hidden_blue_coin_loop(void) {10struct Object *blueCoinSwitch;1112switch (o->oAction) {13case HIDDEN_BLUE_COIN_ACT_INACTIVE:14// Become invisible and intangible15if (configRespawnCertainItems) {16cur_obj_hide();17}18else {19cur_obj_disable_rendering();20}21cur_obj_become_intangible();2223// Set action to HIDDEN_BLUE_COIN_ACT_WAITING after the blue coin switch is found.24o->oHiddenBlueCoinSwitch = cur_obj_nearest_object_with_behavior(bhvBlueCoinSwitch);2526if (o->oHiddenBlueCoinSwitch != NULL) {27o->oAction++;28}2930break;31case HIDDEN_BLUE_COIN_ACT_WAITING:32// Wait until the blue coin switch starts ticking to activate.33blueCoinSwitch = o->oHiddenBlueCoinSwitch;3435if (blueCoinSwitch->oAction == BLUE_COIN_SWITCH_ACT_TICKING) {36o->oAction++; // Set to HIDDEN_BLUE_COIN_ACT_ACTIVE37}3839break;40case HIDDEN_BLUE_COIN_ACT_ACTIVE:41// Become tangible42if (configRespawnCertainItems) {43cur_obj_unhide();44}45else {46cur_obj_enable_rendering();47}48cur_obj_become_tangible();4950// Delete the coin once collected51if (o->oInteractStatus & INT_STATUS_INTERACTED) {52spawn_object(o, MODEL_SPARKLES, bhvGoldenCoinSparkles);53obj_mark_for_deletion(o);54}5556// After 200 frames of waiting and 20 2-frame blinks (for 240 frames total),57// delete the object.58if (cur_obj_wait_then_blink(200, 20)) {59if (configRespawnCertainItems) {60o->oAction = HIDDEN_BLUE_COIN_ACT_INACTIVE;61}62else {63obj_mark_for_deletion(o);64}65}6667break;68}6970o->oInteractStatus = 0;71}7273/**74* Update function for bhvBlueCoinSwitch.75*/76void bhv_blue_coin_switch_loop(void) {77// The switch's model is 1/3 size.78cur_obj_scale(3.0f);7980switch (o->oAction) {81case BLUE_COIN_SWITCH_ACT_IDLE:82// If Mario is on the switch and has ground-pounded,83// recede and get ready to start ticking.84if (gMarioObject->platform == o) {85if (gMarioStates[0].action == ACT_GROUND_POUND_LAND) {86// Set to BLUE_COIN_SWITCH_ACT_RECEDING87o->oAction++;8889// Recede at a rate of 20 units/frame.90o->oVelY = -20.0f;91// Set gravity to 0 so it doesn't accelerate when receding.92o->oGravity = 0.0f;9394cur_obj_play_sound_2(SOUND_GENERAL_SWITCH_DOOR_OPEN);95}96}9798// Have collision99load_object_collision_model();100101break;102case BLUE_COIN_SWITCH_ACT_RECEDING:103// Recede for 6 frames before going invisible and ticking.104// This is probably an off-by-one error, since the switch is 100 units tall105// and recedes at 20 units/frame, which means it will fully recede after 5 frames.106if (o->oTimer > 5) {107cur_obj_hide();108109// Set to BLUE_COIN_SWITCH_ACT_TICKING110o->oAction++;111// ???112if (!configRespawnCertainItems) {113o->oPosY = gMarioObject->oPosY - 40.0f;114}115116// Spawn particles. There's a function that calls this same function117// with the same arguments, spawn_mist_particles, why didn't they just call that?118spawn_mist_particles_variable(0, 0, 46.0f);119} else {120// Have collision while receding121load_object_collision_model();122// Recede123cur_obj_move_using_fvel_and_gravity();124}125126break;127case BLUE_COIN_SWITCH_ACT_TICKING:128// Tick faster when the blue coins start blinking129if (o->oTimer < 200) {130play_sound(SOUND_GENERAL2_SWITCH_TICK_FAST, gGlobalSoundSource);131} else {132play_sound(SOUND_GENERAL2_SWITCH_TICK_SLOW, gGlobalSoundSource);133}134135// Delete the switch (which stops the sound) after the last coin is collected,136// or after the coins unload after the 240-frame timer expires.137if (cur_obj_nearest_object_with_behavior(bhvHiddenBlueCoin) == NULL || o->oTimer > 240) {138if (configRespawnCertainItems && o->oTimer > 240) {139cur_obj_unhide();140o->oAction = BLUE_COIN_SWITCH_ACT_IDLE;141o->oPosY = o->oPosY + 120.0f;142}143else {144obj_mark_for_deletion(o);145}146}147148break;149}150}151152153