Add Igor boss

This commit is contained in:
Alula 2020-11-17 11:46:51 +01:00
parent 441edb833e
commit d2a3a7669f
No known key found for this signature in database
GPG Key ID: 3E00485503A1D8BA
3 changed files with 298 additions and 4 deletions

View File

@ -8,7 +8,7 @@ use crate::bitfield;
/// Multiply cave story degrees (0-255, which corresponds to 0°-360°) with this to get
/// respective value in radians.
pub const CDEG_RAD: f64 = std::f64::consts::PI * 0.003950617283950617;
pub const CDEG_RAD: f64 = std::f64::consts::PI / 128.0;
bitfield! {
#[derive(Clone, Copy)]

View File

@ -1,6 +1,8 @@
use crate::common::Direction;
use ggez::GameResult;
use crate::npc::NPC;
use crate::common::{CDEG_RAD, Direction};
use crate::npc::{NPC, NPCMap};
use crate::player::Player;
use crate::shared_game_state::SharedGameState;
impl NPC {
@ -84,4 +86,294 @@ impl NPC {
Ok(())
}
pub(crate) fn tick_n088_igor_boss(&mut self, state: &mut SharedGameState, player: &Player) -> 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_x = 0;
}
self.anim_counter += 1;
if self.anim_counter > 5 {
self.anim_counter = 0;
self.anim_num += 1;
if self.anim_num > 1 {
self.anim_num = 0;
}
}
self.action_counter += 1;
if self.action_counter > 50 {
self.action_num = 2;
}
}
2 | 3 => {
if self.action_num == 2 {
self.action_num = 3;
self.action_counter = 0;
self.anim_num = 2;
self.anim_counter = 0;
self.vel_x2 += 1;
if self.vel_x2 < 3 || self.life > 150 {
self.action_counter2 = 0;
} else {
self.action_counter2 = 1;
}
self.direction = if player.x < self.x { Direction::Left } else { Direction::Right };
}
self.action_counter += 1;
self.anim_counter += 1;
if self.anim_counter > 3 {
self.anim_counter = 0;
self.anim_num += 1;
if self.anim_num > 5 {
self.anim_num = 2;
}
}
self.vel_x = self.direction.vector_x() * 0x200;
if self.action_counter2 != 0 {
if self.action_counter > 16 {
self.vel_x = 0;
self.action_num = 9;
self.anim_num = 10;
}
} else if self.action_counter > 50 {
self.action_num = 7;
self.action_counter = 0;
self.anim_num = 8;
self.damage = 2;
self.vel_x = (self.vel_x * 3) / 2;
self.vel_y = -0x400;
} else if (self.direction == Direction::Left && self.x - 24 * 0x200 < player.x)
|| (self.direction == Direction::Right && self.x + 24 * 0x200 > player.x) {
self.action_num = 4;
}
}
4 | 5 => {
if self.action_num == 4 {
self.action_num = 5;
self.action_counter = 0;
self.anim_num = 6;
self.vel_x = 0;
}
self.action_counter += 1;
if self.action_counter > 12 {
self.action_num = 6;
self.action_counter = 0;
self.anim_num = 7;
self.damage = 5;
self.hit_bounds.left = 24 * 0x200;
self.hit_bounds.top = 1;
state.sound_manager.play_sfx(70);
}
}
6 => {
self.action_counter += 1;
if self.action_counter > 10 {
self.action_num = 0;
self.anim_num = 0;
self.damage = 0;
self.hit_bounds.left = 8 * 0x200;
self.hit_bounds.top = 16 * 0x200;
}
}
7 => {
if self.flags.hit_bottom_wall() {
self.action_num = 8;
self.anim_num = 9;
self.damage = 0;
state.sound_manager.play_sfx(26);
state.quake_counter = 30;
let mut npc = NPCMap::create_npc(4, &state.npc_table);
for _ in 0..4 {
npc.cond.set_alive(true);
npc.direction = Direction::Left;
npc.x = self.x + state.game_rng.range(-12..12) as isize * 0x200;
npc.y = self.y + state.game_rng.range(-12..12) as isize * 0x200;
npc.vel_x = state.game_rng.range(-0x155..0x155) as isize;
npc.vel_y = state.game_rng.range(-0x600..0) as isize;
state.new_npcs.push(npc);
}
}
}
8 => {
self.vel_x = 0;
self.action_counter += 1;
if self.action_counter > 10 {
self.action_num = 0;
self.anim_num = 0;
self.damage = 0;
}
}
9 | 10 => {
if self.action_num == 9 {
self.action_num = 10;
self.action_counter = 0;
self.direction = if player.x < self.x { Direction::Left } else { Direction::Right };
}
self.action_counter += 1;
if self.action_counter > 100 && self.action_counter % 6 == 1 {
let deg = (if self.direction == Direction::Left { 0x88 } else { 0xf8 } + state.game_rng.range(-16..16)) as f64 * CDEG_RAD;
let vel_x = (deg.cos() * 1536.0) as isize;
let vel_y = (deg.sin() * 1536.0) as isize;
let mut npc = NPCMap::create_npc(11, &state.npc_table);
npc.cond.set_alive(true);
npc.direction = Direction::Left;
npc.x = self.x;
npc.y = self.y + 4 * 0x200;
npc.vel_x = vel_x;
npc.vel_y = vel_y;
state.new_npcs.push(npc);
state.sound_manager.play_sfx(12);
}
self.anim_num = if self.action_counter > 50 && (self.action_counter / 2 % 2) != 0 { 11 } else { 10 };
if self.action_counter > 132 {
self.action_num = 0;
self.anim_num = 0;
self.vel_x2 = 0;
}
}
_ => {}
}
self.vel_y += 0x40;
if self.vel_y > 0x5ff {
self.vel_y = 0x5ff;
}
self.x += self.vel_x;
self.y += self.vel_y;
let dir_offset = if self.direction == Direction::Left { 0 } else { 12 };
self.anim_rect = state.constants.npc.n088_igor_boss[self.anim_num as usize + dir_offset];
Ok(())
}
pub(crate) fn tick_n089_igor_dead(&mut self, state: &mut SharedGameState, player: &Player) -> GameResult {
match self.action_num {
0 | 1 => {
if self.action_num == 0 {
self.action_num = 1;
self.direction = if self.x > player.x { Direction::Left } else { Direction::Right };
let mut npc = NPCMap::create_npc(4, &state.npc_table);
for _ in 0..8 {
npc.cond.set_alive(true);
npc.direction = Direction::Left;
npc.x = self.x + state.game_rng.range(-12..12) as isize * 0x200;
npc.y = self.y + state.game_rng.range(-12..12) as isize * 0x200;
npc.vel_x = state.game_rng.range(-0x155..0x155) as isize;
npc.vel_y = state.game_rng.range(-0x600..0) as isize;
state.new_npcs.push(npc);
}
}
self.action_counter += 1;
if self.action_counter > 100 {
self.action_num = 2;
self.action_counter = 0;
}
if self.action_counter % 5 == 0 {
let mut npc = NPCMap::create_npc(4, &state.npc_table);
npc.cond.set_alive(true);
npc.direction = Direction::Left;
npc.x = self.x + state.game_rng.range(-12..12) as isize * 0x200;
npc.y = self.y + state.game_rng.range(-12..12) as isize * 0x200;
npc.vel_x = state.game_rng.range(-0x155..0x155) as isize;
npc.vel_y = state.game_rng.range(-0x600..0) as isize;
state.new_npcs.push(npc);
}
let dir_offset = if self.direction == Direction::Left { 0 } else { 4 };
self.anim_rect = state.constants.npc.n089_igor_dead[dir_offset];
if (self.action_counter / 2 % 2) != 0 {
self.anim_rect.left -= 1;
}
}
2 => {
self.action_counter += 1;
if (self.action_counter / 2 % 2) != 0 && self.action_counter < 100 {
self.anim_num = 0;
self.display_bounds.left = 20 * 0x200;
self.display_bounds.right = 20 * 0x200;
self.display_bounds.top = 20 * 0x200;
} else {
self.anim_num = 1;
self.display_bounds.left = 12 * 0x200;
self.display_bounds.right = 12 * 0x200;
self.display_bounds.top = 8 * 0x200;
}
if self.action_counter > 150 {
self.action_num = 3;
self.action_counter = 0;
self.anim_num = 1;
}
if self.action_counter % 9 == 0 {
let mut npc = NPCMap::create_npc(4, &state.npc_table);
npc.cond.set_alive(true);
npc.direction = Direction::Left;
npc.x = self.x + state.game_rng.range(-12..12) as isize * 0x200;
npc.y = self.y + state.game_rng.range(-12..12) as isize * 0x200;
npc.vel_x = state.game_rng.range(-0x155..0x155) as isize;
npc.vel_y = state.game_rng.range(-0x600..0) as isize;
state.new_npcs.push(npc);
}
let dir_offset = if self.direction == Direction::Left { 0 } else { 4 };
self.anim_rect = state.constants.npc.n089_igor_dead[self.anim_num as usize + dir_offset];
}
3 => {
self.anim_counter += 1;
if self.anim_counter > 50 {
self.anim_counter = 0;
self.anim_num += 1;
if self.anim_num == 3 {
self.action_num = 4;
}
let dir_offset = if self.direction == Direction::Left { 0 } else { 4 };
self.anim_rect = state.constants.npc.n089_igor_dead[self.anim_num as usize + dir_offset];
}
}
_ => {}
}
Ok(())
}
}

View File

@ -112,7 +112,7 @@ pub struct NPC {
pub anim_rect: Rect<u16>,
}
static PARTICLE_NPCS: [u16; 10] = [1, 4, 73, 84, 86, 87, 108, 129, 199, 355];
static PARTICLE_NPCS: [u16; 11] = [1, 4, 11, 73, 84, 86, 87, 108, 129, 199, 355];
impl NPC {
pub fn get_start_index(&self) -> u16 {
@ -238,6 +238,8 @@ impl GameEntity<(&mut Player, &BTreeMap<u16, RefCell<NPC>>, &mut Stage)> for NPC
85 => self.tick_n085_terminal(state, player),
86 => self.tick_n086_missile_pickup(state),
87 => self.tick_n087_heart_pickup(state),
88 => self.tick_n088_igor_boss(state, player),
89 => self.tick_n089_igor_dead(state, player),
91 => self.tick_n091_mimiga_cage(state),
94 => self.tick_n094_kulala(state, player),
95 => self.tick_n095_jelly(state),