1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2025-03-25 11:29:30 +00:00

first cave critters and physics fixes

This commit is contained in:
Alula 2020-09-09 15:28:58 +02:00
parent 002242ca21
commit 34d94d52c0
No known key found for this signature in database
GPG key ID: 3E00485503A1D8BA
4 changed files with 138 additions and 5 deletions

View file

@ -117,8 +117,10 @@ pub struct NPCConsts {
pub n060_toroko: [Rect<usize>; 16],
pub n061_king: [Rect<usize>; 20],
pub n062_kazuma_computer: [Rect<usize>; 3],
pub n070_sparkle: [Rect<usize>; 4],
pub n063_toroko_stick: [Rect<usize>; 12],
pub n064_first_cave_critter: [Rect<usize>; 6],
pub n065_first_cave_bat: [Rect<usize>; 8],
pub n070_sparkle: [Rect<usize>; 4],
pub n071_chinfish: [Rect<usize>; 6],
pub n072_sprinkler: [Rect<usize>; 2],
pub n073_water_droplet: [Rect<usize>; 5],
@ -553,7 +555,6 @@ impl EngineConstants {
Rect { left: 96, top: 64, right: 112, bottom: 80 },
Rect { left: 112, top: 64, right: 128, bottom: 80 },
Rect { left: 128, top: 64, right: 144, bottom: 80 },
Rect { left: 64, top: 80, right: 80, bottom: 96 }, // right
Rect { left: 80, top: 80, right: 96, bottom: 96 },
Rect { left: 64, top: 80, right: 80, bottom: 96 },
@ -561,6 +562,24 @@ impl EngineConstants {
Rect { left: 112, top: 80, right: 128, bottom: 96 },
Rect { left: 128, top: 80, right: 144, bottom: 96 },
],
n064_first_cave_critter: [
Rect { left: 0, top: 0, right: 16, bottom: 16 },
Rect { left: 16, top: 0, right: 32, bottom: 16 },
Rect { left: 32, top: 0, right: 48, bottom: 16 },
Rect { left: 0, top: 16, right: 16, bottom: 32 },
Rect { left: 16, top: 16, right: 32, bottom: 32 },
Rect { left: 32, top: 16, right: 48, bottom: 32 },
],
n065_first_cave_bat: [
Rect { left: 32, top: 32, right: 48, bottom: 48 },
Rect { left: 48, top: 32, right: 64, bottom: 48 },
Rect { left: 64, top: 32, right: 80, bottom: 48 },
Rect { left: 80, top: 32, right: 96, bottom: 48 },
Rect { left: 32, top: 48, right: 48, bottom: 64 },
Rect { left: 48, top: 48, right: 64, bottom: 64 },
Rect { left: 64, top: 48, right: 80, bottom: 64 },
Rect { left: 80, top: 48, right: 96, bottom: 64 },
],
n070_sparkle: [
Rect { left: 96, top: 48, right: 112, bottom: 64 },
Rect { left: 112, top: 48, right: 128, bottom: 64 },
@ -571,7 +590,6 @@ impl EngineConstants {
Rect { left: 64, top: 32, right: 80, bottom: 48 }, // left
Rect { left: 80, top: 32, right: 96, bottom: 48 },
Rect { left: 96, top: 32, right: 112, bottom: 48 },
Rect { left: 64, top: 48, right: 80, bottom: 64 }, // right
Rect { left: 80, top: 48, right: 96, bottom: 64 },
Rect { left: 96, top: 48, right: 112, bottom: 64 },
@ -594,7 +612,6 @@ impl EngineConstants {
Rect { left: 64, top: 0, right: 80, bottom: 16 },
Rect { left: 112, top: 0, right: 128, bottom: 16 },
Rect { left: 64, top: 0, right: 80, bottom: 16 },
Rect { left: 64, top: 16, right: 80, bottom: 32 }, // right
Rect { left: 80, top: 16, right: 96, bottom: 32 },
Rect { left: 96, top: 16, right: 112, bottom: 32 },
@ -619,7 +636,6 @@ impl EngineConstants {
Rect { left: 0, top: 0, right: 16, bottom: 16 }, // left
Rect { left: 16, top: 0, right: 32, bottom: 16 },
Rect { left: 32, top: 0, right: 48, bottom: 16 },
Rect { left: 0, top: 16, right: 16, bottom: 32 }, // right
Rect { left: 16, top: 16, right: 32, bottom: 32 },
Rect { left: 32, top: 16, right: 48, bottom: 32 },

View file

@ -1,3 +1,4 @@
use crate::common::Direction;
use crate::ggez::GameResult;
use crate::npc::NPC;
use crate::player::Player;
@ -22,4 +23,118 @@ impl NPC {
Ok(())
}
pub(crate) fn tick_n064_first_cave_critter(&mut self, state: &mut SharedGameState, player: &Player) -> GameResult {
match self.action_num {
0 | 1 => {
if self.action_num == 0 {
self.y += 3 * 0x200;
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 }];
}
if self.x > player.x {
self.direction = Direction::Left;
} else {
self.direction = Direction::Right;
}
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 }];
}
} 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 }];
}
}
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 }];
}
}
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.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 }];
}
}
}
2 => {
self.action_counter += 1;
if self.action_counter > 8 {
self.action_num = 3;
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_y = -0x5ff;
// todo play sound 30
if self.direction == Direction::Left {
self.vel_x = -0x100;
} else {
self.vel_x = 0x100;
}
}
}
3 => {
if self.flags.hit_bottom_wall() {
self.vel_x = 0;
self.action_counter = 0;
self.action_num = 1;
// tood play sound 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 }];
}
}
}
_ => {}
}
self.vel_y += 0x40;
if self.vel_y > 0x5ff {
self.vel_y = 0x5ff;
}
self.x += self.vel_x;
self.y += self.vel_y;
Ok(())
}
}

View file

@ -100,6 +100,7 @@ impl GameEntity<&mut Player> for NPC {
60 => { self.tick_n060_toroko(state, player) }
61 => { self.tick_n061_king(state) }
62 => { self.tick_n062_kazuma_computer(state) }
64 => { self.tick_n064_first_cave_critter(state, player) }
70 => { self.tick_n070_sparkle(state) }
72 => { self.tick_n072_sprinkler(state) }
74 => { self.tick_n074_jack(state) }

View file

@ -478,6 +478,7 @@ impl Scene for GameScene {
npc.tick(state, &mut self.player)?;
if npc.cond.alive() && !npc.npc_flags.ignore_solidity() {
npc.flags.0 = 0;
npc.tick_map_collisions(state, &self.stage);
}
}