sm64pc/src/game/behaviors/butterfly.inc.c

113 lines
3.2 KiB
C
Raw Normal View History

2019-08-25 04:46:40 +00:00
// butterfly.c.inc
void bhv_butterfly_init(void) {
2020-03-02 03:42:52 +00:00
cur_obj_init_animation(1);
2019-08-25 04:46:40 +00:00
2020-04-03 18:57:26 +00:00
o->oButterflyYPhase = random_float() * 100.0f;
o->header.gfx.unk38.animFrame = random_float() * 7.0f;
2019-08-25 04:46:40 +00:00
o->oHomeX = o->oPosX;
o->oHomeY = o->oPosY;
o->oHomeZ = o->oPosZ;
}
// sp28 = speed
2020-03-02 03:42:52 +00:00
void butterfly_step(s32 speed) {
2019-08-25 04:46:40 +00:00
struct FloorGeometry *sp24;
s16 yaw = o->oMoveAngleYaw;
s16 pitch = o->oMoveAnglePitch;
s16 yPhase = o->oButterflyYPhase;
f32 floorY;
o->oVelX = sins(yaw) * (f32) speed;
o->oVelY = sins(pitch) * (f32) speed;
o->oVelZ = coss(yaw) * (f32) speed;
o->oPosX += o->oVelX;
o->oPosZ += o->oVelZ;
if (o->oAction == BUTTERFLY_ACT_FOLLOW_MARIO)
2020-02-03 05:51:26 +00:00
o->oPosY -= o->oVelY + coss((s32)(yPhase * 655.36)) * 20.0f / 4;
2019-08-25 04:46:40 +00:00
else
o->oPosY -= o->oVelY;
floorY = find_floor_height_and_data(o->oPosX, o->oPosY, o->oPosZ, &sp24);
if (o->oPosY < floorY + 2.0f)
o->oPosY = floorY + 2.0f;
o->oButterflyYPhase++;
if (o->oButterflyYPhase >= 101)
o->oButterflyYPhase = 0;
}
2020-03-02 03:42:52 +00:00
void butterfly_calculate_angle(void) {
2019-08-25 04:46:40 +00:00
gMarioObject->oPosX += 5 * o->oButterflyYPhase / 4;
gMarioObject->oPosZ += 5 * o->oButterflyYPhase / 4;
obj_turn_toward_object(o, gMarioObject, 16, 0x300);
gMarioObject->oPosX -= 5 * o->oButterflyYPhase / 4;
gMarioObject->oPosZ -= 5 * o->oButterflyYPhase / 4;
gMarioObject->oPosY += (5 * o->oButterflyYPhase + 0x100) / 4;
obj_turn_toward_object(o, gMarioObject, 15, 0x500);
gMarioObject->oPosY -= (5 * o->oButterflyYPhase + 0x100) / 4;
}
2020-03-02 03:42:52 +00:00
void butterfly_act_rest(void) {
2019-08-25 04:46:40 +00:00
if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 1000)) {
2020-03-02 03:42:52 +00:00
cur_obj_init_animation(0);
2019-08-25 04:46:40 +00:00
o->oAction = BUTTERFLY_ACT_FOLLOW_MARIO;
o->oMoveAngleYaw = gMarioObject->header.gfx.angle[1];
}
}
2020-03-02 03:42:52 +00:00
void butterfly_act_follow_mario(void) {
butterfly_calculate_angle();
2019-08-25 04:46:40 +00:00
2020-03-02 03:42:52 +00:00
butterfly_step(7);
2019-08-25 04:46:40 +00:00
if (!is_point_within_radius_of_mario(o->oHomeX, o->oHomeY, o->oHomeZ, 1200))
o->oAction = BUTTERFLY_ACT_RETURN_HOME;
}
2020-03-02 03:42:52 +00:00
void butterfly_act_return_home(void) {
2019-08-25 04:46:40 +00:00
f32 homeDistX = o->oHomeX - o->oPosX;
f32 homeDistY = o->oHomeY - o->oPosY;
f32 homeDistZ = o->oHomeZ - o->oPosZ;
s16 hAngleToHome = atan2s(homeDistZ, homeDistX);
s16 vAngleToHome = atan2s(sqrtf(homeDistX * homeDistX + homeDistZ * homeDistZ), -homeDistY);
o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, hAngleToHome, 0x800);
o->oMoveAnglePitch = approach_s16_symmetric(o->oMoveAnglePitch, vAngleToHome, 0x50);
2020-03-02 03:42:52 +00:00
butterfly_step(7);
2019-08-25 04:46:40 +00:00
if (homeDistX * homeDistX + homeDistY * homeDistY + homeDistZ * homeDistZ < 144.0f) {
2020-03-02 03:42:52 +00:00
cur_obj_init_animation(1);
2019-08-25 04:46:40 +00:00
o->oAction = BUTTERFLY_ACT_RESTING;
o->oPosX = o->oHomeX;
o->oPosY = o->oHomeY;
o->oPosZ = o->oHomeZ;
}
}
void bhv_butterfly_loop(void) {
switch (o->oAction) {
case BUTTERFLY_ACT_RESTING:
2020-03-02 03:42:52 +00:00
butterfly_act_rest();
2019-08-25 04:46:40 +00:00
break;
case BUTTERFLY_ACT_FOLLOW_MARIO:
2020-03-02 03:42:52 +00:00
butterfly_act_follow_mario();
2019-08-25 04:46:40 +00:00
break;
case BUTTERFLY_ACT_RETURN_HOME:
2020-03-02 03:42:52 +00:00
butterfly_act_return_home();
2019-08-25 04:46:40 +00:00
break;
}
2019-12-02 02:52:53 +00:00
set_object_visibility(o, 3000);
2019-08-25 04:46:40 +00:00
}