ttc_treadmill.inc.c (2379B)
1 2 /** 3 * Behavior for bhvTTCTreadmill. 4 * The first treadmill in processing order is the "master treadmill". It is 5 * responsible for playing sounds and calling RNG to control all the other 6 * treadmills. 7 */ 8 9 /** 10 * Collision models for the different sized treadmills. 11 */ 12 static Collision const *sTTCTreadmillCollisionModels[] = { 13 ttc_seg7_collision_070152B4, 14 ttc_seg7_collision_070153E0, 15 }; 16 17 static s16 sTTCTreadmillSpeeds[] = { 18 /* TTC_SPEED_SLOW */ 50, 19 /* TTC_SPEED_FAST */ 100, 20 /* TTC_SPEED_RANDOM */ 0, 21 /* TTC_SPEED_STOPPED */ 0, 22 }; 23 24 extern s16 ttc_movtex_tris_big_surface_treadmill[]; 25 extern s16 ttc_movtex_tris_small_surface_treadmill[]; 26 27 void bhv_ttc_treadmill_init(void) { 28 o->collisionData = segmented_to_virtual( 29 sTTCTreadmillCollisionModels[o->oBhvParams2ndByte & TTC_TREADMILL_BP_FLAG_MASK]); 30 31 o->oTTCTreadmillBigSurface = segmented_to_virtual(ttc_movtex_tris_big_surface_treadmill); 32 o->oTTCTreadmillSmallSurface = segmented_to_virtual(ttc_movtex_tris_small_surface_treadmill); 33 34 *o->oTTCTreadmillBigSurface = *o->oTTCTreadmillSmallSurface = sTTCTreadmillSpeeds[gTTCSpeedSetting]; 35 36 sMasterTreadmill = NULL; 37 } 38 39 /** 40 * Update function for bhvTTCTreadmill. It calls cur_obj_compute_vel_xz afterward. 41 */ 42 void bhv_ttc_treadmill_update(void) { 43 if (sMasterTreadmill == o || sMasterTreadmill == NULL) { 44 sMasterTreadmill = o; 45 46 cur_obj_play_sound_1(SOUND_ENV_ELEVATOR2); 47 48 if (gTTCSpeedSetting == TTC_SPEED_RANDOM) { 49 // Stay still for 5 frames, then accelerate toward the target speed 50 // until it's time to switch 51 if (o->oTimer > o->oTTCTreadmillTimeUntilSwitch) { 52 // Then stop and select new target speed and time until switch 53 if (approach_f32_ptr(&o->oTTCTreadmillSpeed, 0.0f, 10.0f)) { 54 o->oTTCTreadmillTimeUntilSwitch = random_mod_offset(10, 20, 7); 55 o->oTTCTreadmillTargetSpeed = random_sign() * 50.0f; 56 o->oTimer = 0; 57 } 58 } else if (o->oTimer > 5) { 59 approach_f32_ptr(&o->oTTCTreadmillSpeed, o->oTTCTreadmillTargetSpeed, 10.0f); 60 } 61 62 *o->oTTCTreadmillBigSurface = *o->oTTCTreadmillSmallSurface = o->oTTCTreadmillSpeed; 63 } 64 } 65 66 o->oForwardVel = 0.084f * *o->oTTCTreadmillBigSurface; 67 }