1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2024-11-16 02:43:02 +00:00

unfuck already implemented NPCs

This commit is contained in:
Alula 2021-05-05 14:04:59 +02:00
parent ea38f54c74
commit aed30141b4
No known key found for this signature in database
GPG key ID: 3E00485503A1D8BA
7 changed files with 689 additions and 132 deletions

View file

@ -185,7 +185,7 @@ pub struct NPCConsts {
pub n060_toroko: [Rect<u16>; 16],
#[serde(default = "default_n061_king")]
pub n061_king: [Rect<u16>; 20],
pub n061_king: [Rect<u16>; 22],
#[serde(default = "default_n062_kazuma_computer")]
pub n062_kazuma_computer: [Rect<u16>; 3],
@ -505,8 +505,8 @@ pub struct NPCConsts {
#[serde(default = "default_n168_boulder")]
pub n168_boulder: Rect<u16>,
#[serde(default = "default_n169_missile")]
pub n169_missile: [Rect<u16>; 18],
#[serde(default = "default_n169_balrog_missile_group")]
pub n169_balrog_missile_group: [Rect<u16>; 18],
#[serde(default = "default_n170_balrog_missile")]
pub n170_balrog_missile: [Rect<u16>; 4],
@ -1742,7 +1742,7 @@ fn default_n060_toroko() -> [Rect<u16>; 16] {
]
}
fn default_n061_king() -> [Rect<u16>; 20] {
fn default_n061_king() -> [Rect<u16>; 22] {
[
Rect { left: 224, top: 32, right: 240, bottom: 48 },
Rect { left: 240, top: 32, right: 256, bottom: 48 },
@ -1754,6 +1754,7 @@ fn default_n061_king() -> [Rect<u16>; 20] {
Rect { left: 224, top: 32, right: 240, bottom: 48 },
Rect { left: 272, top: 32, right: 288, bottom: 48 },
Rect { left: 0, top: 0, right: 0, bottom: 0 },
Rect { left: 112, top: 32, right: 128, bottom: 48 },
Rect { left: 224, top: 48, right: 240, bottom: 64 },
Rect { left: 240, top: 48, right: 256, bottom: 64 },
Rect { left: 256, top: 48, right: 272, bottom: 64 },
@ -1764,6 +1765,7 @@ fn default_n061_king() -> [Rect<u16>; 20] {
Rect { left: 224, top: 48, right: 240, bottom: 64 },
Rect { left: 272, top: 48, right: 288, bottom: 64 },
Rect { left: 0, top: 0, right: 0, bottom: 0 },
Rect { left: 112, top: 32, right: 128, bottom: 48 },
]
}
@ -2968,7 +2970,7 @@ fn default_n168_boulder() -> Rect<u16> {
Rect { left: 264, top: 56, right: 320, bottom: 96 }
}
fn default_n169_missile() -> [Rect<u16>; 18] {
fn default_n169_balrog_missile_group() -> [Rect<u16>; 18] {
[
Rect { left: 0, top: 0, right: 40, bottom: 24 },
Rect { left: 0, top: 48, right: 40, bottom: 72 },

View file

@ -1,8 +1,8 @@
use crate::framework::error::GameResult;
use num_traits::clamp;
use crate::caret::CaretType;
use crate::common::{CDEG_RAD, Direction};
use crate::common::{Direction, CDEG_RAD};
use crate::framework::error::GameResult;
use crate::npc::list::NPCList;
use crate::npc::NPC;
use crate::player::Player;
@ -11,7 +11,11 @@ use crate::shared_game_state::SharedGameState;
use crate::stage::Stage;
impl NPC {
pub(crate) fn tick_n009_balrog_falling_in(&mut self, state: &mut SharedGameState, npc_list: &NPCList) -> GameResult {
pub(crate) fn tick_n009_balrog_falling_in(
&mut self,
state: &mut SharedGameState,
npc_list: &NPCList,
) -> GameResult {
match self.action_num {
0 | 1 => {
if self.action_num == 0 {
@ -73,7 +77,12 @@ impl NPC {
Ok(())
}
pub(crate) fn tick_n010_balrog_shooting(&mut self, state: &mut SharedGameState, players: [&mut Player; 2], npc_list: &NPCList) -> GameResult {
pub(crate) fn tick_n010_balrog_shooting(
&mut self,
state: &mut SharedGameState,
players: [&mut Player; 2],
npc_list: &NPCList,
) -> GameResult {
let player = self.get_closest_player_mut(players);
match self.action_num {
@ -202,7 +211,13 @@ impl NPC {
Ok(())
}
pub(crate) fn tick_n012_balrog_cutscene(&mut self, state: &mut SharedGameState, players: [&mut Player; 2], npc_list: &NPCList, stage: &mut Stage) -> GameResult {
pub(crate) fn tick_n012_balrog_cutscene(
&mut self,
state: &mut SharedGameState,
players: [&mut Player; 2],
npc_list: &NPCList,
stage: &mut Stage,
) -> GameResult {
match self.action_num {
0 | 1 => {
if self.action_num == 0 {
@ -311,11 +326,7 @@ impl NPC {
}
self.action_counter2 += 1;
self.x += if self.action_counter2 / 2 % 2 != 0 {
0x200
} else {
-0x200
};
self.x += if self.action_counter2 / 2 % 2 != 0 { 0x200 } else { -0x200 };
if self.action_counter > 100 {
self.action_num = 11;
@ -354,11 +365,7 @@ impl NPC {
}
self.anim_counter += 1;
self.anim_num = if self.anim_counter / 2 % 2 != 0 {
5
} else {
6
};
self.anim_num = if self.anim_counter / 2 % 2 != 0 { 5 } else { 6 };
}
42 | 43 => {
if self.action_num == 42 {
@ -378,11 +385,7 @@ impl NPC {
}
self.anim_counter += 1;
self.anim_num = if self.anim_counter / 2 % 2 != 0 {
7
} else {
6
};
self.anim_num = if self.anim_counter / 2 % 2 != 0 { 7 } else { 6 };
}
50 => {
self.anim_num = 8;
@ -435,11 +438,7 @@ impl NPC {
}
self.action_counter2 += 1;
self.x += if self.action_counter2 / 2 % 2 != 0 {
0x200
} else {
-0x200
};
self.x += if self.action_counter2 / 2 % 2 != 0 { 0x200 } else { -0x200 };
self.anim_num = 5;
self.vel_x = 0;
@ -460,8 +459,7 @@ impl NPC {
self.vel_y = -4 * 0x200;
self.npc_flags.set_ignore_solidity(true);
for npc in npc_list.iter_alive()
.filter(|npc| npc.npc_type == 117 || npc.npc_type == 150) {
for npc in npc_list.iter_alive().filter(|npc| npc.npc_type == 117 || npc.npc_type == 150) {
npc.cond.set_alive(false)
}
@ -654,7 +652,12 @@ impl NPC {
Ok(())
}
pub(crate) fn tick_n036_balrog_hover(&mut self, state: &mut SharedGameState, players: [&mut Player; 2], npc_list: &NPCList) -> GameResult {
pub(crate) fn tick_n036_balrog_hover(
&mut self,
state: &mut SharedGameState,
players: [&mut Player; 2],
npc_list: &NPCList,
) -> GameResult {
let player = self.get_closest_player_mut(players);
match self.action_num {
@ -813,7 +816,12 @@ impl NPC {
}
/// note: vel_y2 stores currently caught player
pub(crate) fn tick_n068_balrog_running(&mut self, state: &mut SharedGameState, mut players: [&mut Player; 2], npc_list: &NPCList) -> GameResult {
pub(crate) fn tick_n068_balrog_running(
&mut self,
state: &mut SharedGameState,
mut players: [&mut Player; 2],
npc_list: &NPCList,
) -> GameResult {
match self.action_num {
0 | 1 => {
if self.action_num == 0 {
@ -862,7 +870,9 @@ impl NPC {
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 + 8 * 0x200 > players[pi].y { // 12.0fix9 / 8.0fix9
&& self.y - 12 * 0x200 < players[pi].y && self.y + 8 * 0x200 > players[pi].y
{
// 12.0fix9 / 8.0fix9
self.action_num = 10;
self.anim_num = 5;
self.vel_y2 = pi as i32;
@ -890,8 +900,11 @@ 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 && self.y + 8 * 0x200 > players[pi].y {
if self.action_counter >= 8
&& (players[pi].x - self.x).abs() < 12 * 0x200
&& self.y - 12 * 0x200 < players[pi].y
&& self.y + 8 * 0x200 > players[pi].y
{
self.action_num = 10;
self.anim_num = 5;
self.vel_y2 = pi as i32;
@ -983,5 +996,279 @@ impl NPC {
Ok(())
}
pub(crate) fn tick_n169_balrog_missile_group(
&mut self,
state: &mut SharedGameState,
mut players: [&mut Player; 2],
npc_list: &NPCList,
) -> GameResult {
match self.action_num {
0 | 1 => {
if self.action_num == 0 {
self.action_num = 1;
self.action_counter = 30;
self.anim_num = 0;
let player = self.get_closest_player_mut(players);
if self.x <= player.x {
self.direction = Direction::Right;
} else {
self.direction = Direction::Left;
}
}
if self.action_counter > 0 {
self.action_counter -= 1;
} else {
self.action_num = 2;
self.action_counter3 += 1;
}
}
2 | 3 => {
if self.action_num == 2 {
self.action_num = 3;
self.action_counter = 0;
self.anim_num = 1;
self.anim_counter = 0;
}
self.anim_counter += 1;
if self.anim_counter > 3 {
self.anim_counter = 0;
self.anim_num += 1;
if self.anim_num == 2 || self.anim_num == 4 {
state.sound_manager.play_sfx(23);
}
if self.anim_num > 4 {
self.anim_num = 1;
}
}
self.vel_x += self.direction.vector_x() * 0x20;
let player_idx = self.get_closest_player_idx_mut(&players);
let player = &mut players[player_idx];
if self.action_counter <= 7
|| self.x - 0x1800 >= player.x
|| self.x + 0x1800 <= player.x
|| self.y - 0x1800 >= player.y
|| self.y + 0x1000 <= player.y
{
self.action_counter += 1;
if self.action_counter <= 75 {
if self.flags.hit_left_wall() || self.flags.hit_right_wall() {
if self.action_counter2 > 4 {
self.action_num = 4;
self.action_counter = 0;
self.anim_num = 7;
self.vel_y = -0x5FF;
} else {
self.action_counter2 += 1;
}
} else {
self.action_counter2 = 0;
}
if (self.action_counter3 & 1) == 0 && self.action_counter > 25 {
self.action_num = 4;
self.action_counter = 0;
self.anim_num = 7;
self.vel_y = -0x5FF;
}
} else {
self.action_num = 9;
self.anim_num = 0;
}
} else {
self.action_num = 10;
self.anim_num = 5;
self.target_x = player_idx as i32;
player.cond.set_hidden(true);
player.damage(5, state, npc_list);
}
}
4 => {
let player_idx = self.get_closest_player_idx_mut(&players);
let player = &mut players[player_idx];
if self.x <= player.x {
self.direction = Direction::Right;
} else {
self.direction = Direction::Left;
}
self.action_counter += 1;
if self.action_counter <= 29 && self.action_counter % 6 == 1 {
state.sound_manager.play_sfx(39);
let mut npc = NPC::create(170, &state.npc_table);
npc.cond.set_alive(true);
npc.x = self.x;
npc.y = self.y;
npc.direction = self.direction;
let _ = npc_list.spawn(0x100, npc);
}
if self.flags.hit_bottom_wall() {
self.action_num = 9;
self.anim_num = 8;
state.quake_counter = 30;
state.sound_manager.play_sfx(26);
}
if self.action_counter > 7
&& self.x - 0x1800 < player.x
&& self.x + 0x1800 > player.x
&& self.y - 0x1800 < player.y
&& self.y + 0x1000 > player.y
{
self.action_num = 10;
self.anim_num = 5;
player.cond.set_hidden(true);
player.damage(10, state, npc_list);
}
}
9 => {
self.vel_x = 4 * self.vel_x / 5;
if self.vel_x == 0 {
self.action_num = 0;
}
}
10 => {
let player = &mut players[self.target_x as usize];
player.x = self.x;
player.y = self.y;
self.vel_x = 4 * self.vel_x / 5;
if self.vel_x == 0 {
self.action_num = 11;
self.action_counter = 0;
self.anim_num = 5;
self.anim_counter = 0;
}
}
11 => {
let player = &mut players[self.target_x as usize];
player.x = self.x;
player.y = self.y;
self.animate(2, 5, 6);
self.action_counter += 1;
if self.action_counter > 100 {
self.action_num = 20;
}
}
20 | 21 => {
let player = &mut players[self.target_x as usize];
if self.action_num == 20 {
state.sound_manager.play_sfx(25);
player.cond.set_hidden(false);
if self.direction != Direction::Left {
player.x -= 0x800;
player.y -= 0x1000;
player.vel_x = -0x5FF;
player.vel_y = -0x200;
player.direction = Direction::Left;
self.direction = Direction::Left;
} else {
player.x += 0x800;
player.y -= 0x1000;
player.vel_x = 0x5FF;
player.vel_y = -0x200;
player.direction = Direction::Right;
self.direction = Direction::Right;
}
self.action_num = 21;
self.action_counter = 0;
self.anim_num = 7;
}
self.action_counter += 1;
if self.action_counter >= 50 {
self.action_num = 0;
}
}
_ => {}
}
self.vel_y += 0x20;
self.vel_x = self.vel_x.clamp(-0x300, 0x300);
if self.vel_y > 0x5FF {
self.vel_y = 0x5FF;
}
self.x += self.vel_x;
self.y += self.vel_y;
Ok(())
}
pub(crate) fn tick_n170_balrog_missile(
&mut self,
state: &mut SharedGameState,
players: [&mut Player; 2],
npc_list: &NPCList,
) -> GameResult {
if (self.direction == Direction::Left && self.flags.hit_left_wall())
|| (self.direction == Direction::Right && self.flags.hit_right_wall())
{
state.sound_manager.play_sfx(44);
npc_list.create_death_smoke(self.x, self.y, 0, 3, state, &self.rng);
self.vanish(state);
return Ok(());
}
if self.action_num == 0 {
self.action_num = 1;
self.vel_x = if self.direction != Direction::Left {
self.rng.range(-2..-1) * 0x200
} else {
self.rng.range(1..2) * 0x200
};
self.vel_y = self.rng.range(-2..0) * 0x200;
}
if self.action_num == 1 {
self.action_counter3 += 1;
self.vel_x += self.direction.vector_x() * 0x20;
if self.action_counter3 % 3 == 1 {
state.create_caret(
self.x + 0x1000 * self.direction.vector_x(),
self.y,
CaretType::Exhaust,
self.direction,
);
}
if self.action_counter3 >= 50 {
self.vel_y = 0;
} else {
let player = self.get_closest_player_mut(players);
self.vel_y = if self.y >= player.y { self.vel_y - 32 } else { self.vel_y + 32 };
}
self.anim_num = (self.anim_num + 1) & 1;
}
if self.vel_x < -0x400 {
self.vel_x = -0x600;
}
if self.vel_x > 0x400 {
self.vel_x = 0x600;
}
self.x += self.vel_x;
self.y += self.vel_y;
Ok(())
}
}

View file

@ -25,6 +25,7 @@ impl NPC {
}
let dir_offset = if self.direction == Direction::Left { 0 } else { 2 };
self.anim_rect = state.constants.npc.n029_cthulhu[self.anim_num as usize + dir_offset];
Ok(())
@ -40,14 +41,11 @@ impl NPC {
}
pub(crate) fn tick_n055_kazuma(&mut self, state: &mut SharedGameState) -> GameResult {
let off = if self.direction == Direction::Left { 0 } else { 6 };
match self.action_num {
0 => {
self.action_num = 1;
self.anim_num = 0;
self.anim_counter = 0;
self.anim_rect = state.constants.npc.n055_kazuma[off];
}
3 | 4 => {
if self.action_num == 3 {
@ -56,32 +54,10 @@ impl NPC {
self.anim_counter = 0;
}
self.anim_counter += 1;
if self.anim_counter > 4 {
self.anim_counter = 0;
self.anim_num += 1;
}
if self.anim_num > 4 {
self.anim_num = 1;
}
match self.direction {
Direction::Left => {
self.x -= 0x200;
}
Direction::Right => {
self.x += 0x200;
}
_ => {}
}
self.anim_rect = state.constants.npc.n055_kazuma[self.anim_num as usize + off];
}
5 => {
self.anim_num = 5;
self.anim_rect = state.constants.npc.n055_kazuma[self.anim_num as usize + off];
self.animate(4, 1, 4);
self.x += self.direction.vector_x() * 0x200;
}
5 => self.anim_num = 5,
_ => {}
}
@ -93,10 +69,14 @@ impl NPC {
self.y += self.vel_y;
let dir_offset = if self.direction == Direction::Left { 0 } else { 6 };
self.anim_rect = state.constants.npc.n055_kazuma[self.anim_num as usize + dir_offset];
Ok(())
}
pub(crate) fn tick_n061_king(&mut self, state: &mut SharedGameState) -> GameResult {
pub(crate) fn tick_n061_king(&mut self, state: &mut SharedGameState, npc_list: &NPCList) -> GameResult {
match self.action_num {
0 | 1 => {
if self.action_num == 0 {
@ -132,18 +112,13 @@ impl NPC {
}
self.anim_num = 2;
if self.direction == Direction::Left {
self.vel_x = -0x200;
} else {
self.vel_x = 0x200;
}
if self.action_counter != 0 && self.flags.hit_bottom_wall() {
self.action_num = 5;
}
self.vel_x = self.direction.vector_x() * 0x200;
self.action_counter += 1;
if self.action_counter > 1 && self.flags.hit_bottom_wall() {
self.action_num = 5;
}
}
8 | 9 => {
if self.action_num == 8 {
@ -152,21 +127,8 @@ impl NPC {
self.anim_counter = 0;
}
self.anim_counter += 1;
if self.anim_counter > 4 {
self.anim_counter = 0;
self.anim_num += 1;
}
if self.anim_num > 7 {
self.anim_num = 4;
}
if self.direction == Direction::Left {
self.vel_x = -0x200;
} else {
self.vel_x = 0x200;
}
self.animate(4, 4, 7);
self.vel_x = self.direction.vector_x() * 0x200;
}
10 | 11 => {
if self.action_num == 10 {
@ -175,32 +137,100 @@ impl NPC {
self.anim_counter = 0;
}
self.anim_counter += 1;
if self.anim_counter > 2 {
self.animate(2, 4, 7);
self.vel_x = self.direction.vector_x() * 0x400;
}
20 => {
let mut npc = NPC::create(145, &state.npc_table);
npc.cond.set_alive(true);
npc.direction = Direction::Right;
npc.parent_id = self.id;
let _ = npc_list.spawn(0x100, npc);
self.anim_num = 0;
self.action_num = 0;
}
30 | 31 => {
if self.action_num == 30 {
self.action_num = 31;
self.action_counter = 0;
self.anim_counter = 0;
self.vel_y = 0;
}
self.anim_num = 2;
self.vel_x = self.direction.vector_x() * 0x600;
if self.flags.hit_left_wall() {
self.action_num = 7;
self.action_counter = 0;
self.anim_counter = 0;
self.direction = Direction::Right;
self.vel_y = -0x400;
self.vel_x = 0x200;
state.sound_manager.play_sfx(71);
npc_list.create_death_smoke(self.x, self.y, 0x800, 4, state, &self.rng);
}
}
40 | 42 => {
if self.action_num == 40 {
self.action_num = 42;
self.action_counter = 0;
self.anim_num = 8;
state.sound_manager.play_sfx(29);
}
self.anim_num += 1;
if self.anim_num > 9 {
self.anim_num = 8;
}
if self.anim_num > 7 {
self.anim_num = 4;
}
self.action_counter += 1;
if self.action_counter > 100 {
self.action_num = 50;
self.anim_num = 10;
self.spritesheet_id = 20;
if self.direction == Direction::Left {
self.vel_x = -0x400;
} else {
let mut npc = NPC::create(4, &state.npc_table);
npc.cond.set_alive(true);
npc.direction = Direction::Left;
for _ in 0..4 {
npc.x = self.x + self.rng.range(-12..12) as i32 * 0x200;
npc.y = self.y + self.rng.range(-12..12) as i32 * 0x200;
npc.vel_x = self.rng.range(-0x155..0x155) as i32;
npc.vel_y = self.rng.range(-0x600..0) as i32;
let _ = npc_list.spawn(0x100, npc.clone());
}
}
}
60 | 61 => {
if self.action_num == 60 {
self.action_num = 61;
self.anim_num = 6;
self.action_counter2 = 1;
self.vel_y = -0x5ff;
self.vel_x = 0x400;
}
self.vel_y += 0x40;
if self.flags.hit_bottom_wall() {
self.vel_x = 0;
self.action_num = 0;
self.action_counter2 = 0;
}
}
// todo: 20 - king's sword
// todo: 30,31 - pre misery attack
// todo: 40,42 - dying
// todo: 60,61 - leap
_ => {}
}
if self.action_num < 30 || self.action_num >= 40 {
self.vel_y += 0x40;
self.vel_x = clamp(self.vel_x, -0x400, 0x400);
self.vel_x = self.vel_x.clamp(-0x400, 0x400);
if self.vel_y > 0x5ff {
self.vel_y = 0x5ff;
@ -210,11 +240,9 @@ impl NPC {
self.x += self.vel_x;
self.y += self.vel_y;
if self.direction == Direction::Left {
self.anim_rect = state.constants.npc.n061_king[self.anim_num as usize];
} else {
self.anim_rect = state.constants.npc.n061_king[self.anim_num as usize + 10];
}
let dir_offset = if self.direction == Direction::Left { 0 } else { 11 };
self.anim_rect = state.constants.npc.n061_king[self.anim_num as usize + dir_offset];
Ok(())
}
@ -310,21 +338,9 @@ impl NPC {
self.anim_counter = 0;
}
self.anim_counter += 1;
if self.anim_counter > 4 {
self.anim_counter = 0;
self.anim_num += 1;
}
self.animate(4, 2, 5);
if self.anim_num > 5 {
self.anim_num = 2;
}
if self.direction == Direction::Left {
self.vel_x = -0x200;
} else {
self.vel_x = 0x200;
}
self.vel_x = self.direction.vector_x() * 0x200;
}
_ => {}
}
@ -361,14 +377,15 @@ impl NPC {
} else {
self.direction = Direction::Left;
}
self.x = if self.direction != Direction::Left { parent.x + 5120 } else { parent.x - 5120 };
self.x = parent.x + self.direction.vector_x() * 0x1400;
self.y = parent.y;
}
}
let dir_offset = if self.direction == Direction::Left { 0 } else { 1 };
self.anim_rect = state.constants.npc.n145_king_sword[self.anim_num as usize + dir_offset];
self.anim_rect = state.constants.npc.n145_king_sword[dir_offset];
Ok(())
}
@ -404,4 +421,57 @@ impl NPC {
Ok(())
}
pub(crate) fn tick_n167_booster_falling(&mut self, state: &mut SharedGameState, npc_list: &NPCList) -> GameResult {
match self.action_num {
0 => {
self.action_num = 1;
self.anim_num = 1;
}
10 => {
self.anim_num = 0;
self.vel_y += 0x40;
if self.vel_y > 0x5FF {
self.vel_y = 0x5FF;
}
self.y += self.vel_y;
}
20 | 21 => {
if self.action_num == 20 {
self.action_num = 21;
self.action_counter = 0;
self.anim_num = 0;
state.sound_manager.play_sfx(29);
}
self.anim_num += 1;
if self.anim_num > 2 {
self.anim_num = 1;
}
self.action_counter += 1;
if self.action_counter > 100 {
let mut npc = NPC::create(4, &state.npc_table);
npc.cond.set_alive(true);
npc.direction = Direction::Left;
for _ in 0..4 {
npc.x = self.x + self.rng.range(-12..12) as i32 * 0x200;
npc.y = self.y + self.rng.range(-12..12) as i32 * 0x200;
npc.vel_x = self.rng.range(-0x155..0x155) as i32;
npc.vel_y = self.rng.range(-0x600..0) as i32;
let _ = npc_list.spawn(0x100, npc.clone());
}
self.cond.set_alive(false);
}
}
_ => {}
}
self.anim_rect = state.constants.npc.n167_booster_falling[self.anim_num as usize];
Ok(())
}
}

View file

@ -1,5 +1,5 @@
use crate::caret::CaretType;
use crate::common::{Direction, CDEG_RAD};
use crate::common::{CDEG_RAD, Direction};
use crate::framework::error::GameResult;
use crate::npc::list::NPCList;
use crate::npc::NPC;
@ -821,6 +821,7 @@ impl NPC {
}
let dir_offset = if self.direction == Direction::Left { 0 } else { 2 };
self.anim_rect = state.constants.npc.n163_dr_gero[self.anim_num as usize + dir_offset];
Ok(())
@ -852,11 +853,59 @@ impl NPC {
}
let dir_offset = if self.direction == Direction::Left { 0 } else { 2 };
self.anim_rect = state.constants.npc.n164_nurse_hasumi[self.anim_num as usize + dir_offset];
Ok(())
}
pub(crate) fn tick_n168_boulder(&mut self, state: &mut SharedGameState) -> GameResult {
match self.action_num {
0 => {
self.action_num = 1;
}
10 | 11 => {
if self.action_num == 10 {
self.action_num = 11;
self.action_counter = 0;
self.target_x = self.x;
}
self.action_counter += 1;
self.x = self.target_x;
if ((self.action_counter / 3) & 1) != 0 {
self.x += 0x200;
}
}
20 | 21 => {
if self.action_num == 20 {
self.action_num = 21;
self.action_counter = 0;
self.vel_y = -0x400;
self.vel_x = 0x100;
state.sound_manager.play_sfx(25);
}
self.x += self.vel_x;
self.y += self.vel_y;
if self.action_counter != 0 && self.flags.hit_bottom_wall() {
state.sound_manager.play_sfx(35);
state.quake_counter = 40;
self.action_num = 0;
}
if self.action_counter == 0 {
self.action_counter += 1;
}
}
_ => {}
}
self.anim_rect = state.constants.npc.n168_boulder;
Ok(())
}
pub(crate) fn tick_n173_gaudi_armored(
&mut self,
state: &mut SharedGameState,

View file

@ -1,7 +1,7 @@
use num_traits::{abs, clamp};
use crate::caret::CaretType;
use crate::common::{Direction, CDEG_RAD};
use crate::common::{CDEG_RAD, Direction};
use crate::framework::error::GameResult;
use crate::npc::list::NPCList;
use crate::npc::NPC;
@ -905,6 +905,147 @@ impl NPC {
Ok(())
}
pub(crate) fn tick_n122_colon_enraged(
&mut self,
state: &mut SharedGameState,
players: [&mut Player; 2],
) -> GameResult {
match self.action_num {
0 | 1 => {
if self.action_num == 0 {
self.action_num = 1;
self.anim_num = 0;
self.anim_counter = 0;
}
if self.rng.range(0..120) == 10 {
self.action_num = 2;
self.action_counter = 0;
self.anim_num = 1;
}
let player = self.get_closest_player_mut(players);
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 {
self.direction = Direction::Right;
} else {
self.direction = Direction::Left;
}
}
}
2 => {
self.action_counter += 1;
if self.action_counter > 8 {
self.action_num = 1;
self.anim_num = 0;
}
}
10 | 11 => {
if self.action_num == 10 {
self.life = 1000;
self.action_num = 11;
self.action_counter = self.rng.range(0..50) as u16;
self.anim_num = 0;
self.damage = 0;
}
if self.action_counter != 0 {
self.action_counter -= 1;
} else {
self.action_num = 13;
}
}
13 | 14 => {
if self.action_num == 13 {
self.action_num = 14;
self.action_counter = self.rng.range(0..50) as u16;
let player = self.get_closest_player_mut(players);
if self.x <= player.x {
self.direction = Direction::Right;
} else {
self.direction = Direction::Left;
}
}
self.animate(2, 2, 5);
self.vel_x = if self.direction != Direction::Left { self.vel_x + 64 } else { self.vel_x - 64 };
if self.action_counter != 0 {
self.action_counter -= 1;
} else {
self.npc_flags.set_shootable(true);
self.action_num = 15;
self.anim_num = 2;
self.vel_y = -512;
self.damage = 2;
}
}
15 => {
if self.flags.hit_bottom_wall() {
self.npc_flags.set_shootable(true);
self.vel_x = 0;
self.action_num = 10;
self.damage = 0;
}
}
20 => {
if self.flags.hit_bottom_wall() {
self.vel_x = 0;
self.action_num = 21;
self.damage = 0;
if self.anim_num == 6 {
self.anim_num = 8;
} else {
self.anim_num = 9;
}
self.action_counter = self.rng.range(300..400) as u16;
}
}
21 => {
if self.action_counter > 0 {
self.action_counter -= 1;
} else {
self.npc_flags.set_shootable(true);
self.life = 1000;
self.action_num = 11;
self.action_counter = self.rng.range(0..50) as u16;
self.anim_num = 0;
}
}
_ => {}
}
if self.action_num > 10 && self.action_num < 20 && self.life != 1000 {
self.action_num = 20;
self.vel_y = -512;
self.anim_num = self.rng.range(6..7) as u16;
self.npc_flags.set_shootable(false);
}
self.vel_y += 32;
self.vel_x = self.vel_x.clamp(-0x200, 0x200);
if self.vel_y > 0x5ff {
self.vel_y = 0x5ff;
}
self.y += self.vel_y;
self.x += self.vel_x;
let dir_offset = if self.direction == Direction::Left { 0 } else { 10 };
self.anim_rect = state.constants.npc.n122_colon_enraged[self.anim_num as usize + dir_offset];
Ok(())
}
pub(crate) fn tick_n124_sunstone(&mut self, state: &mut SharedGameState) -> GameResult {
match self.action_num {
0 | 1 => {
@ -1483,7 +1624,6 @@ impl NPC {
self.y += self.vel_y;
self.x += self.vel_x;
let dir_offset = if self.direction == Direction::Left { 0 } else { 2 };
self.anim_rect = state.constants.npc.n135_skeleton[self.anim_num as usize + dir_offset];

View file

@ -225,7 +225,7 @@ impl GameEntity<([&mut Player; 2], &NPCList, &mut Stage, &BulletManager, &mut Fl
58 => self.tick_n058_basu(state, players, npc_list),
59 => self.tick_n059_eye_door(state, players),
60 => self.tick_n060_toroko(state, players),
61 => self.tick_n061_king(state),
61 => self.tick_n061_king(state, npc_list),
62 => self.tick_n062_kazuma_computer(state),
63 => self.tick_n063_toroko_stick(state),
64 => self.tick_n064_first_cave_critter(state, players),
@ -286,6 +286,7 @@ impl GameEntity<([&mut Player; 2], &NPCList, &mut Stage, &BulletManager, &mut Fl
119 => self.tick_n119_table_chair(state),
120 => self.tick_n120_colon_a(state),
121 => self.tick_n121_colon_b(state),
122 => self.tick_n122_colon_enraged(state, players),
123 => self.tick_n123_curly_boss_bullet(state),
124 => self.tick_n124_sunstone(state),
125 => self.tick_n125_hidden_item(state, npc_list),
@ -330,6 +331,10 @@ impl GameEntity<([&mut Player; 2], &NPCList, &mut Stage, &BulletManager, &mut Fl
164 => self.tick_n164_nurse_hasumi(state),
165 => self.tick_n165_curly_collapsed(state, players),
166 => self.tick_n166_chaba(state),
167 => self.tick_n167_booster_falling(state, npc_list),
168 => self.tick_n168_boulder(state),
169 => self.tick_n169_balrog_missile_group(state, players, npc_list),
170 => self.tick_n170_balrog_missile(state, players, npc_list),
192 => self.tick_n192_scooter(state),
193 => self.tick_n193_broken_scooter(state),
194 => self.tick_n194_broken_blue_robot(state),

View file

@ -104,6 +104,8 @@ pub struct SharedGameState {
pub base_path: String,
pub npc_table: NPCTable,
pub npc_super_pos: (i32, i32),
pub npc_curly_target: (i32, i32),
pub npc_curly_counter: u16,
pub stages: Vec<StageData>,
pub frame_time: f64,
pub debugger: bool,
@ -175,6 +177,8 @@ impl SharedGameState {
base_path: str!(base_path),
npc_table: NPCTable::new(),
npc_super_pos: (0, 0),
npc_curly_target: (0, 0),
npc_curly_counter: 0,
stages: Vec::with_capacity(96),
frame_time: 0.0,
debugger: false,