From 55e80b4c69e82cca82f28f02968c484c048055ae Mon Sep 17 00:00:00 2001 From: dawnDus <96957561+dawndus@users.noreply.github.com> Date: Sat, 26 Mar 2022 11:05:56 -0400 Subject: [PATCH] Add max fall speed function for NPCs --- src/npc/ai/balrog.rs | 30 ++++++++++-------------------- src/npc/ai/characters.rs | 28 +++++++--------------------- src/npc/ai/curly.rs | 12 +++--------- src/npc/ai/doctor.rs | 12 +++--------- src/npc/ai/egg_corridor.rs | 12 +++--------- src/npc/ai/first_cave.rs | 4 +--- src/npc/ai/grasstown.rs | 24 ++++++------------------ src/npc/ai/hell.rs | 24 ++++++------------------ src/npc/ai/igor.rs | 12 +++--------- src/npc/ai/last_cave.rs | 12 +++--------- src/npc/ai/maze.rs | 12 +++--------- src/npc/ai/mimiga_village.rs | 20 +++++--------------- src/npc/ai/misc.rs | 32 ++++++++------------------------ src/npc/ai/misery.rs | 8 ++------ src/npc/ai/plantation.rs | 36 +++++++++--------------------------- src/npc/ai/quote.rs | 8 ++------ src/npc/ai/sand_zone.rs | 28 +++++++--------------------- src/npc/ai/sue.rs | 12 +++--------- src/npc/ai/toroko.rs | 12 +++--------- src/npc/boss/balfrog.rs | 4 +--- src/npc/boss/ballos.rs | 16 ++++------------ src/npc/boss/omega.rs | 16 +++++----------- src/npc/boss/undead_core.rs | 4 +--- src/npc/utils.rs | 9 +++++++++ 24 files changed, 107 insertions(+), 280 deletions(-) diff --git a/src/npc/ai/balrog.rs b/src/npc/ai/balrog.rs index 0fab50b..8020d4b 100644 --- a/src/npc/ai/balrog.rs +++ b/src/npc/ai/balrog.rs @@ -166,9 +166,7 @@ impl NPC { } self.vel_y += 0x20; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -329,9 +327,7 @@ impl NPC { } self.vel_y += 0x20; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); } 30 => { self.anim_num = 4; @@ -520,9 +516,7 @@ impl NPC { let _ = npc_list.spawn(0x100, npc); } - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -799,9 +793,7 @@ impl NPC { self.direction = if self.x < player.x { Direction::Right } else { Direction::Left }; } - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -867,8 +859,10 @@ impl NPC { self.vel_x += 0x10 * self.direction.vector_x(); let pi = self.get_closest_player_idx_mut(&players); - if self.action_counter >= 8 && (players[pi].x - self.x).abs() < 0x1800 - && self.y - 0x1800 < players[pi].y && self.y + 0x1000 > players[pi].y + if self.action_counter >= 8 + && (players[pi].x - self.x).abs() < 0x1800 + && self.y - 0x1800 < players[pi].y + && self.y + 0x1000 > players[pi].y { self.action_num = 10; self.anim_num = 5; @@ -980,9 +974,7 @@ impl NPC { self.vel_x = clamp(self.vel_x, -0x400, 0x400); self.vel_y += 0x20; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -1199,9 +1191,7 @@ impl NPC { self.vel_y += 0x20; self.vel_x = self.vel_x.clamp(-0x300, 0x300); - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; diff --git a/src/npc/ai/characters.rs b/src/npc/ai/characters.rs index 6ab6f7d..c48760c 100644 --- a/src/npc/ai/characters.rs +++ b/src/npc/ai/characters.rs @@ -63,9 +63,7 @@ impl NPC { self.vel_y += 0x20; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.y += self.vel_y; @@ -235,9 +233,7 @@ impl NPC { self.vel_y += 0x40; self.vel_x = self.vel_x.clamp(-0x400, 0x400); - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); } self.x += self.vel_x; @@ -351,9 +347,7 @@ impl NPC { self.vel_y += 0x40; self.vel_x = clamp(self.vel_x, -0x400, 0x400); - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -434,9 +428,7 @@ impl NPC { 10 => { self.anim_num = 0; self.vel_y += 0x40; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.y += self.vel_y; } 20 | 21 => { @@ -558,9 +550,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -627,9 +617,7 @@ impl NPC { } self.vel_y += 0x20; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -723,9 +711,7 @@ impl NPC { } 20 => { self.vel_y += 0x40; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.action_counter += 1; if self.action_counter > 50 { diff --git a/src/npc/ai/curly.rs b/src/npc/ai/curly.rs index 13ea0f5..1af51c0 100644 --- a/src/npc/ai/curly.rs +++ b/src/npc/ai/curly.rs @@ -114,9 +114,7 @@ impl NPC { _ => (), } - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -259,9 +257,7 @@ impl NPC { self.vel_x = clamp(self.vel_x, -0x1ff, 0x1ff); self.vel_y += 0x20; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -551,9 +547,7 @@ impl NPC { self.vel_x = self.vel_x.clamp(-0x300, 0x300); - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; diff --git a/src/npc/ai/doctor.rs b/src/npc/ai/doctor.rs index a61f326..5fcf9bf 100644 --- a/src/npc/ai/doctor.rs +++ b/src/npc/ai/doctor.rs @@ -456,9 +456,7 @@ impl NPC { state.npc_super_pos = (self.x, self.y); } - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -967,9 +965,7 @@ impl NPC { } } - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -1059,9 +1055,7 @@ impl NPC { self.vel_y += self.direction.vector_y() * 0x40; self.action_counter += 1; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; diff --git a/src/npc/ai/egg_corridor.rs b/src/npc/ai/egg_corridor.rs index 9257eae..e845cac 100644 --- a/src/npc/ai/egg_corridor.rs +++ b/src/npc/ai/egg_corridor.rs @@ -81,9 +81,7 @@ impl NPC { self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -175,9 +173,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -839,9 +835,7 @@ impl NPC { self.anim_rect = state.constants.npc.n203_critter_destroyed_egg_corridor[self.anim_num as usize + dir_offset]; self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; diff --git a/src/npc/ai/first_cave.rs b/src/npc/ai/first_cave.rs index c8477c5..1b308a5 100644 --- a/src/npc/ai/first_cave.rs +++ b/src/npc/ai/first_cave.rs @@ -149,9 +149,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; diff --git a/src/npc/ai/grasstown.rs b/src/npc/ai/grasstown.rs index 1447fb4..c80d467 100644 --- a/src/npc/ai/grasstown.rs +++ b/src/npc/ai/grasstown.rs @@ -125,9 +125,7 @@ impl NPC { if self.action_num != 4 { self.vel_y += 0x20; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); } else { self.vel_x = clamp(self.vel_x + if self.x < player.x { 0x20 } else { -0x20 }, -0x200, 0x200); self.vel_y = clamp(self.vel_y + if self.y > self.target_y { -0x10 } else { 0x10 }, -0x200, 0x200); @@ -186,9 +184,7 @@ impl NPC { } 3 => { self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); if self.flags.hit_bottom_wall() { self.vel_x *= 2; @@ -334,9 +330,7 @@ impl NPC { if self.action_num != 4 { self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); } else { self.vel_x = clamp(self.vel_x + if self.x < player.x { 0x20 } else { -0x20 }, -0x200, 0x200); self.vel_y = clamp(self.vel_y + if self.y > self.target_y { -0x10 } else { 0x10 }, -0x200, 0x200); @@ -394,9 +388,7 @@ impl NPC { } 4 => { self.vel_y += 0x20; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.action_counter += 1; if self.action_counter >= 20 && (self.flags.hit_bottom_wall() || self.y > player.y - 0x2000) { @@ -1084,9 +1076,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.y += self.vel_y; @@ -1332,9 +1322,7 @@ impl NPC { self.vel_y += if self.action_num <= 50 { 0x40 } else { 0x20 }; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; diff --git a/src/npc/ai/hell.rs b/src/npc/ai/hell.rs index f7b08fc..f08b712 100644 --- a/src/npc/ai/hell.rs +++ b/src/npc/ai/hell.rs @@ -25,9 +25,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -422,9 +420,7 @@ impl NPC { _ => (), } - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF - }; + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -475,9 +471,7 @@ impl NPC { } self.vel_y += 0x20; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -635,9 +629,7 @@ impl NPC { } self.vel_y += 0x55; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF - }; + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -686,9 +678,7 @@ impl NPC { } self.vel_y += 0x20; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -727,9 +717,7 @@ impl NPC { }; self.vel_y += 0x2A; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF - }; + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; diff --git a/src/npc/ai/igor.rs b/src/npc/ai/igor.rs index a6ea321..1983208 100644 --- a/src/npc/ai/igor.rs +++ b/src/npc/ai/igor.rs @@ -75,9 +75,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -256,9 +254,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -519,9 +515,7 @@ impl NPC { } self.vel_y += 0x33; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; diff --git a/src/npc/ai/last_cave.rs b/src/npc/ai/last_cave.rs index 4d6abc5..a0546b8 100644 --- a/src/npc/ai/last_cave.rs +++ b/src/npc/ai/last_cave.rs @@ -96,9 +96,7 @@ impl NPC { } self.vel_y += 0x55; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -206,9 +204,7 @@ impl NPC { return Ok(()); } - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.y += self.vel_y; self.anim_rect = state.constants.npc.n244_lava_drop; @@ -421,9 +417,7 @@ impl NPC { } self.vel_y += 0x20; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; diff --git a/src/npc/ai/maze.rs b/src/npc/ai/maze.rs index 957a205..f227475 100644 --- a/src/npc/ai/maze.rs +++ b/src/npc/ai/maze.rs @@ -146,9 +146,7 @@ impl NPC { self.vel_y = self.vel_y.clamp(-0x200, 0x200); } else { self.vel_y += 0x20; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); } self.x += self.vel_x; @@ -318,9 +316,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -372,9 +368,7 @@ impl NPC { } self.vel_y += 0x20; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; diff --git a/src/npc/ai/mimiga_village.rs b/src/npc/ai/mimiga_village.rs index b4cdb67..99979f9 100644 --- a/src/npc/ai/mimiga_village.rs +++ b/src/npc/ai/mimiga_village.rs @@ -83,9 +83,7 @@ impl NPC { self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -224,9 +222,7 @@ impl NPC { self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.y += self.vel_y; @@ -411,9 +407,7 @@ impl NPC { self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -704,9 +698,7 @@ impl NPC { } } - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF - }; + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -885,9 +877,7 @@ impl NPC { if self.action_counter2 > 300 { self.vanish(state); } else { - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF - }; + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; diff --git a/src/npc/ai/misc.rs b/src/npc/ai/misc.rs index e2c9d0d..ed9ca2b 100644 --- a/src/npc/ai/misc.rs +++ b/src/npc/ai/misc.rs @@ -125,9 +125,7 @@ impl NPC { self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.y += self.vel_y; @@ -181,9 +179,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.y += self.vel_y; @@ -211,9 +207,7 @@ impl NPC { self.anim_rect = state.constants.npc.n016_save_point[self.anim_num as usize]; self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.y += self.vel_y; @@ -281,9 +275,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.y += self.vel_y; @@ -603,9 +595,7 @@ impl NPC { self.anim_rect = state.constants.npc.n073_water_droplet[self.rng.range(0..4) as usize]; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -1021,9 +1011,7 @@ impl NPC { self.vel_y += 0x20; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.y += self.vel_y; @@ -1891,9 +1879,7 @@ impl NPC { if self.action_num >= 5 { self.vel_y += 0x80; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.y += self.vel_y; } @@ -2516,9 +2502,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); if self.flags.hit_bottom_wall() { self.action_num = 2; diff --git a/src/npc/ai/misery.rs b/src/npc/ai/misery.rs index 3e4b9a8..d73b35e 100644 --- a/src/npc/ai/misery.rs +++ b/src/npc/ai/misery.rs @@ -120,9 +120,7 @@ impl NPC { self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); if self.flags.hit_bottom_wall() { state.sound_manager.play_sfx(23); @@ -1202,9 +1200,7 @@ impl NPC { self.vel_y += 0x40; } - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; diff --git a/src/npc/ai/plantation.rs b/src/npc/ai/plantation.rs index e4c7b40..f594e78 100644 --- a/src/npc/ai/plantation.rs +++ b/src/npc/ai/plantation.rs @@ -106,9 +106,7 @@ impl NPC { _ => (), } self.vel_y += 0x20; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -277,9 +275,7 @@ impl NPC { self.vel_y += 0x20; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -353,9 +349,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -583,9 +577,7 @@ impl NPC { } 3 => { self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); if self.flags.hit_bottom_wall() { self.vel_y = 0; @@ -674,9 +666,7 @@ impl NPC { } self.vel_y += 0x20; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -821,9 +811,7 @@ impl NPC { } self.vel_y += 0x20; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -893,9 +881,7 @@ impl NPC { } self.vel_y += 0x20; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -1038,9 +1024,7 @@ impl NPC { } self.vel_y += 0x55; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -1092,9 +1076,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; diff --git a/src/npc/ai/quote.rs b/src/npc/ai/quote.rs index 47f7f7c..ef799dd 100644 --- a/src/npc/ai/quote.rs +++ b/src/npc/ai/quote.rs @@ -263,9 +263,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); if self.flags.hit_bottom_wall() { self.vel_y = 0; @@ -426,9 +424,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); if self.flags.hit_bottom_wall() { self.vel_y = 0; diff --git a/src/npc/ai/sand_zone.rs b/src/npc/ai/sand_zone.rs index ee49419..6fed0a0 100644 --- a/src/npc/ai/sand_zone.rs +++ b/src/npc/ai/sand_zone.rs @@ -395,9 +395,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -1030,9 +1028,7 @@ impl NPC { self.vel_x = self.vel_x.clamp(-0x200, 0x200); - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.y += self.vel_y; self.x += self.vel_x; @@ -1169,9 +1165,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -1242,9 +1236,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -1355,9 +1347,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -1515,9 +1505,7 @@ impl NPC { _ => (), } self.vel_y += 0x40; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.y += self.vel_y; let dir_offset = if self.direction == Direction::Left { 0 } else { 3 }; @@ -1616,9 +1604,7 @@ impl NPC { } } self.vel_y += 0x33; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.vel_x = clamp(self.vel_x, -0x5ff, 0x5ff); self.y += self.vel_y; diff --git a/src/npc/ai/sue.rs b/src/npc/ai/sue.rs index 4a47f16..708d55d 100644 --- a/src/npc/ai/sue.rs +++ b/src/npc/ai/sue.rs @@ -213,9 +213,7 @@ impl NPC { self.vel_y += 0x40; self.vel_x = self.vel_x.clamp(-0x400, 0x400); - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -315,9 +313,7 @@ impl NPC { if self.action_num > 1 { self.vel_y += 0x20; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.y += self.vel_y; } @@ -543,9 +539,7 @@ impl NPC { } self.vel_y += 0x20; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); } 43 => { self.action_counter += 1; diff --git a/src/npc/ai/toroko.rs b/src/npc/ai/toroko.rs index 2b8043c..efa0ccf 100644 --- a/src/npc/ai/toroko.rs +++ b/src/npc/ai/toroko.rs @@ -154,9 +154,7 @@ impl NPC { self.vel_y += 0x40; self.vel_x = self.vel_x.clamp(-0x400, 0x400); - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -258,9 +256,7 @@ impl NPC { self.vel_y += 0x40; self.vel_x = self.vel_x.clamp(-0x400, 0x400); - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -812,9 +808,7 @@ impl NPC { if self.action_num > 1 { self.vel_y += 0x20; - if self.vel_y > 0x5ff { - self.vel_y = 0x5ff; - } + self.clamp_fall_speed(); self.y += self.vel_y; } diff --git a/src/npc/boss/balfrog.rs b/src/npc/boss/balfrog.rs index 7099692..9dd27c0 100644 --- a/src/npc/boss/balfrog.rs +++ b/src/npc/boss/balfrog.rs @@ -463,9 +463,7 @@ impl BossNPC { } self.parts[0].vel_y += 0x40; - if self.parts[0].vel_y > 0x5ff { - self.parts[0].vel_y = 0x5ff; - } + self.parts[0].clamp_fall_speed(); self.parts[0].x += self.parts[0].vel_x; self.parts[0].y += self.parts[0].vel_y; diff --git a/src/npc/boss/ballos.rs b/src/npc/boss/ballos.rs index f0390ac..b13d8cd 100644 --- a/src/npc/boss/ballos.rs +++ b/src/npc/boss/ballos.rs @@ -30,9 +30,7 @@ impl NPC { } self.vel_y += 0x40; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.x += self.vel_x; self.y += self.vel_y; @@ -426,9 +424,7 @@ impl NPC { } self.vel_y += 0x80; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.animate(1, 4, 5); @@ -525,9 +521,7 @@ impl NPC { npc_list.create_death_smoke(self.x, self.y, 16, 16, state, &self.rng); } self.vel_y += 0x20; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); self.action_counter; self.x = self.target_x + if self.action_counter & 0x02 != 0 { 0x200 } else { -0x200 }; @@ -775,9 +769,7 @@ impl NPC { } self.vel_y += 0x20; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); } 1000 | 1001 => { if self.action_num == 1000 { diff --git a/src/npc/boss/omega.rs b/src/npc/boss/omega.rs index 82c5c2e..4e69dac 100644 --- a/src/npc/boss/omega.rs +++ b/src/npc/boss/omega.rs @@ -74,8 +74,7 @@ impl BossNPC { self.parts[0].target_y = self.parts[0].y; self.parts[0].display_bounds = Rect { left: 40 * 0x200, top: 40 * 0x200, right: 40 * 0x200, bottom: 0x2000 }; - self.parts[0].hit_bounds = - Rect { left: 0x1000, top: 24 * 0x200, right: 0x1000, bottom: 0x2000 }; + self.parts[0].hit_bounds = Rect { left: 0x1000, top: 24 * 0x200, right: 0x1000, bottom: 0x2000 }; self.parts[1].cond.set_alive(true); self.parts[1].display_bounds = @@ -93,10 +92,8 @@ impl BossNPC { self.parts[3].direction = Direction::Left; self.parts[3].x = self.parts[0].x + 0x2000; self.parts[3].y = self.parts[0].y; - self.parts[3].display_bounds = - Rect { left: 24 * 0x200, top: 0x2000, right: 0x2000, bottom: 0x2000 }; - self.parts[3].hit_bounds = - Rect { left: 0x1000, top: 0x1000, right: 0x1000, bottom: 0x1000 }; + self.parts[3].display_bounds = Rect { left: 24 * 0x200, top: 0x2000, right: 0x2000, bottom: 0x2000 }; + self.parts[3].hit_bounds = Rect { left: 0x1000, top: 0x1000, right: 0x1000, bottom: 0x1000 }; self.hurt_sound[3] = 52; self.parts[4].cond.set_alive(true); @@ -309,9 +306,7 @@ impl BossNPC { let player = self.parts[5].get_closest_player_mut(players); self.parts[5].damage = if player.flags.hit_bottom_wall() && self.parts[0].vel_y > 0 { 20 } else { 0 }; self.parts[0].vel_y += 0x24; - if self.parts[0].vel_y > 0x5ff { - self.parts[0].vel_y = 0x5ff; - } + self.parts[0].clamp_fall_speed(); self.parts[0].y += self.parts[0].vel_y; self.parts[0].x += self.parts[0].vel_x; @@ -416,8 +411,7 @@ impl BossNPC { self.parts[5].action_num = 1; self.parts[5].npc_flags.set_solid_soft(true); self.parts[5].npc_flags.set_ignore_solidity(true); - self.parts[5].hit_bounds = - Rect { left: 20 * 0x200, top: 36 * 0x200, right: 20 * 0x200, bottom: 0x2000 }; + self.parts[5].hit_bounds = Rect { left: 20 * 0x200, top: 36 * 0x200, right: 20 * 0x200, bottom: 0x2000 }; } self.parts[5].x = self.parts[0].x; diff --git a/src/npc/boss/undead_core.rs b/src/npc/boss/undead_core.rs index ee7fe04..78d04f8 100644 --- a/src/npc/boss/undead_core.rs +++ b/src/npc/boss/undead_core.rs @@ -254,9 +254,7 @@ impl NPC { } Direction::Bottom => { self.vel_y += 0x20; - if self.vel_y > 0x5FF { - self.vel_y = 0x5FF; - } + self.clamp_fall_speed(); if self.flags.hit_bottom_wall() { self.action_num = 2; diff --git a/src/npc/utils.rs b/src/npc/utils.rs index 2ebabe8..4e16b66 100644 --- a/src/npc/utils.rs +++ b/src/npc/utils.rs @@ -12,6 +12,8 @@ use crate::rng::{Xoroshiro32PlusPlus, RNG}; use crate::shared_game_state::{SharedGameState, TileSize}; use crate::weapon::bullet::Bullet; +const MAX_FALL_SPEED: i32 = 0x5FF; + impl NPC { /// Initializes the RNG. Called when the [NPC] is being added to an [NPCList]. pub(crate) fn init_rng(&mut self) { @@ -166,6 +168,13 @@ impl NPC { self.direction = if self.x > player.x { Direction::Left } else { Direction::Right }; } + /// Clamps +Y velocity if above `MAX_FALL_SPEED`. + pub fn clamp_fall_speed(&mut self) { + if self.vel_y > MAX_FALL_SPEED { + self.vel_y = MAX_FALL_SPEED; + } + } + /// Returns true if the [NPC] collides with a [Bullet]. pub fn collides_with_bullet(&self, bullet: &Bullet) -> bool { (self.npc_flags.shootable()