purple_switch.inc.c (3068B)
1 2 /** 3 * Behavior for bhvFloorSwitchHardcodedModel, bhvFloorSwitchGrills, and 4 * bhvFloorSwitchAnimatesObject. 5 * 6 * This controls the purple switches that Mario can step on to affect parts of 7 * the environment. 8 */ 9 10 void bhv_purple_switch_loop(void) { 11 UNUSED u8 filler[4]; 12 13 switch (o->oAction) { 14 /** 15 * Set the switch's model and scale. If Mario is standing near the 16 * switch's middle section, transition to the pressed state. 17 */ 18 case PURPLE_SWITCH_ACT_IDLE: 19 cur_obj_set_model(MODEL_PURPLE_SWITCH); 20 cur_obj_scale(1.5f); 21 if (gMarioObject->platform == o && !(gMarioStates[0].action & MARIO_UNKNOWN_13)) { 22 if (lateral_dist_between_objects(o, gMarioObject) < 127.5) { 23 o->oAction = PURPLE_SWITCH_ACT_PRESSED; 24 } 25 } 26 break; 27 28 /** 29 * Collapse the switch downward, play a sound, and shake the screen. 30 * Immediately transition to the ticking state. 31 */ 32 case PURPLE_SWITCH_ACT_PRESSED: 33 cur_obj_scale_over_time(2, 3, 1.5f, 0.2f); 34 if (o->oTimer == 3) { 35 cur_obj_play_sound_2(SOUND_GENERAL2_PURPLE_SWITCH); 36 o->oAction = PURPLE_SWITCH_ACT_TICKING; 37 cur_obj_shake_screen(SHAKE_POS_SMALL); 38 #if ENABLE_RUMBLE 39 queue_rumble_data(5, 80); 40 #endif 41 } 42 break; 43 44 /** 45 * Play a continuous ticking sound that gets faster when time is almost 46 * up. When time is up, move to a waiting-while-pressed state. 47 */ 48 case PURPLE_SWITCH_ACT_TICKING: 49 if (o->oBhvParams2ndByte != 0) { 50 if (o->oBhvParams2ndByte == 1 && gMarioObject->platform != o) { 51 o->oAction++; 52 } else { 53 if (o->oTimer < 360) { 54 play_sound(SOUND_GENERAL2_SWITCH_TICK_FAST, gGlobalSoundSource); 55 } else { 56 play_sound(SOUND_GENERAL2_SWITCH_TICK_SLOW, gGlobalSoundSource); 57 } 58 if (o->oTimer > 400) { 59 o->oAction = PURPLE_SWITCH_ACT_WAIT_FOR_MARIO_TO_GET_OFF; 60 } 61 } 62 } 63 break; 64 65 /** 66 * Make the switch look unpressed again, and transition back to the 67 * idle state. 68 */ 69 case PURPLE_SWITCH_ACT_UNPRESSED: 70 cur_obj_scale_over_time(2, 3, 0.2f, 1.5f); 71 if (o->oTimer == 3) { 72 o->oAction = PURPLE_SWITCH_ACT_IDLE; 73 } 74 break; 75 76 /** 77 * Mario is standing on the switch, but time has expired. Wait for 78 * him to get off the switch, and when he does so, transition to the 79 * unpressed state. 80 */ 81 case PURPLE_SWITCH_ACT_WAIT_FOR_MARIO_TO_GET_OFF: 82 if (!cur_obj_is_mario_on_platform()) { 83 o->oAction = PURPLE_SWITCH_ACT_UNPRESSED; 84 } 85 break; 86 } 87 }