1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2025-06-21 02:11:15 +00:00

some refactorings, behemot smoke fix

This commit is contained in:
Alula 2022-03-26 10:21:08 +01:00
parent fb17edea7a
commit a0df539b7b
No known key found for this signature in database
GPG key ID: 3E00485503A1D8BA
19 changed files with 203 additions and 290 deletions

View file

@ -163,7 +163,7 @@ pub enum FadeDirection {
}
impl FadeDirection {
pub fn from_int(val: usize) -> Option<FadeDirection> {
pub const fn from_int(val: usize) -> Option<FadeDirection> {
match val {
0 => Some(FadeDirection::Left),
1 => Some(FadeDirection::Up),
@ -174,7 +174,7 @@ impl FadeDirection {
}
}
pub fn opposite(&self) -> FadeDirection {
pub const fn opposite(&self) -> FadeDirection {
match self {
FadeDirection::Left => FadeDirection::Right,
FadeDirection::Up => FadeDirection::Down,
@ -207,7 +207,7 @@ pub enum Direction {
pub const FILE_TYPES: [&str; 3] = [".png", ".bmp", ".pbm"];
impl Direction {
pub fn from_int(val: usize) -> Option<Direction> {
pub const fn from_int(val: usize) -> Option<Direction> {
match val {
0 => Some(Direction::Left),
1 => Some(Direction::Up),
@ -217,7 +217,7 @@ impl Direction {
}
}
pub fn from_int_facing(val: usize) -> Option<Direction> {
pub const fn from_int_facing(val: usize) -> Option<Direction> {
match val {
0 => Some(Direction::Left),
1 => Some(Direction::Up),
@ -228,33 +228,33 @@ impl Direction {
}
}
pub fn opposite(&self) -> Direction {
pub const fn opposite(&self) -> Direction {
match self {
Direction::Left => Direction::Right,
Direction::Up => Direction::Bottom,
Direction::Right => Direction::Left,
Direction::Bottom => Direction::Up,
Direction::FacingPlayer => unreachable!(),
Direction::FacingPlayer => Direction::FacingPlayer,
}
}
pub fn vector_x(&self) -> i32 {
pub const fn vector_x(&self) -> i32 {
match self {
Direction::Left => -1,
Direction::Up => 0,
Direction::Right => 1,
Direction::Bottom => 0,
Direction::FacingPlayer => unreachable!(),
Direction::FacingPlayer => 0,
}
}
pub fn vector_y(&self) -> i32 {
pub const fn vector_y(&self) -> i32 {
match self {
Direction::Left => 0,
Direction::Up => -1,
Direction::Right => 0,
Direction::Bottom => 1,
Direction::FacingPlayer => unreachable!(),
Direction::FacingPlayer => 0,
}
}
}

View file

@ -562,7 +562,7 @@ impl NPC {
state.sound_manager.play_sfx(26);
state.quake_counter = 30;
self.y += 10 * 0x200;
self.y += 0x1400;
self.action_num = 1;
self.anim_num = 3;
self.vel_y = -0x100;
@ -864,13 +864,12 @@ impl NPC {
}
}
self.vel_x += 0x10 * self.direction.vector_x(); // 0.03125fix9
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() < 12 * 0x200 // 12.0fix9
&& self.y - 12 * 0x200 < 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
{
// 12.0fix9 / 8.0fix9
self.action_num = 10;
self.anim_num = 5;
self.vel_y2 = pi as i32;
@ -899,8 +898,8 @@ impl NPC {
let pi = self.get_closest_player_idx_mut(&players);
if self.action_counter >= 8
&& (players[pi].x - self.x).abs() < 12 * 0x200
&& self.y - 12 * 0x200 < players[pi].y
&& (players[pi].x - self.x).abs() < 0x1800
&& self.y - 0x1800 < players[pi].y
&& self.y + 0x1000 > players[pi].y
{
self.action_num = 10;

View file

@ -24,8 +24,8 @@ impl NPC {
}
let player = self.get_closest_player_mut(players);
if (self.x - player.x).abs() < 32 * 0x200
&& self.y - 32 * 0x200 < player.y
if (self.x - player.x).abs() < 0x4000
&& self.y - 0x4000 < player.y
&& self.y + 0x2000 > player.y {
self.direction = if self.x > player.x { Direction::Left } else { Direction::Right };
}

View file

@ -18,7 +18,7 @@ impl NPC {
let player = self.get_closest_player_mut(players);
if abs(self.x - player.x) < 48 * 0x200 && self.y - 48 * 0x200 < player.y && self.y + 0x2000 > player.y {
if abs(self.x - player.x) < 0x6000 && self.y - 0x6000 < player.y && self.y + 0x2000 > player.y {
self.anim_num = 1;
} else {
self.anim_num = 0;

View file

@ -11,7 +11,7 @@ use crate::shared_game_state::SharedGameState;
use crate::weapon::bullet::BulletManager;
impl NPC {
pub(crate) fn tick_n002_behemoth(&mut self, state: &mut SharedGameState) -> GameResult {
pub(crate) fn tick_n002_behemoth(&mut self, state: &mut SharedGameState, npc_list: &NPCList) -> GameResult {
if self.flags.hit_left_wall() {
self.direction = Direction::Right;
} else if self.flags.hit_right_wall() {
@ -20,11 +20,7 @@ impl NPC {
match self.action_num {
0 => {
self.vel_x = match self.direction {
Direction::Left => -0x100,
Direction::Right => 0x100,
_ => 0,
};
self.vel_x = self.direction.vector_x() * 0x100;
self.animate(8, 0, 3);
@ -52,11 +48,7 @@ impl NPC {
}
}
2 => {
self.vel_x = match self.direction {
Direction::Left => -0x400,
Direction::Right => 0x400,
_ => 0,
};
self.vel_x = self.direction.vector_x() * 0x400;
self.action_counter += 1;
if self.action_counter > 200 {
@ -68,10 +60,19 @@ impl NPC {
if self.anim_counter > 5 {
self.anim_counter = 0;
self.anim_num += 1;
if self.anim_num > 6 {
self.anim_num = 5;
state.sound_manager.play_sfx(26);
state.quake_counter = 8;
state.sound_manager.play_sfx(26);
let mut npc = NPC::create(4, &state.npc_table);
npc.cond.set_alive(true);
npc.x = self.x;
npc.y = self.y + 0x600;
let _ = npc_list.spawn(0x100, npc);
}
}
}
@ -79,6 +80,7 @@ impl NPC {
}
self.vel_y += 0x40;
if self.vel_y > 0x5ff {
self.vel_y = 0x5ff;
}
@ -86,8 +88,9 @@ impl NPC {
self.x += self.vel_x;
self.y += self.vel_y;
self.anim_rect = state.constants.npc.n002_behemoth
[self.anim_num as usize + if self.direction == Direction::Right { 7 } else { 0 }];
let dir_offset = if self.direction == Direction::Left { 0 } else { 7 };
self.anim_rect = state.constants.npc.n002_behemoth[self.anim_num as usize + dir_offset];
Ok(())
}
@ -103,17 +106,10 @@ impl NPC {
self.y += 0x600;
self.action_num = 1;
self.anim_num = 0;
self.anim_rect = state.constants.npc.n005_green_critter
[self.anim_num as usize + if self.direction == Direction::Right { 3 } else { 0 }];
}
let player = self.get_closest_player_mut(players);
if self.x > player.x {
self.direction = Direction::Left;
} else {
self.direction = Direction::Right;
}
let player = self.get_closest_player_ref(&players);
self.face_player(player);
if self.target_x < 100 {
self.target_x += 1;
@ -125,32 +121,20 @@ impl NPC {
&& self.y - 0xa000 < player.y
&& self.y + 0xa000 > player.y
{
if self.anim_num != 1 {
self.anim_num = 1;
self.anim_rect = state.constants.npc.n005_green_critter
[self.anim_num as usize + if self.direction == Direction::Right { 3 } else { 0 }];
}
self.anim_num = 1;
} else {
if self.action_counter < 8 {
self.action_counter += 1;
}
if self.anim_num != 0 {
self.anim_num = 0;
self.anim_rect = state.constants.npc.n005_green_critter
[self.anim_num as usize + if self.direction == Direction::Right { 3 } else { 0 }];
}
self.anim_num = 0;
}
if self.shock > 0 {
self.action_num = 2;
self.action_counter = 0;
if self.anim_num != 0 {
self.anim_num = 0;
self.anim_rect = state.constants.npc.n005_green_critter
[self.anim_num as usize + if self.direction == Direction::Right { 3 } else { 0 }];
}
self.anim_num = 0;
}
if self.action_counter >= 8
@ -163,32 +147,18 @@ impl NPC {
self.action_num = 2;
self.action_counter = 0;
if self.anim_num != 0 {
self.anim_num = 0;
self.anim_rect = state.constants.npc.n005_green_critter
[self.anim_num as usize + if self.direction == Direction::Right { 3 } else { 0 }];
}
self.anim_num = 0;
}
}
2 => {
self.action_counter += 1;
if self.action_counter > 8 {
self.action_num = 3;
self.anim_num = 2;
if self.anim_num != 2 {
self.anim_num = 2;
self.anim_rect = state.constants.npc.n005_green_critter
[self.anim_num as usize + if self.direction == Direction::Right { 3 } else { 0 }];
}
self.vel_x = self.direction.vector_x() * 0x100;
self.vel_y = -0x5ff;
state.sound_manager.play_sfx(30);
if self.direction == Direction::Left {
self.vel_x = -0x100;
} else {
self.vel_x = 0x100;
}
}
}
3 => {
@ -196,14 +166,9 @@ impl NPC {
self.vel_x = 0;
self.action_counter = 0;
self.action_num = 1;
self.anim_num = 0;
state.sound_manager.play_sfx(23);
if self.anim_num != 0 {
self.anim_num = 0;
self.anim_rect = state.constants.npc.n005_green_critter
[self.anim_num as usize + if self.direction == Direction::Right { 3 } else { 0 }];
}
}
}
_ => (),
@ -217,6 +182,10 @@ impl NPC {
self.x += self.vel_x;
self.y += self.vel_y;
let dir_offset = if self.direction == Direction::Left { 0 } else { 3 };
self.anim_rect = state.constants.npc.n005_green_critter[self.anim_num as usize + dir_offset];
Ok(())
}
@ -248,15 +217,7 @@ impl NPC {
self.x += self.vel_x;
}
self.anim_counter += 1;
if self.anim_counter > 1 {
self.anim_counter = 0;
self.anim_num += 1;
if self.anim_num > 2 {
self.anim_num = 1;
}
}
self.animate(1, 1, 2);
if self.flags.hit_left_wall() {
self.action_num = 2;
@ -287,15 +248,7 @@ impl NPC {
self.x += self.vel_x;
}
self.anim_counter += 1;
if self.anim_counter > 1 {
self.anim_counter = 0;
self.anim_num += 1;
if self.anim_num > 2 {
self.anim_num = 1;
}
}
self.animate(1, 1, 2);
if self.flags.hit_right_wall() {
self.action_num = 4;
@ -316,8 +269,9 @@ impl NPC {
_ => (),
}
self.anim_rect = state.constants.npc.n006_green_beetle
[self.anim_num as usize + if self.direction == Direction::Right { 5 } else { 0 }];
let dir_offset = if self.direction == Direction::Left { 0 } else { 5 };
self.anim_rect = state.constants.npc.n006_green_beetle[self.anim_num as usize + dir_offset];
Ok(())
}
@ -338,7 +292,7 @@ impl NPC {
self.vel_x -= 0x40;
let player = self.get_closest_player_mut(players);
if self.x < (player.x - 192 * 0x200) {
if self.x < (player.x - 0x18000) {
self.action_num = 2;
}
@ -351,7 +305,7 @@ impl NPC {
self.vel_x += 0x40;
let player = self.get_closest_player_mut(players);
if self.x > (player.x + 192 * 0x200) {
if self.x > (player.x + 0x18000) {
self.action_num = 1;
}
@ -370,19 +324,13 @@ impl NPC {
}
self.vel_x = clamp(self.vel_x, -0x5ff, 0x5ff);
self.x += self.vel_x;
self.anim_counter += 1;
if self.anim_counter > 1 {
self.anim_counter = 0;
self.anim_num = (self.anim_num + 1) % 2;
}
self.animate(1, 0, 1);
if self.anim_counter == 1 {
self.anim_rect = state.constants.npc.n007_basil
[self.anim_num as usize + if self.direction == Direction::Right { 3 } else { 0 }];
}
let dir_offset = if self.direction == Direction::Left { 0 } else { 3 };
self.anim_rect = state.constants.npc.n007_basil[self.anim_num as usize + dir_offset];
Ok(())
}
@ -403,17 +351,8 @@ impl NPC {
self.action_num = 1;
self.damage = 2;
match self.direction {
Direction::Left => {
self.x = player.x + 256 * 0x200;
self.vel_x = -0x2ff;
}
Direction::Right => {
self.x = player.x - 256 * 0x200;
self.vel_x = 0x2ff;
}
_ => (),
}
self.x = player.x + self.direction.opposite().vector_x() * 0x20000;
self.vel_x = self.direction.vector_x() * 0x2ff;
} else {
self.npc_flags.set_shootable(false);
self.anim_rect.left = 0;
@ -428,14 +367,9 @@ impl NPC {
1 => {
let player = self.get_closest_player_mut(players);
if self.x > player.x {
self.direction = Direction::Left;
self.vel_x -= 0x10;
} else {
self.direction = Direction::Right;
self.vel_x += 0x10;
}
self.face_player(player);
self.vel_x += self.direction.vector_x() * 0x10;
self.vel_y += if self.y < self.target_y { 8 } else { -8 };
self.vel_x = clamp(self.vel_x, -0x2ff, 0x2ff);
@ -452,20 +386,11 @@ impl NPC {
_ => (),
}
self.anim_counter += 1;
if self.anim_counter > 1 {
self.anim_counter = 0;
self.anim_num += 1;
self.animate(1, 0, 1);
if self.anim_num > 1 {
self.anim_num = 0;
}
}
let dir_offset = if self.direction == Direction::Left { 0 } else { 2 };
if self.anim_counter == 1 {
self.anim_rect = state.constants.npc.n008_blue_beetle
[self.anim_num as usize + if self.direction == Direction::Right { 2 } else { 0 }];
}
self.anim_rect = state.constants.npc.n008_blue_beetle[self.anim_num as usize + dir_offset];
Ok(())
}
@ -576,7 +501,7 @@ impl NPC {
self.tsc_direction = self.direction as u16;
self.npc_flags.set_shootable(true);
self.x = player.x + self.direction.opposite().vector_x() * 16 * 0x2000;
self.x = player.x + self.direction.opposite().vector_x() * 0x20000;
self.vel_x = self.direction.vector_x() * 0x2ff;
} else {
self.anim_rect = Rect::new(0, 0, 0, 0);
@ -618,7 +543,7 @@ impl NPC {
self.y += self.vel_y;
}
if player.x > self.x + 400 * 0x200 || player.x < self.x - 400 * 0x200 {
if player.x > self.x + 0x32000 || player.x < self.x - 0x32000 {
self.action_num = 0;
self.vel_x = 0;
self.x = self.target_x;
@ -635,7 +560,7 @@ impl NPC {
self.action_counter += 1;
} else {
self.action_counter2 += 1;
if (self.action_counter2 % 8) == 0 && abs(self.x - player.x) < 160 * 0x200 {
if (self.action_counter2 % 8) == 0 && abs(self.x - player.x) < 0x14000 {
let angle = f64::atan2((self.y - player.y) as f64, (self.x - player.x) as f64)
+ self.rng.range(-6..6) as f64 * CDEG_RAD;
@ -670,6 +595,7 @@ impl NPC {
}
let dir_offset = if self.direction == Direction::Left { 0 } else { 3 };
self.anim_rect = state.constants.npc.n058_basu[self.anim_num as usize + dir_offset];
Ok(())
@ -1234,7 +1160,7 @@ impl NPC {
self.tsc_direction = self.direction as u16;
self.npc_flags.set_shootable(true);
self.x = player.x + self.direction.opposite().vector_x() * 16 * 0x2000;
self.x = player.x + self.direction.opposite().vector_x() * 0x20000;
self.vel_x = self.direction.vector_x() * 0x2ff;
} else {
self.anim_rect = Rect::new(0, 0, 0, 0);
@ -1276,7 +1202,7 @@ impl NPC {
self.y += self.vel_y;
}
if player.x > self.x + 400 * 0x200 || player.x < self.x - 400 * 0x200 {
if player.x > self.x + 0x32000 || player.x < self.x - 0x32000 {
self.action_num = 0;
self.vel_x = 0;
self.x = self.target_x;
@ -1293,7 +1219,7 @@ impl NPC {
self.action_counter += 1;
} else {
self.action_counter2 += 1;
if (self.action_counter2 % 8) == 0 && abs(self.x - player.x) < 160 * 0x200 {
if (self.action_counter2 % 8) == 0 && abs(self.x - player.x) < 0x14000 {
let angle = f64::atan2((self.y - player.y) as f64, (self.x - player.x) as f64)
+ self.rng.range(-6..6) as f64 * CDEG_RAD;

View file

@ -1,7 +1,7 @@
use crate::framework::error::GameResult;
use num_traits::clamp;
use crate::common::Direction;
use crate::framework::error::GameResult;
use crate::npc::NPC;
use crate::player::Player;
use crate::rng::RNG;
@ -16,10 +16,11 @@ impl NPC {
}
let player = self.get_closest_player_mut(players);
if self.x - (64 * 0x200) < player.x
&& self.x + (64 * 0x200) > player.x
&& self.y - (64 * 0x200) < player.y
&& self.y + (64 * 0x200) > player.y {
if self.x - 0x8000 < player.x
&& self.x + 0x8000 > player.x
&& self.y - 0x8000 < player.y
&& self.y + 0x8000 > player.y
{
self.action_num = 2;
self.anim_counter = 0;
}
@ -37,10 +38,11 @@ impl NPC {
}
3 => {
let player = self.get_closest_player_mut(players);
if !(self.x - (64 * 0x200) < player.x
&& self.x + (64 * 0x200) > player.x
&& self.y - (64 * 0x200) < player.y
&& self.y + (64 * 0x200) > player.y) {
if !(self.x - 0x8000 < player.x
&& self.x + 0x8000 > player.x
&& self.y - 0x8000 < player.y
&& self.y + 0x8000 > player.y)
{
self.action_num = 4;
self.anim_counter = 0;
}
@ -66,105 +68,81 @@ impl NPC {
}
Ok(())
}
pub(crate) fn tick_n064_first_cave_critter(&mut self, state: &mut SharedGameState, players: [&mut Player; 2]) -> GameResult {
pub(crate) fn tick_n064_first_cave_critter(
&mut self,
state: &mut SharedGameState,
players: [&mut Player; 2],
) -> GameResult {
match self.action_num {
0 | 1 => {
if self.action_num == 0 {
self.y += 0x600;
self.action_num = 1;
self.anim_num = 0;
self.anim_rect = state.constants.npc.n064_first_cave_critter[self.anim_num as usize + if self.direction == Direction::Right { 3 } else { 0 }];
}
let player = self.get_closest_player_mut(players);
if self.x > player.x {
self.direction = Direction::Left;
} else {
self.direction = Direction::Right;
}
self.face_player(player);
if self.target_x < 100 {
self.target_x += 1;
}
if self.action_counter >= 8
&& self.x - (112 * 0x200) < player.x
&& self.x + (112 * 0x200) > player.x
&& self.y - (80 * 0x200) < player.y
&& self.y + (80 * 0x200) > player.y {
if self.anim_num != 1 {
self.anim_num = 1;
self.anim_rect = state.constants.npc.n064_first_cave_critter[self.anim_num as usize + if self.direction == Direction::Right { 3 } else { 0 }];
}
&& self.x - 0xe000 < player.x
&& self.x + 0xe000 > player.x
&& self.y - 0xa000 < player.y
&& self.y + 0xa000 > player.y
{
self.anim_num = 1;
} else {
if self.action_counter < 8 {
self.action_counter += 1;
}
if self.anim_num != 0 {
self.anim_num = 0;
self.anim_rect = state.constants.npc.n064_first_cave_critter[self.anim_num as usize + if self.direction == Direction::Right { 3 } else { 0 }];
}
self.anim_num = 0;
}
if self.shock > 0 {
self.action_num = 2;
self.action_counter = 0;
if self.anim_num != 0 {
self.anim_num = 0;
self.anim_rect = state.constants.npc.n064_first_cave_critter[self.anim_num as usize + if self.direction == Direction::Right { 3 } else { 0 }];
}
self.anim_num = 0;
}
if self.action_counter >= 8
&& self.target_x >= 100
&& self.x - (64 * 0x200) < player.x
&& self.x + (64 * 0x200) > player.x
&& self.y - (80 * 0x200) < player.y
&& self.y + (80 * 0x200) > player.y {
&& self.x - 0x8000 < player.x
&& self.x + 0x8000 > player.x
&& self.y - 0xa000 < player.y
&& self.y + 0xa000 > player.y
{
self.action_num = 2;
self.action_counter = 0;
if self.anim_num != 0 {
self.anim_num = 0;
self.anim_rect = state.constants.npc.n064_first_cave_critter[self.anim_num as usize + if self.direction == Direction::Right { 3 } else { 0 }];
}
self.anim_num = 0;
}
}
2 => {
self.action_counter += 1;
if self.action_counter > 8 {
self.action_num = 3;
self.anim_num = 2;
if self.anim_num != 2 {
self.anim_num = 2;
self.anim_rect = state.constants.npc.n064_first_cave_critter[self.anim_num as usize + if self.direction == Direction::Right { 3 } else { 0 }];
}
self.vel_x = self.direction.vector_x() * 0x100;
self.vel_y = -0x5ff;
state.sound_manager.play_sfx(30);
if self.direction == Direction::Left {
self.vel_x = -0x100;
} else {
self.vel_x = 0x100;
}
state.sound_manager.play_sfx(30);
}
}
3 => {
if self.flags.hit_bottom_wall() {
self.vel_x = 0;
self.anim_num = 0;
self.action_counter = 0;
self.action_num = 1;
state.sound_manager.play_sfx(23);
if self.anim_num != 0 {
self.anim_num = 0;
self.anim_rect = state.constants.npc.n064_first_cave_critter[self.anim_num as usize + if self.direction == Direction::Right { 3 } else { 0 }];
}
}
}
_ => (),
@ -178,10 +156,18 @@ impl NPC {
self.x += self.vel_x;
self.y += self.vel_y;
let dir_offset = if self.direction == Direction::Left { 0 } else { 3 };
self.anim_rect = state.constants.npc.n064_first_cave_critter[self.anim_num as usize + dir_offset];
Ok(())
}
pub(crate) fn tick_n065_first_cave_bat(&mut self, state: &mut SharedGameState, players: [&mut Player; 2]) -> GameResult {
pub(crate) fn tick_n065_first_cave_bat(
&mut self,
state: &mut SharedGameState,
players: [&mut Player; 2],
) -> GameResult {
match self.action_num {
0 | 1 => {
if self.action_num == 0 {
@ -230,7 +216,8 @@ impl NPC {
self.anim_num = 0;
}
self.anim_rect = state.constants.npc.n065_first_cave_bat[self.anim_num as usize + if self.direction == Direction::Right { 4 } else { 0 }];
self.anim_rect = state.constants.npc.n065_first_cave_bat
[self.anim_num as usize + if self.direction == Direction::Right { 4 } else { 0 }];
}
Ok(())

View file

@ -177,7 +177,7 @@ impl NPC {
if self.action_counter2 < 120 {
self.action_counter2 += 1;
} else if abs(self.x - player.x) < 0x1000 && self.y < player.y && self.y + 96 * 0x200 > player.y {
} else if abs(self.x - player.x) < 0x1000 && self.y < player.y && self.y + 0xc000 > player.y {
self.vel_x /= 2;
self.vel_y = 0;
self.action_num = 3;
@ -231,9 +231,9 @@ impl NPC {
}
if self.action_counter >= 8
&& abs(self.x - player.x) < 96 * 0x200
&& self.y - 128 * 0x200 < player.y
&& self.y + 48 * 0x200 > player.y
&& abs(self.x - player.x) < 0xc000
&& self.y - 0x10000 < player.y
&& self.y + 0x6000 > player.y
{
if self.x > player.x {
self.direction = Direction::Left;
@ -257,9 +257,9 @@ impl NPC {
}
if self.action_counter >= 8
&& abs(self.x - player.x) < 96 * 0x200
&& self.y - 96 * 0x200 < player.y
&& self.y + 48 * 0x200 > player.y
&& abs(self.x - player.x) < 0xc000
&& self.y - 0xc000 < player.y
&& self.y + 0x6000 > player.y
{
self.action_num = 2;
self.action_counter = 0;
@ -370,7 +370,7 @@ impl NPC {
self.anim_num = 1;
}
if abs(self.x - player.x) < 0x1000 && self.y - 0x1000 < player.y && self.y + 96 * 0x200 > player.y {
if abs(self.x - player.x) < 0x1000 && self.y - 0x1000 < player.y && self.y + 0xc000 > player.y {
self.action_num = 3;
self.anim_num = 0;
}
@ -385,7 +385,7 @@ impl NPC {
3 => {
self.anim_num = 0;
if self.shock > 0 || abs(self.x - player.x) > 20 * 0x200 {
if self.shock > 0 || abs(self.x - player.x) > 0x2800 {
self.action_num = 4;
self.action_counter = 0;
self.anim_num = 1;
@ -841,7 +841,7 @@ impl NPC {
&& self.action_num != 3
&& self.action_counter > 10
&& ((self.shock > 0)
|| (abs(self.x - player.x) < 160 * 0x200 && abs(self.y - player.y) < 64 * 0x200)
|| (abs(self.x - player.x) < 0x14000 && abs(self.y - player.y) < 0x8000)
&& self.rng.range(0..50) == 2)
{
self.direction = if self.x >= player.x { Direction::Left } else { Direction::Right };
@ -1055,7 +1055,7 @@ impl NPC {
let player = self.get_closest_player_mut(players);
if abs(self.x - player.x) < 32 * 0x200 && self.y - 32 * 0x200 < player.y && self.y + 0x2000 > player.y {
if abs(self.x - player.x) < 0x4000 && self.y - 0x4000 < player.y && self.y + 0x2000 > player.y {
self.direction = if self.x > player.x { Direction::Left } else { Direction::Right };
}
}
@ -1186,7 +1186,7 @@ impl NPC {
&& self.action_num != 3
&& self.action_counter > 10
&& ((self.shock > 0)
|| (abs(self.x - player.x) < 160 * 0x200 && abs(self.y - player.y) < 64 * 0x200)
|| (abs(self.x - player.x) < 0x14000 && abs(self.y - player.y) < 0x8000)
&& self.rng.range(0..50) == 2)
{
self.direction = if self.x >= player.x { Direction::Left } else { Direction::Right };
@ -1357,7 +1357,7 @@ impl NPC {
10 => {
self.action_num = 11;
self.anim_num = 1;
self.y -= 5 * 0x200;
self.y -= 0xa00;
self.display_bounds.top = 0x2000;
self.display_bounds.bottom = 0x2000
}
@ -1406,7 +1406,7 @@ impl NPC {
self.action_num = 41;
self.action_counter = 2;
self.direction = Direction::Left;
self.y -= 48 * 0x200;
self.y -= 0x6000;
self.vel_x = -0x1000;
}
@ -1425,8 +1425,8 @@ impl NPC {
if self.action_counter % 4 == 0 && self.action_num >= 20 {
state.sound_manager.play_sfx(34);
state.create_caret(
self.x + self.direction.opposite().vector_x() * 10 * 0x200,
self.y + 10 * 0x200,
self.x + self.direction.opposite().vector_x() * 0x1400,
self.y + 0x1400,
CaretType::Exhaust,
self.direction.opposite(),
);
@ -1442,7 +1442,7 @@ impl NPC {
pub(crate) fn tick_n193_broken_scooter(&mut self, state: &mut SharedGameState) -> GameResult {
if self.action_num == 0 {
self.action_num = 1;
self.x += 24 * 0x200;
self.x += 0x3000;
}
self.anim_rect = state.constants.npc.n193_broken_scooter;

View file

@ -33,10 +33,10 @@ impl NPC {
}
if self.action_counter >= 8
&& self.x - (144 * 0x200) < player.x
&& self.x + (144 * 0x200) > player.x
&& self.y - (96 * 0x200) < player.y
&& self.y + (96 * 0x200) > player.y
&& self.x - 0x12000 < player.x
&& self.x + 0x12000 > player.x
&& self.y - 0xc000 < player.y
&& self.y + 0xc000 > player.y
{
self.anim_num = 1;
} else {
@ -56,10 +56,10 @@ impl NPC {
if self.action_counter >= 8
&& self.target_x >= 100
&& self.x - (96 * 0x200) < player.x
&& self.x + (96 * 0x200) > player.x
&& self.y - (80 * 0x200) < player.y
&& self.y + (80 * 0x200) > player.y
&& self.x - 0xc000 < player.x
&& self.x + 0xc000 > player.x
&& self.y - 0xa000 < player.y
&& self.y + 0xa000 > player.y
{
self.action_num = 2;
self.action_counter = 0;

View file

@ -166,10 +166,10 @@ impl NPC {
if self.action_num == 1 {
let player = self.get_closest_player_mut(players);
if (self.x - (48 * 0x200) < player.x)
&& (self.x + (48 * 0x200) > player.x)
&& (self.y - (48 * 0x200) < player.y)
&& (self.y + (48 * 0x200) > player.y)
if (self.x - 0x6000 < player.x)
&& (self.x + 0x6000 > player.x)
&& (self.y - 0x6000 < player.y)
&& (self.y + 0x6000 > player.y)
{
self.anim_num = 1;
} else {
@ -232,9 +232,9 @@ impl NPC {
}
let player = self.get_closest_player_mut(players);
if (self.x - (32 * 0x200) < player.x)
&& (self.x + (32 * 0x200) > player.x)
&& (self.y - (32 * 0x200) < player.y)
if (self.x - (0x4000) < player.x)
&& (self.x + (0x4000) > player.x)
&& (self.y - (0x4000) < player.y)
&& (self.y + (0x2000) > player.y)
{
if self.x > player.x {
@ -285,9 +285,9 @@ impl NPC {
self.anim_num = 0;
let player = self.get_closest_player_mut(players);
if abs(player.x - self.x) < 128 * 0x200
&& self.y - 48 * 0x200 < player.y
&& self.y + 32 * 0x200 > player.y
if abs(player.x - self.x) < 0x10000
&& self.y - 0x6000 < player.y
&& self.y + 0x4000 > player.y
{
self.anim_counter = 0;
self.action_num = 2;
@ -314,7 +314,7 @@ impl NPC {
let player = self.get_closest_player_mut(players);
if abs(player.x - self.x) < 0x2000 {
self.hit_bounds.left = 18 * 0x200;
self.hit_bounds.left = 0x2400;
self.action_counter = 0;
self.action_num = 3;
self.npc_flags.set_shootable(true);

View file

@ -573,7 +573,7 @@ impl NPC {
self.anim_num = self.anim_counter / 2;
let player = self.get_closest_player_mut(players);
if self.anim_num % 2 == 0 && (player.x - self.x).abs() < 480 * 0x200 {
if self.anim_num % 2 == 0 && (player.x - self.x).abs() < 0x3c000 {
self.action_counter = self.action_counter.wrapping_add(1);
let mut droplet = NPC::create(73, &state.npc_table);
@ -723,8 +723,8 @@ impl NPC {
{
let i = self.get_closest_player_idx_mut(&players);
if (players[i].x - self.x).abs() < 480 * 0x200
&& (players[i].y - self.y).abs() < 240 * 0x200
if (players[i].x - self.x).abs() < 0x3c000
&& (players[i].y - self.y).abs() < 0x1e000
&& self.rng.range(0..5) == 1
{
let mut particle = NPC::create(199, &state.npc_table);
@ -741,7 +741,7 @@ impl NPC {
continue;
}
if (player.y - self.y).abs() < 0x1000 && player.x < self.x && player.x > self.x - 96 * 0x200 {
if (player.y - self.y).abs() < 0x1000 && player.x < self.x && player.x > self.x - 0xc000 {
player.vel_x -= 0x88;
player.cond.set_increase_acceleration(true);
}
@ -783,8 +783,8 @@ impl NPC {
{
let i = self.get_closest_player_idx_mut(&players);
if (players[i].x - self.x).abs() < 480 * 0x200
&& (players[i].y - self.y).abs() < 240 * 0x200
if (players[i].x - self.x).abs() < 0x3c000
&& (players[i].y - self.y).abs() < 0x1e000
&& self.rng.range(0..5) == 1
{
let mut particle = NPC::create(199, &state.npc_table);
@ -801,7 +801,7 @@ impl NPC {
continue;
}
if (player.x - self.x).abs() < 0x1000 && player.y < self.y && player.y > self.y - 96 * 0x200 {
if (player.x - self.x).abs() < 0x1000 && player.y < self.y && player.y > self.y - 0xc000 {
player.vel_y -= 0x88;
}
}
@ -842,8 +842,8 @@ impl NPC {
{
let i = self.get_closest_player_idx_mut(&players);
if (players[i].x - self.x).abs() < 480 * 0x200
&& (players[i].y - self.y).abs() < 240 * 0x200
if (players[i].x - self.x).abs() < 0x3c000
&& (players[i].y - self.y).abs() < 0x1e000
&& self.rng.range(0..5) == 1
{
let mut particle = NPC::create(199, &state.npc_table);
@ -856,7 +856,7 @@ impl NPC {
}
for player in players {
if (player.y - self.y).abs() < 0x1000 && player.x > self.x && player.x < self.x + 96 * 0x200 {
if (player.y - self.y).abs() < 0x1000 && player.x > self.x && player.x < self.x + 0xc000 {
player.vel_x += 0x88;
player.cond.set_increase_acceleration(true);
}
@ -898,8 +898,8 @@ impl NPC {
{
let i = self.get_closest_player_idx_mut(&players);
if (players[i].x - self.x).abs() < 480 * 0x200
&& (players[i].y - self.y).abs() < 240 * 0x200
if (players[i].x - self.x).abs() < 0x3c000
&& (players[i].y - self.y).abs() < 0x1e000
&& self.rng.range(0..5) == 1
{
let mut particle = NPC::create(199, &state.npc_table);
@ -912,7 +912,7 @@ impl NPC {
}
for player in players {
if (player.x - self.x).abs() < 0x1000 && player.y > self.y && player.y < self.y + 96 * 0x200 {
if (player.x - self.x).abs() < 0x1000 && player.y > self.y && player.y < self.y + 0xc000 {
player.vel_y += 0x88;
}
}
@ -1160,10 +1160,10 @@ impl NPC {
self.npc_flags.set_rear_and_top_not_hurt(false);
self.damage = 0;
let player = self.get_closest_player_mut(players);
if (player.x < self.x + 25 * 0x200)
&& (player.x > self.x - 25 * 0x2000)
&& (player.y < self.y + 25 * 0x200)
&& (player.y > self.y - 25 * 0x200)
if (player.x < self.x + 0x3200)
&& (player.x > self.x - 0x32000)
&& (player.y < self.y + 0x3200)
&& (player.y > self.y - 0x3200)
{
self.action_num = 11;
self.action_counter = 0;
@ -1211,10 +1211,10 @@ impl NPC {
self.damage = 0;
let player = self.get_closest_player_mut(players);
if (player.x > self.x - 25 * 0x200)
&& (player.x < self.x + 25 * 0x2000)
&& (player.y < self.y + 25 * 0x200)
&& (player.y > self.y - 25 * 0x200)
if (player.x > self.x - 0x3200)
&& (player.x < self.x + 0x32000)
&& (player.y < self.y + 0x3200)
&& (player.y > self.y - 0x3200)
{
self.action_num = 21;
self.action_counter = 0;
@ -1304,10 +1304,10 @@ impl NPC {
self.npc_flags.set_rear_and_top_not_hurt(false);
self.damage = 0;
let player = self.get_closest_player_mut(players);
if (player.y < self.y + 25 * 0x200)
&& (player.y > self.y - 25 * 0x2000)
&& (player.x < self.x + 25 * 0x200)
&& (player.x > self.x - 25 * 0x200)
if (player.y < self.y + 0x3200)
&& (player.y > self.y - 0x32000)
&& (player.x < self.x + 0x3200)
&& (player.x > self.x - 0x3200)
{
self.action_num = 11;
self.action_counter = 0;
@ -1355,10 +1355,10 @@ impl NPC {
self.damage = 0;
let player = self.get_closest_player_mut(players);
if (player.y > self.y - 25 * 0x200)
&& (player.y < self.y + 25 * 0x2000)
&& (player.x < self.x + 25 * 0x200)
&& (player.x > self.x - 25 * 0x200)
if (player.y > self.y - 0x3200)
&& (player.y < self.y + 0x32000)
&& (player.x < self.x + 0x3200)
&& (player.x > self.x - 0x3200)
{
self.action_num = 21;
self.action_counter = 0;
@ -2646,15 +2646,15 @@ impl NPC {
npc_list: &NPCList,
) -> GameResult {
let player = self.get_closest_player_mut(players);
if (player.x - self.x).abs() < 320 * 0x200
&& player.y < self.y + 320 * 0x200
&& player.y > self.y - 160 * 0x200
if (player.x - self.x).abs() < 0x28000
&& player.y < self.y + 0x28000
&& player.y > self.y - 0x12c00
&& self.rng.range(0..100) == 2
{
let mut npc = NPC::create(73, &state.npc_table);
npc.cond.set_alive(true);
npc.x = self.x + self.rng.range(-6..6) * 0x200;
npc.y = self.y - 7 * 0x200;
npc.y = self.y - 0xe00;
let _ = npc_list.spawn(0, npc);
}

View file

@ -259,7 +259,7 @@ impl NPC {
}
let player = self.get_closest_player_mut(players);
if abs(self.x - player.x) < 12 * 0x200 && player.y > self.y && player.y < self.y + 0x1000 {
if abs(self.x - player.x) < 0x1800 && player.y > self.y && player.y < self.y + 0x1000 {
self.action_num = 15;
self.action_counter = 0;
}

View file

@ -17,7 +17,7 @@ impl NPC {
self.vel_x -= 0x8;
if self.x < 80 * 0x200 {
if self.x < 0xa000 {
self.cond.set_alive(false);
return Ok(());
}
@ -160,7 +160,7 @@ impl NPC {
}
self.vel_x -= 0x08;
if self.x < 80 * 0x200 {
if self.x < 0xa000 {
self.cond.set_alive(false)
}
@ -228,7 +228,7 @@ impl NPC {
}
self.vel_x -= 0x08;
if self.x < 80 * 0x200 {
if self.x < 0xa000 {
self.cond.set_alive(false)
}

View file

@ -24,7 +24,7 @@ impl NPC {
}
let player = self.get_closest_player_mut(players);
if abs(self.x - player.x) < 32 * 0x200 && self.y - 32 * 0x200 < player.y && self.y + 0x2000 > player.y {
if abs(self.x - player.x) < 0x4000 && self.y - 0x4000 < player.y && self.y + 0x2000 > player.y {
self.direction = if self.x > player.x { Direction::Left } else { Direction::Right };
}
}

View file

@ -140,7 +140,7 @@ impl NPC {
self.anim_num = 0;
let mut npc = NPC::create(257, &state.npc_table);
npc.x = self.x + 128 * 0x200;
npc.x = self.x + 0x10000;
npc.y = self.y;
npc.direction = Direction::Left;
npc.cond.set_alive(true);
@ -150,7 +150,7 @@ impl NPC {
let _ = npc_list.spawn(0x80, npc);
}
state.npc_super_pos = (self.x - 24 * 0x200, self.y - 0x1000);
state.npc_super_pos = (self.x - 0x3000, self.y - 0x1000);
}
17 => {
self.vel_x = 0;

View file

@ -242,7 +242,7 @@ impl GameEntity<([&mut Player; 2], &NPCList, &mut Stage, &mut BulletManager, &mu
_ if npc_hook_ran => Ok(()),
0 => self.tick_n000_null(),
1 => self.tick_n001_experience(state, stage),
2 => self.tick_n002_behemoth(state),
2 => self.tick_n002_behemoth(state, npc_list),
3 => self.tick_n003_dead_enemy(),
4 => self.tick_n004_smoke(state),
5 => self.tick_n005_green_critter(state, players),

View file

@ -161,6 +161,10 @@ impl NPC {
&players[idx]
}
pub fn face_player(&mut self, player: &Player) {
self.direction = if self.x > player.x { Direction::Left } else { Direction::Right };
}
/// Returns true if the [NPC] collides with a [Bullet].
pub fn collides_with_bullet(&self, bullet: &Bullet) -> bool {
(self.npc_flags.shootable()

View file

@ -8,7 +8,6 @@ use crate::framework::context::Context;
use crate::framework::error::GameResult;
use crate::framework::filesystem;
use crate::input::combined_menu_controller::CombinedMenuController;
use crate::input::touch_controls::TouchControlType;
use crate::map::Map;
use crate::scene::title_scene::TitleScene;
use crate::scene::Scene;

View file

@ -326,7 +326,7 @@ impl SharedGameState {
BMFontRenderer::load(&vec!["/".to_owned()], "/builtin/builtin_font.fnt", ctx)
})?;
let mut mod_list = ModList::load(ctx, &constants.string_table)?;
let mod_list = ModList::load(ctx, &constants.string_table)?;
for i in 0..0xffu8 {
let path = format!("/pxt/fx{:02x}.pxt", i);

View file

@ -13,8 +13,6 @@ use crate::framework::context::Context;
use crate::framework::error::{GameError, GameResult};
use crate::framework::filesystem;
use crate::framework::graphics::{create_texture, FilterMode};
use crate::settings::Settings;
use crate::shared_game_state::Season;
pub static mut I_MAG: f32 = 1.0;
pub static mut G_MAG: f32 = 1.0;