1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2025-03-24 02:49:21 +00:00

let npc access other npcs, add misery/stick toroko for shack scene

This commit is contained in:
Alula 2020-09-19 17:37:32 +02:00
parent e0b1eba88d
commit 39d0d2d6f4
No known key found for this signature in database
GPG key ID: 3E00485503A1D8BA
8 changed files with 559 additions and 279 deletions

View file

@ -181,6 +181,8 @@ pub struct NPCConsts {
pub n063_toroko_stick: [Rect<usize>; 12],
pub n064_first_cave_critter: [Rect<usize>; 6],
pub n065_first_cave_bat: [Rect<usize>; 8],
pub n066_misery_bubble: [Rect<usize>; 4],
pub n067_misery_floating: [Rect<usize>; 16],
pub n070_sparkle: [Rect<usize>; 4],
pub n071_chinfish: [Rect<usize>; 6],
pub n072_sprinkler: [Rect<usize>; 2],
@ -757,6 +759,32 @@ impl EngineConstants {
Rect { left: 64, top: 48, right: 80, bottom: 64 },
Rect { left: 80, top: 48, right: 96, bottom: 64 },
],
n066_misery_bubble: [
Rect { left: 32, top: 192, right: 56, bottom: 216 },
Rect { left: 56, top: 192, right: 80, bottom: 216 },
Rect { left: 32, top: 216, right: 56, bottom: 240 },
Rect { left: 56, top: 216, right: 80, bottom: 240 },
],
n067_misery_floating: [
Rect { left: 80, top: 0, right: 96, bottom: 16 }, // left
Rect { left: 96, top: 0, right: 112, bottom: 16 },
Rect { left: 112, top: 0, right: 128, bottom: 16 },
Rect { left: 128, top: 0, right: 144, bottom: 16 },
Rect { left: 144, top: 0, right: 160, bottom: 16 },
Rect { left: 160, top: 0, right: 176, bottom: 16 },
Rect { left: 176, top: 0, right: 192, bottom: 16 },
Rect { left: 144, top: 0, right: 160, bottom: 16 },
Rect { left: 80, top: 16, right: 96, bottom: 32 }, // right
Rect { left: 96, top: 16, right: 112, bottom: 32 },
Rect { left: 112, top: 16, right: 128, bottom: 32 },
Rect { left: 128, top: 16, right: 144, bottom: 32 },
Rect { left: 144, top: 16, right: 160, bottom: 32 },
Rect { left: 160, top: 16, right: 176, bottom: 32 },
Rect { left: 176, top: 16, right: 192, bottom: 32 },
Rect { left: 144, top: 16, right: 160, bottom: 32 },
],
n070_sparkle: [
Rect { left: 96, top: 48, right: 112, bottom: 64 },
Rect { left: 112, top: 48, right: 128, bottom: 64 },

View file

@ -65,163 +65,6 @@ impl NPC {
Ok(())
}
pub(crate) fn tick_n060_toroko(&mut self, state: &mut SharedGameState, player: &Player) -> GameResult {
match self.action_num {
0 | 1 => {
if self.action_num == 0 {
self.action_num = 1;
self.anim_num = 0;
self.anim_counter = 0;
self.vel_x = 0;
}
if state.game_rng.range(0..120) == 10 {
self.action_num = 2;
self.action_counter = 0;
self.anim_num = 1;
}
if (self.x - (16 * 0x200) < player.x) && (self.x + (16 * 0x200) > player.x)
&& (self.y - (16 * 0x200) < player.y) && (self.y + (16 * 0x200) > player.y) {
if self.x > player.x {
self.direction = Direction::Left;
} else {
self.direction = Direction::Right;
}
}
}
2 => {
self.action_counter += 1;
if self.action_counter > 8 {
self.action_num = 1;
self.anim_num = 0;
}
}
3 | 4 => {
if self.action_num == 3 {
self.action_num = 4;
self.anim_num = 1;
self.anim_counter = 0;
}
self.anim_counter += 1;
if self.anim_counter > 2 {
self.anim_counter = 0;
self.anim_num += 1;
}
if self.anim_num > 4 {
self.anim_num = 1;
}
if self.flags.hit_left_wall() {
self.direction = Direction::Right;
self.vel_x = 0x200;
}
if self.flags.hit_right_wall() {
self.direction = Direction::Left;
self.vel_x = -0x200;
}
if self.direction == Direction::Left {
self.vel_x = -0x400;
} else {
self.vel_x = 0x400;
}
}
6 | 7 => {
if self.action_num == 6 {
self.action_num = 7;
self.action_counter = 0;
self.anim_num = 1;
self.anim_counter = 0;
self.vel_y = -0x400;
}
self.anim_counter += 1;
if self.anim_counter > 2 {
self.anim_counter = 0;
self.anim_num += 1;
}
if self.anim_num > 4 {
self.anim_num = 1;
}
if self.direction == Direction::Left {
self.vel_x = -0x100;
} else {
self.vel_x = 0x100;
}
if self.action_counter != 0 && self.flags.hit_bottom_wall() {
self.action_num = 3;
}
self.action_counter += 1;
}
8 | 9 => {
if self.action_num == 8 {
self.anim_num = 1;
self.action_counter = 0;
self.action_num = 9;
self.vel_y = -0x200;
}
if self.action_counter != 0 && self.flags.hit_bottom_wall() {
self.action_num = 0;
}
self.action_counter += 1;
}
10 => {
self.action_num = 11;
self.anim_num = 6;
self.vel_y = -0x400;
// todo play sound 50
if self.direction == Direction::Left {
self.vel_x = -0x100;
} else {
self.vel_x = 0x100;
}
}
11 => {
if self.action_counter != 0 && self.flags.hit_bottom_wall() {
self.action_num = 12;
self.anim_num = 7;
self.npc_flags.set_interactable(true);
}
self.action_counter += 1;
}
12 => {
self.vel_x = 0;
}
_ => {}
}
self.vel_y += 0x40;
self.vel_x = clamp(self.vel_x, -0x400, 0x400);
if self.vel_y > 0x5ff {
self.vel_y = 0x5ff;
}
self.x += self.vel_x;
self.y += self.vel_y;
if self.direction == Direction::Left {
self.anim_rect = state.constants.npc.n060_toroko[self.anim_num as usize];
} else {
self.anim_rect = state.constants.npc.n060_toroko[self.anim_num as usize + 8];
}
Ok(())
}
pub(crate) fn tick_n061_king(&mut self, state: &mut SharedGameState) -> GameResult {
match self.action_num {
0 | 1 => {
@ -409,15 +252,15 @@ impl NPC {
}
pub(crate) fn tick_n074_jack(&mut self, state: &mut SharedGameState) -> GameResult {
if self.action_num == 0 {
self.action_num = 1;
self.anim_num = 0;
self.anim_counter = 0;
self.vel_x = 0;
}
match self.action_num {
1 => {
0 | 1 => {
if self.action_num == 0 {
self.action_num = 1;
self.anim_num = 0;
self.anim_counter = 0;
self.vel_x = 0;
}
if state.game_rng.range(0..120) == 10 {
self.action_num = 2;
self.action_counter = 0;

View file

@ -7,112 +7,6 @@ use crate::player::Player;
use crate::SharedGameState;
impl NPC {
pub(crate) fn tick_n063_toroko_stick(&mut self, state: &mut SharedGameState) -> GameResult {
match self.action_num {
0 | 1 => {
if self.action_num == 0 {
self.action_num = 1;
self.action_counter = 0;
self.anim_counter = 0;
self.vel_y = -0x400;
}
if self.vel_y > 0 {
self.npc_flags.set_ignore_solidity(true);
}
self.anim_counter += 1;
if self.anim_counter > 2 {
self.anim_counter = 0;
self.anim_num += 1;
if self.anim_num > 3 {
self.anim_num = 0;
}
}
self.vel_x = 0x100 * self.direction.vector_x();
self.action_counter += 1;
if self.action_counter != 0 && self.flags.hit_bottom_wall() {
self.action_num = 2;
}
}
2 | 3 => {
if self.action_num ==2 {
self.action_num = 3;
self.action_counter = 0;
self.anim_num = 0;
self.anim_counter = 0;
}
self.anim_counter += 1;
if self.anim_counter > 2 {
self.anim_counter = 0;
self.anim_num += 1;
if self.anim_num > 3 {
self.anim_num = 0;
}
}
self.action_counter += 1;
if self.action_counter > 50 {
self.action_counter = 40;
self.vel_x = -self.vel_x;
self.direction = self.direction.opposite();
}
if self.action_counter > 35 {
self.npc_flags.set_shootable(true);
}
self.vel_x += 0x40 * self.direction.vector_x();
if self.shock > 0 {
self.action_num = 4;
self.anim_num = 4;
self.vel_y = -0x400;
self.npc_flags.set_shootable(false);
self.damage = 0;
}
}
4 => {
self.vel_x = 0x100 * self.direction.vector_x();
self.action_counter += 1;
if self.action_counter != 0 && self.flags.hit_bottom_wall() {
self.action_num = 5;
self.npc_flags.set_interactable(true);
}
}
5 => {
self.vel_x = 0;
self.anim_num = 5;
}
_ => {}
}
self.vel_y += 0x40;
self.vel_x = clamp(self.vel_x, -0x400, 0x400);
if self.vel_y > 0x5ff {
self.vel_y = 0x5ff;
}
self.x += self.vel_x;
self.y += self.vel_y;
if self.direction == Direction::Left {
self.anim_rect = state.constants.npc.n063_toroko_stick[self.anim_num as usize];
} else {
self.anim_rect = state.constants.npc.n063_toroko_stick[self.anim_num as usize + 6];
}
Ok(())
}
pub(crate) fn tick_n071_chinfish(&mut self, state: &mut SharedGameState) -> GameResult {
if self.action_num == 0 {
self.action_num = 1;

239
src/npc/misery.rs Normal file
View file

@ -0,0 +1,239 @@
use std::cell::RefCell;
use std::collections::HashMap;
use num_traits::clamp;
use num_traits::real::Real;
use crate::common::Direction;
use crate::ggez::GameResult;
use crate::npc::{NPC, NPCMap, NPCTable};
use crate::SharedGameState;
impl NPC {
pub(crate) fn tick_n066_misery_bubble(&mut self, state: &mut SharedGameState, map: &HashMap<u16, RefCell<NPC>>) -> GameResult {
match self.action_num {
0 | 1 => {
if self.action_num == 0 {
for (&id, npc_cell) in map.iter() {
if self.id == id { continue; }
let npc = npc_cell.borrow();
if npc.event_num == 1000 {
self.action_counter2 = npc.id;
self.target_x = npc.x;
self.target_y = npc.y;
let angle = ((self.y - self.target_y) as f64 / (self.x - self.target_x) as f64 ).atan();
self.vel_x = (angle.cos() * 1024.0) as isize; // 2.0fix9
self.vel_y = (angle.sin() * 1024.0) as isize;
log::info!("bubble toss: {:#x} {:#x}", self.vel_x, self.vel_y);
break;
}
}
if self.action_counter2 == 0 {
self.action_num = 0xffff;
return Ok(());
}
self.action_num = 1;
}
self.anim_counter += 1;
if self.anim_counter > 1 {
self.anim_counter = 0;
self.anim_num += 1;
if self.anim_num > 1 {
self.anim_num = 0;
}
}
if (self.x - self.target_x).abs() < 3 * 0x200 && (self.y - self.target_y).abs() < 3 * 0x200 {
self.action_num = 2;
self.anim_num = 2;
state.sound_manager.play_sfx(21);
if let Some(npc) = map.get(&self.action_counter2) {
npc.borrow_mut().cond.set_alive(false);
}
}
}
2 => {
self.vel_x -= 0x20;
self.vel_y -= 0x20;
self.vel_x = clamp(self.vel_x, -0x5ff, 0x5ff);
self.vel_y = clamp(self.vel_y, -0x5ff, 0x5ff);
if self.y < -8 * 0x200 {
self.cond.set_alive(false);
}
self.anim_counter += 1;
if self.anim_counter > 3 {
self.anim_counter = 0;
self.anim_num += 1;
if self.anim_num > 3 {
self.anim_num = 2;
}
}
}
_ => {}
}
self.x += self.vel_x;
self.y += self.vel_y;
self.anim_rect = state.constants.npc.n066_misery_bubble[self.anim_num as usize];
Ok(())
}
pub(crate) fn tick_n067_misery_floating(&mut self, state: &mut SharedGameState) -> GameResult {
match self.action_num {
0 | 1 => {
if self.action_num == 0 {
self.action_num = 1;
self.anim_num = 0;
self.target_x = self.x;
self.target_y = self.y;
state.sound_manager.play_sfx(29);
}
self.x = self.target_x + state.game_rng.range(-1..1) as isize * 0x200;
self.action_counter += 1;
if self.action_counter >= 32 {
self.action_num = 10;
}
}
10 | 11 => {
if self.action_num == 10 {
self.action_num = 1;
self.action_counter = 0;
self.anim_num = 0;
self.vel_y = 0x200;
}
if self.target_y < self.y {
self.vel_y -= 0x10;
}
if self.target_y > self.y {
self.vel_y += 0x10;
}
self.vel_y = clamp(self.vel_y, -0x100, 0x100);
}
13 => {
self.anim_num = 1;
self.vel_y += 0x40;
if self.vel_y > 0x5ff {
self.vel_y = 0x5ff;
}
if self.flags.hit_bottom_wall() {
state.sound_manager.play_sfx(23);
self.vel_y = 0;
self.action_num = 14;
self.npc_flags.set_ignore_solidity(true);
self.anim_num = 2;
}
}
15 | 16 => {
if self.action_num == 15 {
self.action_num = 16;
self.action_counter = 0;
self.anim_num = 4;
}
self.action_counter += 1;
if self.action_counter == 30 {
state.sound_manager.play_sfx(21);
let mut npc = NPCMap::create_npc(66, &state.npc_table);
npc.x = self.x;
npc.y = self.y - 16 * 0x200;
npc.cond.set_alive(true);
state.new_npcs.push(npc);
}
if self.action_counter == 50 {
self.action_num = 14;
}
}
20 | 21 => {
if self.action_num == 20 {
self.action_num = 21;
self.anim_num = 0;
self.vel_y = 0;
self.npc_flags.set_ignore_solidity(true);
}
self.vel_y -= 0x20;
if self.y < -8 * 0x200 {
self.cond.set_alive(false);
}
}
25 | 26 => {
if self.action_num == 25 {
self.action_num = 26;
self.action_counter = 0;
self.anim_num = 5;
self.anim_counter = 0;
}
self.anim_num += 1;
if self.anim_num > 7 {
self.anim_num = 5;
}
self.action_counter += 1;
if self.action_counter == 30 {
state.sound_manager.play_sfx(101);
// todo flash
self.action_num = 27;
self.anim_num = 7;
}
}
27 => {
self.action_counter += 1;
if self.action_counter == 50 {
self.action_num = 14;
}
}
_ => {}
}
self.x += self.vel_x;
self.y += self.vel_y;
match self.action_num {
11 => {}
14 => {}
_ => {}
}
if self.direction == Direction::Left {
self.anim_rect = state.constants.npc.n067_misery_floating[self.anim_num as usize];
} else {
self.anim_rect = state.constants.npc.n067_misery_floating[self.anim_num as usize + 8];
}
if self.action_num == 1 && self.anim_counter < 32 {
self.anim_counter += 1;
self.anim_rect.bottom = self.anim_counter as usize / 2 + self.anim_rect.bottom as usize - 16;
}
Ok(())
}
}

View file

@ -25,7 +25,9 @@ pub mod egg_corridor;
pub mod first_cave;
pub mod mimiga_village;
pub mod misc;
pub mod misery;
pub mod pickups;
pub mod toroko;
bitfield! {
#[derive(Clone, Copy)]
@ -92,8 +94,8 @@ impl NPC {
}
}
impl GameEntity<&mut Player> for NPC {
fn tick(&mut self, state: &mut SharedGameState, player: &mut Player) -> GameResult {
impl GameEntity<(&mut Player, &HashMap<u16, RefCell<NPC>>)> for NPC {
fn tick(&mut self, state: &mut SharedGameState, (player, map): (&mut Player, &HashMap<u16, RefCell<NPC>>)) -> GameResult {
match self.npc_type {
0 => { self.tick_n000_null() }
1 => { self.tick_n001_experience(state) }
@ -130,6 +132,8 @@ impl GameEntity<&mut Player> for NPC {
63 => { self.tick_n063_toroko_stick(state) }
64 => { self.tick_n064_first_cave_critter(state, player) }
65 => { self.tick_n065_first_cave_bat(state, player) }
66 => { self.tick_n066_misery_bubble(state, map) }
67 => { self.tick_n067_misery_floating(state) }
70 => { self.tick_n070_sparkle(state) }
71 => { self.tick_n071_chinfish(state) }
72 => { self.tick_n072_sprinkler(state) }

272
src/npc/toroko.rs Normal file
View file

@ -0,0 +1,272 @@
use num_traits::clamp;
use crate::common::Direction;
use crate::ggez::GameResult;
use crate::npc::NPC;
use crate::player::Player;
use crate::SharedGameState;
impl NPC {
pub(crate) fn tick_n060_toroko(&mut self, state: &mut SharedGameState, player: &Player) -> GameResult {
match self.action_num {
0 | 1 => {
if self.action_num == 0 {
self.action_num = 1;
self.anim_num = 0;
self.anim_counter = 0;
self.vel_x = 0;
}
if state.game_rng.range(0..120) == 10 {
self.action_num = 2;
self.action_counter = 0;
self.anim_num = 1;
}
if (self.x - (16 * 0x200) < player.x) && (self.x + (16 * 0x200) > player.x)
&& (self.y - (16 * 0x200) < player.y) && (self.y + (16 * 0x200) > player.y) {
if self.x > player.x {
self.direction = Direction::Left;
} else {
self.direction = Direction::Right;
}
}
}
2 => {
self.action_counter += 1;
if self.action_counter > 8 {
self.action_num = 1;
self.anim_num = 0;
}
}
3 | 4 => {
if self.action_num == 3 {
self.action_num = 4;
self.anim_num = 1;
self.anim_counter = 0;
}
self.anim_counter += 1;
if self.anim_counter > 2 {
self.anim_counter = 0;
self.anim_num += 1;
}
if self.anim_num > 4 {
self.anim_num = 1;
}
if self.flags.hit_left_wall() {
self.direction = Direction::Right;
self.vel_x = 0x200;
}
if self.flags.hit_right_wall() {
self.direction = Direction::Left;
self.vel_x = -0x200;
}
if self.direction == Direction::Left {
self.vel_x = -0x400;
} else {
self.vel_x = 0x400;
}
}
6 | 7 => {
if self.action_num == 6 {
self.action_num = 7;
self.action_counter = 0;
self.anim_num = 1;
self.anim_counter = 0;
self.vel_y = -0x400;
}
self.anim_counter += 1;
if self.anim_counter > 2 {
self.anim_counter = 0;
self.anim_num += 1;
}
if self.anim_num > 4 {
self.anim_num = 1;
}
if self.direction == Direction::Left {
self.vel_x = -0x100;
} else {
self.vel_x = 0x100;
}
if self.action_counter != 0 && self.flags.hit_bottom_wall() {
self.action_num = 3;
}
self.action_counter += 1;
}
8 | 9 => {
if self.action_num == 8 {
self.anim_num = 1;
self.action_counter = 0;
self.action_num = 9;
self.vel_y = -0x200;
}
if self.action_counter != 0 && self.flags.hit_bottom_wall() {
self.action_num = 0;
}
self.action_counter += 1;
}
10 => {
self.action_num = 11;
self.anim_num = 6;
self.vel_y = -0x400;
state.sound_manager.play_sfx(50);
if self.direction == Direction::Left {
self.vel_x = -0x100;
} else {
self.vel_x = 0x100;
}
}
11 => {
if self.action_counter != 0 && self.flags.hit_bottom_wall() {
self.action_num = 12;
self.anim_num = 7;
self.npc_flags.set_interactable(true);
}
self.action_counter += 1;
}
12 => {
self.vel_x = 0;
}
_ => {}
}
self.vel_y += 0x40;
self.vel_x = clamp(self.vel_x, -0x400, 0x400);
if self.vel_y > 0x5ff {
self.vel_y = 0x5ff;
}
self.x += self.vel_x;
self.y += self.vel_y;
if self.direction == Direction::Left {
self.anim_rect = state.constants.npc.n060_toroko[self.anim_num as usize];
} else {
self.anim_rect = state.constants.npc.n060_toroko[self.anim_num as usize + 8];
}
Ok(())
}
pub(crate) fn tick_n063_toroko_stick(&mut self, state: &mut SharedGameState) -> GameResult {
match self.action_num {
0 | 1 => {
if self.action_num == 0 {
self.action_num = 1;
self.action_counter = 0;
self.anim_counter = 0;
self.vel_y = -0x400;
}
if self.vel_y > 0 {
self.npc_flags.set_ignore_solidity(false);
}
self.anim_counter += 1;
if self.anim_counter > 2 {
self.anim_counter = 0;
self.anim_num += 1;
if self.anim_num > 3 {
self.anim_num = 0;
}
}
self.vel_x = 0x100 * self.direction.vector_x();
self.action_counter += 1;
if self.action_counter != 0 && self.flags.hit_bottom_wall() {
self.action_num = 2;
}
}
2 | 3 => {
if self.action_num == 2 {
self.action_num = 3;
self.action_counter = 0;
self.anim_num = 0;
self.anim_counter = 0;
}
self.anim_counter += 1;
if self.anim_counter > 2 {
self.anim_counter = 0;
self.anim_num += 1;
if self.anim_num > 3 {
self.anim_num = 0;
}
}
self.action_counter += 1;
if self.action_counter > 50 {
self.action_counter = 40;
self.vel_x = -self.vel_x;
self.direction = self.direction.opposite();
}
if self.action_counter > 35 {
self.npc_flags.set_shootable(true);
}
self.vel_x += 0x40 * self.direction.vector_x();
if self.shock > 0 {
self.action_num = 4;
self.anim_num = 4;
self.vel_y = -0x400;
self.npc_flags.set_shootable(false);
self.damage = 0;
}
}
4 => {
self.vel_x = 0x100 * self.direction.vector_x();
self.action_counter += 1;
if self.action_counter != 0 && self.flags.hit_bottom_wall() {
self.action_num = 5;
self.npc_flags.set_interactable(true);
}
}
5 => {
self.vel_x = 0;
self.anim_num = 5;
}
_ => {}
}
self.vel_y += 0x40;
self.vel_x = clamp(self.vel_x, -0x400, 0x400);
if self.vel_y > 0x5ff {
self.vel_y = 0x5ff;
}
self.x += self.vel_x;
self.y += self.vel_y;
if self.direction == Direction::Left {
self.anim_rect = state.constants.npc.n063_toroko_stick[self.anim_num as usize];
} else {
self.anim_rect = state.constants.npc.n063_toroko_stick[self.anim_num as usize + 6];
}
Ok(())
}
}

View file

@ -692,9 +692,9 @@ impl Scene for GameScene {
self.player.target_y = self.player.y;
self.frame.immediate_update(state, &self.player, &self.stage);
//self.inventory.add_weapon(WeaponType::PolarStar, 0);
//self.inventory.add_xp(120, state);
//self.player.equip.set_booster_2_0(true);
self.inventory.add_weapon(WeaponType::PolarStar, 0);
self.inventory.add_xp(120, state);
self.player.equip.set_booster_2_0(true);
Ok(())
}
@ -711,11 +711,11 @@ impl Scene for GameScene {
};
self.player.tick(state, ())?;
for npc_id in self.npc_map.npc_ids.iter() {
if let Some(npc_cell) = self.npc_map.npcs.get_mut(npc_id) {
if let Some(npc_cell) = self.npc_map.npcs.get(npc_id) {
let mut npc = npc_cell.borrow_mut();
if npc.cond.alive() {
npc.tick(state, &mut self.player)?;
npc.tick(state, (&mut self.player, &self.npc_map.npcs))?;
}
}
}

View file

@ -1094,7 +1094,7 @@ impl TextScriptVM {
if tick_npc != 0 {
if let Some(npc) = game_scene.npc_map.npcs.get(&tick_npc) {
npc.borrow_mut().tick(state, &mut game_scene.player)?;
npc.borrow_mut().tick(state, (&mut game_scene.player, &game_scene.npc_map.npcs))?;
}
}