Path: blob/master/src/game/behaviors/blue_fish.inc.c
7861 views
/**1* @file blue_fish.inc.c2* Implements behaviour and spawning for bhvBlueFish located in the castle aquarium outside of SA.3*/45/**6* Determines fish movement.7*/8void bhv_blue_fish_movement_loop(void) {9f32 randomSwitch;10switch (o->oAction) {11// Initial dive phase after spawning12case BLUE_FISH_ACT_DIVE:13cur_obj_init_animation_with_accel_and_sound(0, 1.0f);1415// Assigns random values to variables that help determine natural motion.16if (o->oTimer == 0) {17o->oBlueFishRandomAngle = random_sign() << 11;18o->oBlueFishRandomVel = random_float() * 2;19o->oBlueFishRandomTime = (s32)(random_float() * 30) & 0xFE;2021// Adjusts pitch velocity or sets to zero dependant on outcome of randomSwitch.22randomSwitch = random_float() * 5;23if (randomSwitch < 2.0f) {24o->oAngleVelPitch = random_f32_around_zero(128);25} else {26o->oAngleVelPitch = 0;27}28}2930// Set forward velocity and progress oAction to BLUE_FISH_ACT_TURN.31o->oForwardVel = o->oBlueFishRandomVel + 3.0f;32if (o->oTimer >= o->oBlueFishRandomTime + 60) {33o->oAction++;34}3536// Set pitch velocity37if (o->oTimer < (o->oBlueFishRandomTime + 60) / 2) {38o->oFaceAnglePitch += o->oAngleVelPitch;39} else {40o->oFaceAnglePitch -= o->oAngleVelPitch;41}4243// Calculate new Y velocity44o->oVelY = -sins(o->oFaceAnglePitch) * o->oForwardVel;45break;46// Animates and adjusts fish yaw angle.47case BLUE_FISH_ACT_TURN:48cur_obj_init_animation_with_accel_and_sound(0, 2.0f);49o->oMoveAngleYaw = (s32)(o->oBlueFishRandomAngle + o->oMoveAngleYaw);50if (o->oTimer == 15) {51o->oAction++;52}53break;54// Animates and adjusts pitch to an upward direction.55case BLUE_FISH_ACT_ASCEND:56cur_obj_init_animation_with_accel_and_sound(0, 1.0f);5758// Progresses oAction to BLUE_FISH_ACT_TURN_BACK after elapsed time.59if (o->oTimer >= o->oBlueFishRandomTime + 60) {60o->oAction++;61}6263// Adjusts pitch angle. Direction relies on time not passed.64if (o->oTimer < (o->oBlueFishRandomTime + 60) / 2) {65o->oFaceAnglePitch -= o->oAngleVelPitch;66} else {67o->oFaceAnglePitch += o->oAngleVelPitch;68}69break;70// Animates and turns fish around71case BLUE_FISH_ACT_TURN_BACK:72cur_obj_init_animation_with_accel_and_sound(0, 2.0f);73o->oMoveAngleYaw = (s32)(o->oBlueFishRandomAngle + o->oMoveAngleYaw);7475// Sets the fish back to the BLUE_FISH_ACT_DIVE phase.76if (o->oTimer == 15) {77o->oAction = BLUE_FISH_ACT_DIVE;78}79break;80}8182// Calculates Y velocity and calls physics engine.83o->oVelY = -sins(o->oFaceAnglePitch) * o->oForwardVel;84cur_obj_move_using_fvel_and_gravity();8586// Deletes object if the parent has oAction set to BLUE_FISH_ACT_DUPLICATE.87if (o->parentObj->oAction == BLUE_FISH_ACT_DUPLICATE) {88obj_mark_for_deletion(o);89}90}9192/**93* Spawns fifteen fish if Mario resides in room fifteen or seven.94* They move at random within 200.0f95*/96void bhv_tank_fish_group_loop(void) {97struct Object *fish;98s32 i;99switch (o->oAction) {100case BLUE_FISH_ACT_SPAWN:101if (gMarioCurrentRoom == 15 || gMarioCurrentRoom == 7) {102103// spawns fifteen fish and moves them within 200.0f104for (i = 0; i < 15; i++) {105fish = spawn_object_relative(0, 300, 0, -200, o, MODEL_FISH, bhvBlueFish);106obj_translate_xyz_random(fish, 200.0f);107}108109// Proceed to BLUE_FISH_ACT_ROOM phase.110o->oAction++;111}112break;113114// Sets next oAction phase if Mario is not in rooms fifteen and seven.115case BLUE_FISH_ACT_ROOM:116if (gMarioCurrentRoom != 15 && gMarioCurrentRoom != 7) {117o->oAction++;118}119break;120121// Sets oAction to the BLUE_FISH_ACT_SPAWN phase.122case BLUE_FISH_ACT_DUPLICATE:123o->oAction = BLUE_FISH_ACT_SPAWN;124break;125}126}127128129