blue_fish.inc.c (4589B)
1 2 /** 3 * @file blue_fish.inc.c 4 * Implements behaviour and spawning for bhvBlueFish located in the castle aquarium outside of SA. 5 */ 6 7 /** 8 * Determines fish movement. 9 */ 10 void bhv_blue_fish_movement_loop(void) { 11 f32 randomSwitch; 12 13 switch (o->oAction) { 14 // Initial dive phase after spawning 15 case BLUE_FISH_ACT_DIVE: 16 cur_obj_init_animation_with_accel_and_sound(0, 1.0f); 17 18 // Assigns random values to variables that help determine natural motion. 19 if (o->oTimer == 0) { 20 o->oBlueFishRandomAngle = random_sign() * 0x800; 21 o->oBlueFishRandomVel = random_float() * 2; 22 o->oBlueFishRandomTime = (s32)(random_float() * 30) & 0xFE; 23 24 // Adjusts pitch velocity or sets to zero dependant on outcome of randomSwitch. 25 randomSwitch = random_float() * 5; 26 if (randomSwitch < 2.0f) { 27 o->oAngleVelPitch = random_f32_around_zero(128); 28 } else { 29 o->oAngleVelPitch = 0; 30 } 31 } 32 33 // Set forward velocity and progress oAction to BLUE_FISH_ACT_TURN. 34 o->oForwardVel = o->oBlueFishRandomVel + 3.0f; 35 if (o->oTimer >= o->oBlueFishRandomTime + 60) { 36 o->oAction++; 37 } 38 39 // Set pitch velocity 40 if (o->oTimer < (o->oBlueFishRandomTime + 60) / 2) { 41 o->oFaceAnglePitch += o->oAngleVelPitch; 42 } else { 43 o->oFaceAnglePitch -= o->oAngleVelPitch; 44 } 45 46 // Calculate new Y velocity 47 o->oVelY = -sins(o->oFaceAnglePitch) * o->oForwardVel; 48 break; 49 50 // Animates and adjusts fish yaw angle. 51 case BLUE_FISH_ACT_TURN: 52 cur_obj_init_animation_with_accel_and_sound(0, 2.0f); 53 o->oMoveAngleYaw = (s32)(o->oBlueFishRandomAngle + o->oMoveAngleYaw); 54 if (o->oTimer == 15) { 55 o->oAction++; 56 } 57 break; 58 59 // Animates and adjusts pitch to an upward direction. 60 case BLUE_FISH_ACT_ASCEND: 61 cur_obj_init_animation_with_accel_and_sound(0, 1.0f); 62 63 // Progresses oAction to BLUE_FISH_ACT_TURN_BACK after elapsed time. 64 if (o->oTimer >= o->oBlueFishRandomTime + 60) { 65 o->oAction++; 66 } 67 68 // Adjusts pitch angle. Direction relies on time not passed. 69 if (o->oTimer < (o->oBlueFishRandomTime + 60) / 2) { 70 o->oFaceAnglePitch -= o->oAngleVelPitch; 71 } else { 72 o->oFaceAnglePitch += o->oAngleVelPitch; 73 } 74 break; 75 76 // Animates and turns fish around 77 case BLUE_FISH_ACT_TURN_BACK: 78 cur_obj_init_animation_with_accel_and_sound(0, 2.0f); 79 o->oMoveAngleYaw = (s32)(o->oBlueFishRandomAngle + o->oMoveAngleYaw); 80 81 // Sets the fish back to the BLUE_FISH_ACT_DIVE phase. 82 if (o->oTimer == 15) { 83 o->oAction = BLUE_FISH_ACT_DIVE; 84 } 85 break; 86 } 87 88 // Calculates Y velocity and calls physics engine. 89 o->oVelY = -sins(o->oFaceAnglePitch) * o->oForwardVel; 90 cur_obj_move_using_fvel_and_gravity(); 91 92 // Deletes object if the parent has oAction set to BLUE_FISH_ACT_DUPLICATE. 93 if (o->parentObj->oAction == BLUE_FISH_ACT_DUPLICATE) { 94 obj_mark_for_deletion(o); 95 } 96 } 97 98 /** 99 * Spawns fifteen fish if Mario resides in room fifteen or seven. 100 * They move at random within 200.0f 101 */ 102 void bhv_tank_fish_group_loop(void) { 103 struct Object *fish; 104 s32 i; 105 106 switch (o->oAction) { 107 case BLUE_FISH_ACT_SPAWN: 108 if (gMarioCurrentRoom == 15 || gMarioCurrentRoom == 7) { 109 110 // spawns fifteen fish and moves them within 200.0f 111 for (i = 0; i < 15; i++) { 112 fish = spawn_object_relative(0, 300, 0, -200, o, MODEL_FISH, bhvBlueFish); 113 obj_translate_xyz_random(fish, 200.0f); 114 } 115 116 // Proceed to BLUE_FISH_ACT_ROOM phase. 117 o->oAction++; 118 } 119 break; 120 121 // Sets next oAction phase if Mario is not in rooms fifteen and seven. 122 case BLUE_FISH_ACT_ROOM: 123 if (gMarioCurrentRoom != 15 && gMarioCurrentRoom != 7) { 124 o->oAction++; 125 } 126 break; 127 128 // Sets oAction to the BLUE_FISH_ACT_SPAWN phase. 129 case BLUE_FISH_ACT_DUPLICATE: 130 o->oAction = BLUE_FISH_ACT_SPAWN; 131 break; 132 } 133 }