doukutsu-rs/src/npc/misc.rs

174 lines
5.3 KiB
Rust
Raw Normal View History

2020-09-04 23:08:33 +00:00
use crate::common::Direction;
use crate::ggez::GameResult;
use crate::npc::NPC;
use crate::SharedGameState;
impl NPC {
pub(crate) fn tick_n000_null(&mut self, state: &mut SharedGameState) -> GameResult {
Ok(())
}
pub(crate) fn tick_n016_save_point(&mut self, state: &mut SharedGameState) -> GameResult {
2020-09-05 02:09:52 +00:00
if self.action_num == 0 {
self.action_num = 1;
if self.direction == Direction::Right {
self.npc_flags.set_interactable(false);
self.vel_y = -0x200;
}
}
if self.flags.hit_bottom_wall() {
self.npc_flags.set_interactable(true);
}
self.anim_counter = (self.anim_counter + 1) % 24;
self.anim_num = self.anim_counter / 3;
self.anim_rect = state.constants.npc.n016_save_point[self.anim_num as usize];
2020-09-04 23:08:33 +00:00
Ok(())
}
pub(crate) fn tick_n017_health_refill(&mut self, state: &mut SharedGameState) -> GameResult {
if self.action_num == 0 {
self.action_num = 1;
}
match self.action_num {
1 => {
let rand = state.game_rng.range(0..30);
if rand < 10 {
self.action_num = 2;
} else if rand < 25 {
self.action_num = 3;
} else {
self.action_num = 4;
}
self.action_counter = state.game_rng.range(0x10..0x40) as u16;
self.anim_counter = 0;
}
2 => {
self.anim_rect = state.constants.npc.n017_health_refill[0];
if self.action_counter > 0 {
self.action_counter -= 1;
} else {
self.action_num = 1;
}
}
3 => {
self.anim_counter += 1;
if self.anim_counter % 2 == 0 {
self.anim_rect = state.constants.npc.n017_health_refill[1];
} else {
self.anim_rect = state.constants.npc.n017_health_refill[0];
}
if self.action_counter > 0 {
self.action_counter -= 1;
} else {
self.action_num = 1;
}
}
4 => {
self.anim_rect = state.constants.npc.n017_health_refill[1];
if self.action_counter > 0 {
self.action_counter -= 1;
} else {
self.action_num = 1;
}
}
_ => {}
}
Ok(())
}
pub(crate) fn tick_n018_door(&mut self, state: &mut SharedGameState) -> GameResult {
match self.action_num {
0 => {
match self.direction {
2020-09-05 02:09:52 +00:00
Direction::Left => { self.anim_rect = state.constants.npc.n018_door[0] }
Direction::Right => { self.anim_rect = state.constants.npc.n018_door[1] }
2020-09-04 23:08:33 +00:00
_ => {}
}
}
1 => {
// todo smoke
self.action_num = 0;
}
_ => {}
}
Ok(())
}
2020-09-05 02:09:52 +00:00
pub(crate) fn tick_n020_computer(&mut self, state: &mut SharedGameState) -> GameResult {
Ok(())
}
pub(crate) fn tick_n027_death_trap(&mut self, state: &mut SharedGameState) -> GameResult {
if self.action_num == 0 {
self.action_num = 1;
self.anim_rect = state.constants.npc.n027_death_trap;
}
Ok(())
}
pub(crate) fn tick_n032_life_capsule(&mut self, state: &mut SharedGameState) -> GameResult {
self.anim_counter = (self.anim_counter + 1) % 4;
self.anim_num = self.anim_counter / 2;
self.anim_rect = state.constants.npc.n032_life_capsule[self.anim_num as usize];
Ok(())
}
pub(crate) fn tick_n034_bed(&mut self, state: &mut SharedGameState) -> GameResult {
match self.direction {
Direction::Left => { self.anim_rect = state.constants.npc.n034_bed[0] }
Direction::Right => { self.anim_rect = state.constants.npc.n034_bed[1] }
_ => {}
}
Ok(())
}
pub(crate) fn tick_n037_sign(&mut self, state: &mut SharedGameState) -> GameResult {
self.anim_counter = (self.anim_counter + 1) % 4;
self.anim_num = self.anim_counter / 2;
self.anim_rect = state.constants.npc.n037_sign[self.anim_num as usize];
Ok(())
}
pub(crate) fn tick_n038_fireplace(&mut self, state: &mut SharedGameState) -> GameResult {
match self.action_num {
0 => {
self.anim_counter = (self.anim_counter + 1) % 16;
self.anim_num = self.anim_counter / 4;
self.anim_rect = state.constants.npc.n038_fireplace[self.anim_num as usize];
}
10 => {}
11 => {}
_ => {}
}
Ok(())
}
pub(crate) fn tick_n039_save_sign(&mut self, state: &mut SharedGameState) -> GameResult {
match self.direction {
Direction::Left => { self.anim_rect = state.constants.npc.n039_save_sign[0] }
Direction::Right => { self.anim_rect = state.constants.npc.n039_save_sign[1] }
_ => {}
}
Ok(())
}
2020-09-04 23:08:33 +00:00
}