sm64

A Super Mario 64 decompilation
Log | Files | Refs | README | LICENSE

ttc_rotating_solid.inc.c (2736B)


      1 
      2 /**
      3  * Behavior for bhvTTCRotatingSolid, which are the rotating cube and triangular
      4  * prism.
      5  */
      6 
      7 /**
      8  * The collision models for cube and triangular prism, respectively.
      9  */
     10 static Collision const *sTTCRotatingSolidCollisionModels[] = {
     11     ttc_seg7_collision_07014F70,
     12     ttc_seg7_collision_07015008,
     13 };
     14 
     15 /**
     16  * The number of frames to wait before rotating for the first time.
     17  */
     18 static u8 sTTCRotatingSolidInitialDelays[] = {
     19     /* TTC_SPEED_SLOW    */ 120,
     20     /* TTC_SPEED_FAST    */ 40,
     21     /* TTC_SPEED_RANDOM  */ 0,
     22     /* TTC_SPEED_STOPPED */ 0,
     23 };
     24 
     25 /**
     26  * Init function for bhvTTCRotatingSolid.
     27  */
     28 void bhv_ttc_rotating_solid_init(void) {
     29     o->collisionData = segmented_to_virtual(sTTCRotatingSolidCollisionModels[o->oBhvParams2ndByte]);
     30 
     31     o->oTTCRotatingSolidNumSides = o->oBhvParams2ndByte == TTC_ROTATING_SOLID_BP_CUBE ? 4 : 3;
     32 
     33     o->oTTCRotatingSolidRotationDelay = sTTCRotatingSolidInitialDelays[gTTCSpeedSetting];
     34 }
     35 
     36 /**
     37  * Update function for bhvTTCRotatingSolid.
     38  * Wait a bit, dip down and back up, play a sound, then rotate.
     39  */
     40 void bhv_ttc_rotating_solid_update(void) {
     41     // 1. Wait out the rotation delay
     42     if (gTTCSpeedSetting != TTC_SPEED_STOPPED && o->oTimer > o->oTTCRotatingSolidRotationDelay) {
     43         if (o->oTTCRotatingSolidSoundTimer != 0) {
     44             // 3. Play a sound after 6 frames
     45             if (--o->oTTCRotatingSolidSoundTimer == 0) {
     46                 cur_obj_play_sound_2(SOUND_GENERAL2_ROTATING_BLOCK_ALERT);
     47             }
     48         } else if (o->oTTCRotatingSolidVelY > 0.0f && o->oPosY >= o->oHomeY) {
     49             // 4. Rotate
     50             s32 targetRoll =
     51                 (s32)((f32) o->oTTCRotatingSolidNumTurns / o->oTTCRotatingSolidNumSides * 0x10000);
     52             s32 startRoll = o->oFaceAngleRoll;
     53 
     54             obj_face_roll_approach(targetRoll, 1200);
     55 
     56             o->oAngleVelRoll = o->oFaceAngleRoll - startRoll;
     57             if (o->oAngleVelRoll == 0) {
     58                 cur_obj_play_sound_2(SOUND_GENERAL2_ROTATING_BLOCK_CLICK);
     59 
     60                 o->oTTCRotatingSolidNumTurns =
     61                     (o->oTTCRotatingSolidNumTurns + 1) % o->oTTCRotatingSolidNumSides;
     62 
     63                 o->oTimer = 0;
     64                 if (gTTCSpeedSetting == TTC_SPEED_RANDOM) {
     65                     o->oTTCRotatingSolidRotationDelay = random_mod_offset(5, 20, 7);
     66                 }
     67             }
     68         } else {
     69             // 2. Move vertically with vel -4.5, -4.0, ... until reached back home
     70             o->oTTCRotatingSolidVelY += 0.5f;
     71             if ((o->oPosY += o->oTTCRotatingSolidVelY) >= o->oHomeY) {
     72                 o->oPosY = o->oHomeY;
     73                 o->oTTCRotatingSolidSoundTimer = 6;
     74             }
     75         }
     76     } else {
     77         o->oTTCRotatingSolidVelY = -5.0f;
     78     }
     79 }