1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2024-11-17 11:22:52 +00:00
doukutsu-rs/src/npc/maze.rs

98 lines
3.2 KiB
Rust
Raw Normal View History

use ggez::GameResult;
2020-11-01 19:05:29 +00:00
use num_traits::{abs, clamp};
use crate::common::Direction;
2020-10-02 23:53:32 +00:00
use crate::npc::NPC;
2020-11-01 19:05:29 +00:00
use crate::player::Player;
use crate::shared_game_state::SharedGameState;
2020-10-02 23:53:32 +00:00
impl NPC {
2020-11-01 19:05:29 +00:00
pub(crate) fn tick_n154_gaudi_dead(&mut self, state: &mut SharedGameState) -> GameResult {
let dir_offset = if self.direction == Direction::Left { 0 } else { 3 };
self.anim_rect = state.constants.npc.n154_gaudi_dead[self.anim_num as usize + dir_offset];
Ok(())
}
pub(crate) fn tick_n361_gaudi_dashing(&mut self, state: &mut SharedGameState, players: [&mut Player; 2]) -> GameResult {
2020-11-01 19:05:29 +00:00
match self.action_num {
0 | 1 => {
if self.action_num == 0 {
self.vel_x2 = 0;
self.vel_y2 = 0;
self.action_num = 1;
}
let player = self.get_closest_player_mut(players);
2020-11-01 19:05:29 +00:00
if (self.direction == Direction::Right && player.x > self.x + 272 * 0x200 && player.x < self.x + 288 * 0x200)
|| (self.direction == Direction::Left && player.x < self.x - 272 * 0x200 && player.x > self.x - 288 * 0x200) {
self.action_num = 10;
} else {
return Ok(());
}
}
10 | 11 => {
if self.action_num == 10 {
self.npc_flags.set_shootable(true);
self.action_num = 11;
self.damage = 5;
}
let player = self.get_closest_player_mut(players);
2020-11-01 19:05:29 +00:00
if self.x > player.x {
self.direction = Direction::Left;
} else {
self.direction = Direction::Right;
}
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;
}
}
self.vel_x2 += self.direction.vector_x() * 0x10;
self.vel_y2 += (player.y - self.y).signum() * 0x10;
if self.vel_x2 < 0 && self.flags.hit_left_wall() {
self.vel_x2 /= -2;
}
if self.vel_x2 > 0 && self.flags.hit_right_wall() {
self.vel_x2 /= -2;
}
if self.vel_y2 < 0 && self.flags.hit_top_wall() {
self.vel_y2 *= -1;
}
if self.vel_y2 > 0 && self.flags.hit_bottom_wall() {
self.vel_y2 /= -2;
}
self.vel_x2 = clamp(self.vel_x2, -0x5ff, 0x5ff);
self.vel_y2 = clamp(self.vel_y2, -0x5ff, 0x5ff);
self.x += self.vel_x2;
self.y += self.vel_y2;
}
_ => {}
}
if self.life <= 985 {
self.cond.set_drs_destroyed(true);
self.npc_type = 154;
self.action_num = 0;
}
let dir_offset = if self.direction == Direction::Left { 0 } else { 2 };
self.anim_rect = state.constants.npc.n361_gaudi_dashing[self.anim_num as usize + dir_offset];
2020-10-02 23:53:32 +00:00
2020-11-01 19:05:29 +00:00
Ok(())
}
2020-10-02 23:53:32 +00:00
}