1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2025-03-24 19:09:22 +00:00
This commit is contained in:
Alula 2020-09-13 07:57:03 +02:00
parent 2736f61e13
commit 82a51dda88
No known key found for this signature in database
GPG key ID: 3E00485503A1D8BA
2 changed files with 174 additions and 1 deletions

View file

@ -207,7 +207,101 @@ impl NPC {
Ok(())
}
pub(crate) fn tick_n006_green_beetle(&mut self, state: &mut SharedGameState, player: &Player) -> GameResult {
pub(crate) fn tick_n006_green_beetle(&mut self, state: &mut SharedGameState) -> GameResult {
match self.action_num {
0 => {
self.action_num = 1;
match self.direction {
Direction::Left => { self.action_num = 1; }
Direction::Right => { self.action_num = 3; }
_ => {}
}
}
1 => {
self.vel_x -= 0x10;
if self.vel_x < -0x400 {
self.vel_x = -0x400;
}
if self.shock > 0 {
self.x += self.vel_x / 2;
} else {
self.x += self.vel_x;
}
self.anim_counter += 1;
if self.anim_counter > 1 {
self.anim_counter = 0;
self.anim_num += 1;
if self.anim_num > 2 {
self.anim_num = 1;
}
}
if self.flags.hit_left_wall() {
self.action_num = 2;
self.action_counter = 0;
self.anim_num = 0;
self.vel_x = 0;
self.direction = Direction::Right;
}
}
2 => {
self.action_counter += 1;
if self.action_counter > 60 {
self.action_num = 3;
self.anim_counter = 0;
self.anim_num = 1;
}
}
3 => {
self.vel_x += 0x10;
if self.vel_x > 0x400 {
self.vel_x = 0x400;
}
if self.shock > 0 {
self.x += self.vel_x / 2;
} else {
self.x += self.vel_x;
}
self.anim_counter += 1;
if self.anim_counter > 1 {
self.anim_counter = 0;
self.anim_num += 1;
if self.anim_num > 2 {
self.anim_num = 1;
}
}
if self.flags.hit_right_wall() {
self.action_num = 4;
self.action_counter = 0;
self.anim_num = 0;
self.vel_x = 0;
self.direction = Direction::Left;
}
}
4 => {
self.action_counter += 1;
if self.action_counter > 60 {
self.action_num = 1;
self.anim_counter = 0;
self.anim_num = 1;
}
}
_ => {}
}
if self.anim_counter == 1 {
self.anim_rect = state.constants.npc.n006_green_beetle[self.anim_num as usize + if self.direction == Direction::Right { 5 } else { 0 }];
}
Ok(())
}
@ -264,9 +358,86 @@ impl NPC {
if self.anim_counter > 1 {
self.anim_counter = 0;
self.anim_num = (self.anim_num + 1) % 2;
}
if self.anim_counter == 1 {
self.anim_rect = state.constants.npc.n007_basil[self.anim_num as usize + if self.direction == Direction::Right { 3 } else { 0 }];
}
Ok(())
}
pub(crate) fn tick_n008_blue_beetle(&mut self, state: &mut SharedGameState, player: &Player) -> GameResult {
match self.action_num {
0 => {
if player.x < self.x + 16 * 0x200 && player.x > self.x - 16 * 0x200 {
self.npc_flags.set_shootable(true);
self.vel_y = -0x100;
self.target_y = self.y;
self.action_num = 1;
self.damage = 2;
match self.direction {
Direction::Left => {
self.x = player.x + 256 * 0x200;
self.vel_x = -0x2ff;
}
Direction::Right => {
self.x = player.x - 256 * 0x200;
self.vel_x = 0x2ff;
}
_ => {}
}
} else {
self.npc_flags.set_shootable(false);
self.anim_rect.left = 0;
self.anim_rect.right = 0;
self.damage = 0;
self.vel_x = 0;
self.vel_y = 0;
return Ok(());
}
}
1 => {
if self.x > player.x {
self.direction = Direction::Left;
self.vel_x -= 0x10;
} else {
self.direction = Direction::Right;
self.vel_x += 0x10;
}
self.vel_y += if self.y < self.target_y { 8 } else { -8 };
self.vel_x = clamp(self.vel_x, -0x2ff, 0x2ff);
self.vel_y = clamp(self.vel_y, -0x100, 0x100);
if self.shock > 0 {
self.x += self.vel_x / 2;
self.y += self.vel_y / 2;
} else {
self.x += self.vel_x;
self.y += self.vel_y;
}
}
_ => {}
}
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.anim_counter == 1 {
self.anim_rect = state.constants.npc.n008_blue_beetle[self.anim_num as usize + if self.direction == Direction::Right { 2 } else { 0 }];
}
Ok(())
}
}

View file

@ -104,7 +104,9 @@ impl GameEntity<&mut Player> for NPC {
3 => { self.tick_n003_dead_enemy() }
4 => { self.tick_n004_smoke(state) }
5 => { self.tick_n005_green_critter(state, player) }
6 => { self.tick_n006_green_beetle(state) }
7 => { self.tick_n007_basil(state, player) }
8 => { self.tick_n008_blue_beetle(state, player) }
15 => { self.tick_n015_chest_closed(state) }
16 => { self.tick_n016_save_point(state) }
17 => { self.tick_n017_health_refill(state) }