pyramid_elevator.inc.c (2758B)
1 2 /** 3 * Behaviors for bhvPyramidElevator and bhvPyramidElevatorTrajectoryMarkerBall. 4 * 5 * This controls the elevator that descends Shifting Sand Land's pyramid, as 6 * well as the small marker balls that demarcate its trajactory. 7 */ 8 9 /** 10 * Generate the ten trajectory marker balls that indicate where the elevator 11 * moves. 12 */ 13 void bhv_pyramid_elevator_init(void) { 14 s32 i; 15 16 for (i = 0; i < 10; i++) { 17 struct Object *ball = spawn_object(o, MODEL_TRAJECTORY_MARKER_BALL, 18 bhvPyramidElevatorTrajectoryMarkerBall); 19 ball->oPosY = 4600 - i * 460; 20 } 21 } 22 23 void bhv_pyramid_elevator_loop(void) { 24 switch (o->oAction) { 25 /** 26 * Do not move until Mario stands on the elevator. When he does, 27 * transition to the starting state. 28 */ 29 case PYRAMID_ELEVATOR_ACT_IDLE: 30 if (gMarioObject->platform == o) { 31 o->oAction = PYRAMID_ELEVATOR_ACT_START_MOVING; 32 } 33 break; 34 35 /** 36 * Use a sine wave to start the elevator's movement with a small jolt. 37 * After a certain amount of time, transition to a constant-velocity state. 38 */ 39 case PYRAMID_ELEVATOR_ACT_START_MOVING: 40 o->oPosY = o->oHomeY - sins(o->oTimer * 0x1000) * 10.0f; 41 if (o->oTimer == 8) { 42 o->oAction = PYRAMID_ELEVATOR_ACT_CONSTANT_VELOCITY; 43 } 44 break; 45 46 /** 47 * Move downwards with constant velocity. Once at the bottom of the 48 * track, transition to the final state. 49 */ 50 case PYRAMID_ELEVATOR_ACT_CONSTANT_VELOCITY: 51 o->oVelY = -10.0f; 52 o->oPosY += o->oVelY; 53 if (o->oPosY < 128.0f) { 54 o->oPosY = 128.0f; 55 o->oAction = PYRAMID_ELEVATOR_ACT_AT_BOTTOM; 56 } 57 break; 58 59 /** 60 * Use a sine wave to stop the elevator's movement with a small jolt. 61 * Then, remain at the bottom of the track. 62 */ 63 case PYRAMID_ELEVATOR_ACT_AT_BOTTOM: 64 o->oPosY = sins(o->oTimer * 0x1000) * 10.0f + 128.0f; 65 if (o->oTimer >= 8) { 66 o->oVelY = 0; 67 o->oPosY = 128.0f; 68 } 69 break; 70 } 71 } 72 73 /** 74 * Deactivate the trajectory marker balls if the elevator is not moving. 75 * Otherwise, set their scale. 76 */ 77 void bhv_pyramid_elevator_trajectory_marker_ball_loop(void) { 78 struct Object *elevator; 79 80 cur_obj_scale(0.15f); 81 elevator = cur_obj_nearest_object_with_behavior(bhvPyramidElevator); 82 83 if (elevator != NULL) { 84 if (elevator->oAction != PYRAMID_ELEVATOR_ACT_IDLE) { 85 o->activeFlags = ACTIVE_FLAG_DEACTIVATED; 86 } 87 } 88 }