ttc_pit_block.inc.c (2094B)
1 2 /** 3 * Behavior for bhvTTCPitBlock. This is the block that moves up and down near the 4 * Pit and the Pendulum star. 5 */ 6 7 /** 8 * Collision models. The second one is unused. 9 */ 10 static Collision const *sTTCPitBlockCollisionModels[] = { 11 ttc_seg7_collision_07015754, 12 ttc_seg7_collision_070157D8, 13 }; 14 15 /** 16 * The speed of movement, and the time to wait before moving. 17 * If the wait time is negative (before moving down on random setting), wait 18 * a random amount of time instead. 19 */ 20 struct TTCPitBlockProperties { 21 s16 speed; 22 s16 waitTime; 23 }; 24 25 /** 26 * Properties for the pit block on each speed setting when moving up and down, 27 * respectively. 28 */ 29 static struct TTCPitBlockProperties sTTCPitBlockProperties[][2] = { 30 /* TTC_SPEED_SLOW */ { { 11, 20 }, { -9, 30 } }, 31 /* TTC_SPEED_FAST */ { { 18, 15 }, { -11, 15 } }, 32 /* TTC_SPEED_RANDOM */ { { 11, 20 }, { -9, -1 } }, 33 /* TTC_SPEED_STOPPED */ { { 0, 0 }, { 0, 0 } }, 34 }; 35 36 /** 37 * Init function for bhvTTCPitBlock. 38 */ 39 void bhv_ttc_pit_block_init(void) { 40 o->collisionData = segmented_to_virtual(sTTCPitBlockCollisionModels[o->oBhvParams2ndByte]); 41 42 o->oTTCPitBlockPeakY = o->oPosY + 330.0f; 43 44 if (gTTCSpeedSetting == TTC_SPEED_STOPPED) { 45 o->oPosY += 330.0f; 46 } 47 } 48 49 /** 50 * Update function for bhvTTCPitBlock. 51 * Move up and down, pausing before changing direction. 52 */ 53 void bhv_ttc_pit_block_update(void) { 54 if (o->oTimer > o->oTTCPitBlockWaitTime) { 55 // Forward vel and gravity are zero, so this just does posY += velY 56 cur_obj_move_using_fvel_and_gravity(); 57 58 if (clamp_f32(&o->oPosY, o->oHomeY, o->oTTCPitBlockPeakY)) { 59 o->oTTCPitBlockDir = o->oTTCPitBlockDir ^ 0x01; 60 61 if ((o->oTTCPitBlockWaitTime = 62 sTTCPitBlockProperties[gTTCSpeedSetting][o->oTTCPitBlockDir & 0x01].waitTime) 63 < 0) { 64 o->oTTCPitBlockWaitTime = random_mod_offset(10, 20, 6); 65 } 66 67 o->oVelY = sTTCPitBlockProperties[gTTCSpeedSetting][o->oTTCPitBlockDir].speed; 68 o->oTimer = 0; 69 } 70 } 71 }