Synchronized fire spitters

This commit is contained in:
MysterD 2020-09-23 09:29:46 -07:00
parent 2b5c830cc4
commit 08e8ecfc97
2 changed files with 38 additions and 5 deletions

View file

@ -1,7 +1,10 @@
static void fire_spitter_act_idle(void) {
struct Object* player = nearest_player_to_object(o);
int distanceToPlayer = dist_between_objects(o, player);
approach_f32_ptr(&o->header.gfx.scale[0], 0.2f, 0.002f);
if (o->oTimer > 150 && o->oDistanceToMario < 800.0f && !(o->oMoveFlags & OBJ_MOVE_MASK_IN_WATER)) {
if (o->oTimer > 150 && distanceToPlayer < 800.0f && !(o->oMoveFlags & OBJ_MOVE_MASK_IN_WATER)) {
o->oAction = FIRE_SPITTER_ACT_SPIT_FIRE;
o->oFireSpitterScaleVel = 0.05f;
}
@ -10,7 +13,10 @@ static void fire_spitter_act_idle(void) {
static void fire_spitter_act_spit_fire(void) {
s32 scaleStatus;
o->oMoveAngleYaw = o->oAngleToMario;
struct Object* player = nearest_player_to_object(o);
int angleToPlayer = obj_angle_to_object(o, player);
o->oMoveAngleYaw = angleToPlayer;
// Increase scale by 0.05, 0.04, ..., -0.03. Then wait ~8 frames, then
// starting moving scale by 0.05 each frame toward 0.1. The first time
@ -20,13 +26,37 @@ static void fire_spitter_act_spit_fire(void) {
if (scaleStatus < 0) {
o->oAction = FIRE_SPITTER_ACT_IDLE;
} else {
if (network_owns_object(o)) {
cur_obj_play_sound_2(SOUND_OBJ_FLAME_BLOWN);
obj_spit_fire(0, 0, 0, 5.0f, MODEL_RED_FLAME_SHADOW, 20.0f, 15.0f, 0x1000);
struct Object* fire = obj_spit_fire(0, 0, 0, 5.0f, MODEL_RED_FLAME_SHADOW, 20.0f, 15.0f, 0x1000);
struct Object* spawn_objects[] = { fire };
u32 models[] = { MODEL_RED_FLAME_SHADOW };
network_send_spawn_objects(spawn_objects, models, 1);
network_send_object(o);
}
}
}
}
static void bhv_fire_spitter_on_received_post(u8 localIndex) {
cur_obj_play_sound_2(SOUND_OBJ_FLAME_BLOWN);
}
void bhv_fire_spitter_update(void) {
if (!network_sync_object_initialized(o)) {
struct SyncObject* so = network_init_object(o, SYNC_DISTANCE_ONLY_EVENTS);
so->on_received_post = bhv_fire_spitter_on_received_post;
network_init_object_field(o, &o->oAction);
network_init_object_field(o, &o->oPrevAction);
network_init_object_field(o, &o->oTimer);
network_init_object_field(o, &o->oFireSpitterScaleVel);
network_init_object_field(o, &o->header.gfx.scale[0]);
network_init_object_field(o, &o->header.gfx.scale[1]);
network_init_object_field(o, &o->header.gfx.scale[2]);
}
cur_obj_scale(o->header.gfx.scale[0]);
o->oGraphYOffset = 40.0f;
cur_obj_update_floor_and_walls();

View file

@ -1,6 +1,9 @@
// flame.inc.c
void bhv_small_piranha_flame_loop(void) {
struct Object* player = nearest_player_to_object(o);
int angleToPlayer = obj_angle_to_object(o, player);
f32 sp2C;
if ((u16)(o->oBehParams >> 16) == 0) {
@ -16,7 +19,7 @@ void bhv_small_piranha_flame_loop(void) {
} else {
cur_obj_update_floor_and_walls();
if (approach_f32_ptr(&o->oSmallPiranhaFlameUnkF4, o->oSmallPiranhaFlameUnkF8, 0.6f)) {
cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x200);
cur_obj_rotate_yaw_toward(angleToPlayer, 0x200);
}
obj_compute_vel_from_move_pitch(o->oSmallPiranhaFlameUnkF4);