mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2025-07-23 13:00:52 +00:00
Compare commits
10 commits
a1d546215f
...
36fd5f8879
Author | SHA1 | Date | |
---|---|---|---|
|
36fd5f8879 | ||
|
268ecb62bd | ||
|
211108674f | ||
|
b34422ac7f | ||
|
12b2556b40 | ||
|
361baeb20d | ||
|
ac29d35950 | ||
|
9d552eaa1a | ||
|
f87b791c87 | ||
|
ecfcf57847 |
|
@ -21,12 +21,13 @@ opt-level = 1
|
|||
opt-level = 1
|
||||
|
||||
[features]
|
||||
default = ["scripting", "backend-sdl", "ogg-playback"]
|
||||
default = ["scripting", "backend-sdl", "ogg-playback", "netplay"]
|
||||
ogg-playback = ["lewton"]
|
||||
backend-sdl = ["sdl2"]
|
||||
#backend-sokol = ["sokol"]
|
||||
backend-glutin = ["winit", "glutin"]
|
||||
scripting = ["lua-ffi"]
|
||||
netplay = []
|
||||
editor = []
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:extractNativeLibs="true"
|
||||
android:theme="@style/Theme.Doukutsurs">
|
||||
|
||||
<provider
|
||||
|
|
111
src/components/flash.rs
Normal file
111
src/components/flash.rs
Normal file
|
@ -0,0 +1,111 @@
|
|||
use crate::common::{Color, Rect};
|
||||
use crate::entity::GameEntity;
|
||||
use crate::frame::Frame;
|
||||
use crate::framework::context::Context;
|
||||
use crate::framework::error::GameResult;
|
||||
use crate::framework::graphics;
|
||||
use crate::shared_game_state::SharedGameState;
|
||||
|
||||
pub enum FlashState {
|
||||
None,
|
||||
Cross(i32, i32, u16),
|
||||
Blink(u16),
|
||||
}
|
||||
|
||||
pub struct Flash {
|
||||
state: FlashState,
|
||||
}
|
||||
|
||||
impl Flash {
|
||||
pub fn new() -> Flash {
|
||||
Flash {
|
||||
state: FlashState::None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_cross(&mut self, x: i32, y: i32) {
|
||||
self.state = FlashState::Cross(x, y, 0);
|
||||
}
|
||||
|
||||
pub fn set_blink(&mut self) {
|
||||
self.state = FlashState::Blink(0);
|
||||
}
|
||||
|
||||
pub fn stop(&mut self) {
|
||||
self.state = FlashState::None;
|
||||
}
|
||||
}
|
||||
|
||||
impl GameEntity<()> for Flash {
|
||||
fn tick(&mut self, state: &mut SharedGameState, _custom: ()) -> GameResult<()> {
|
||||
match self.state {
|
||||
FlashState::None => {}
|
||||
FlashState::Cross(x, y, tick) => {
|
||||
self.state = if tick > 128 {
|
||||
FlashState::None
|
||||
} else {
|
||||
FlashState::Cross(x, y, tick + 1)
|
||||
};
|
||||
}
|
||||
FlashState::Blink(tick) => {
|
||||
self.state = if tick > 20 {
|
||||
FlashState::None
|
||||
} else {
|
||||
FlashState::Blink(tick + 1)
|
||||
};
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn draw(&self, state: &mut SharedGameState, ctx: &mut Context, frame: &Frame) -> GameResult<()> {
|
||||
const WHITE: Color = Color::new(1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
match self.state {
|
||||
FlashState::None => {}
|
||||
FlashState::Cross(x, y, tick) => {
|
||||
let tick = tick as f32 + state.frame_time as f32;
|
||||
let frame_pos = frame.xy_interpolated(state.frame_time, state.scale);
|
||||
|
||||
let (cen_x, cen_y) = (
|
||||
(x as f32 / 512.0) - frame_pos.0,
|
||||
(y as f32 / 512.0) - frame_pos.1
|
||||
);
|
||||
|
||||
let width = if tick > 100.0 {
|
||||
(1.0 - (tick - 100.0).max(0.0) / 28.0).powf(2.0) * state.canvas_size.0
|
||||
} else {
|
||||
(1.0 - (0.97f32).powf(tick)).max(0.0) * state.canvas_size.0
|
||||
};
|
||||
|
||||
|
||||
let mut rect = Rect {
|
||||
left: 0,
|
||||
top: ((cen_y - width) * state.scale) as isize,
|
||||
right: (state.canvas_size.0 * state.scale) as isize,
|
||||
bottom: ((cen_y + width) * state.scale) as isize
|
||||
};
|
||||
|
||||
graphics::draw_rect(ctx, rect, WHITE)?;
|
||||
|
||||
if tick <= 100.0 {
|
||||
rect = Rect {
|
||||
left: ((cen_x - width) * state.scale) as isize,
|
||||
top: 0,
|
||||
right: ((cen_x + width) * state.scale) as isize,
|
||||
bottom: (state.canvas_size.1 * state.scale) as isize
|
||||
};
|
||||
|
||||
graphics::draw_rect(ctx, rect, WHITE)?;
|
||||
}
|
||||
}
|
||||
FlashState::Blink(tick) => {
|
||||
if tick / 2 % 2 != 0 {
|
||||
graphics::clear(ctx, WHITE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
pub mod boss_life_bar;
|
||||
pub mod draw_common;
|
||||
pub mod flash;
|
||||
pub mod hud;
|
||||
pub mod inventory;
|
||||
pub mod stage_select;
|
||||
|
|
|
@ -44,6 +44,14 @@ impl PlayerController for DummyPlayerController {
|
|||
false
|
||||
}
|
||||
|
||||
fn map(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn inventory(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn jump(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
@ -80,6 +88,14 @@ impl PlayerController for DummyPlayerController {
|
|||
false
|
||||
}
|
||||
|
||||
fn trigger_map(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn trigger_inventory(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn trigger_jump(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
|
|
@ -101,6 +101,14 @@ impl PlayerController for KeyboardController {
|
|||
self.state.next_weapon()
|
||||
}
|
||||
|
||||
fn map(&self) -> bool {
|
||||
self.state.map()
|
||||
}
|
||||
|
||||
fn inventory(&self) -> bool {
|
||||
self.state.inventory()
|
||||
}
|
||||
|
||||
fn jump(&self) -> bool {
|
||||
self.state.jump()
|
||||
}
|
||||
|
@ -137,6 +145,14 @@ impl PlayerController for KeyboardController {
|
|||
self.trigger.next_weapon()
|
||||
}
|
||||
|
||||
fn trigger_map(&self) -> bool {
|
||||
self.trigger.map()
|
||||
}
|
||||
|
||||
fn trigger_inventory(&self) -> bool {
|
||||
self.trigger.inventory()
|
||||
}
|
||||
|
||||
fn trigger_jump(&self) -> bool {
|
||||
self.trigger.jump()
|
||||
}
|
||||
|
|
|
@ -26,6 +26,12 @@ pub trait PlayerController: PlayerControllerClone {
|
|||
/// True if "next weapon" button is down.
|
||||
fn next_weapon(&self) -> bool;
|
||||
|
||||
/// True if "map" button is down.
|
||||
fn map(&self) -> bool;
|
||||
|
||||
/// True if "inventory" button is down.
|
||||
fn inventory(&self) -> bool;
|
||||
|
||||
/// True if "jump" button is down.
|
||||
fn jump(&self) -> bool;
|
||||
|
||||
|
@ -47,6 +53,10 @@ pub trait PlayerController: PlayerControllerClone {
|
|||
|
||||
fn trigger_next_weapon(&self) -> bool;
|
||||
|
||||
fn trigger_map(&self) -> bool;
|
||||
|
||||
fn trigger_inventory(&self) -> bool;
|
||||
|
||||
fn trigger_jump(&self) -> bool;
|
||||
|
||||
fn trigger_shoot(&self) -> bool;
|
||||
|
|
|
@ -241,6 +241,14 @@ impl PlayerController for TouchPlayerController {
|
|||
self.state.next_weapon()
|
||||
}
|
||||
|
||||
fn map(&self) -> bool {
|
||||
self.state.map()
|
||||
}
|
||||
|
||||
fn inventory(&self) -> bool {
|
||||
self.state.inventory()
|
||||
}
|
||||
|
||||
fn jump(&self) -> bool {
|
||||
self.state.jump()
|
||||
}
|
||||
|
@ -278,6 +286,14 @@ impl PlayerController for TouchPlayerController {
|
|||
self.trigger.next_weapon()
|
||||
}
|
||||
|
||||
fn trigger_map(&self) -> bool {
|
||||
self.trigger.map()
|
||||
}
|
||||
|
||||
fn trigger_inventory(&self) -> bool {
|
||||
self.trigger.inventory()
|
||||
}
|
||||
|
||||
fn trigger_jump(&self) -> bool {
|
||||
self.trigger.jump()
|
||||
}
|
||||
|
|
|
@ -47,6 +47,8 @@ mod live_debugger;
|
|||
mod macros;
|
||||
mod map;
|
||||
mod menu;
|
||||
#[cfg(feature = "netplay")]
|
||||
mod netplay;
|
||||
mod npc;
|
||||
mod physics;
|
||||
mod player;
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
use crate::framework::context::Context;
|
||||
use crate::framework::error::GameResult;
|
||||
|
||||
use imgui::{CollapsingHeader, Condition, im_str, ImStr, ImString, Slider, Window};
|
||||
use itertools::Itertools;
|
||||
|
||||
use crate::framework::context::Context;
|
||||
use crate::framework::error::GameResult;
|
||||
use crate::scene::game_scene::GameScene;
|
||||
use crate::shared_game_state::SharedGameState;
|
||||
use crate::text_script::TextScriptExecutionState;
|
||||
|
@ -22,6 +21,7 @@ pub struct LiveDebugger {
|
|||
events_visible: bool,
|
||||
hacks_visible: bool,
|
||||
flags_visible: bool,
|
||||
npc_inspector_visible: bool,
|
||||
last_stage_id: usize,
|
||||
stages: Vec<ImString>,
|
||||
selected_stage: i32,
|
||||
|
@ -39,6 +39,7 @@ impl LiveDebugger {
|
|||
events_visible: false,
|
||||
hacks_visible: false,
|
||||
flags_visible: false,
|
||||
npc_inspector_visible: false,
|
||||
last_stage_id: usize::MAX,
|
||||
stages: Vec::new(),
|
||||
selected_stage: -1,
|
||||
|
@ -123,7 +124,6 @@ impl LiveDebugger {
|
|||
}
|
||||
}
|
||||
|
||||
ui.same_line(0.0);
|
||||
if game_scene.player2.cond.alive() {
|
||||
if ui.button(im_str!("Drop Player 2"), [0.0, 0.0]) {
|
||||
game_scene.drop_player2();
|
||||
|
@ -131,6 +131,11 @@ impl LiveDebugger {
|
|||
} else if ui.button(im_str!("Add Player 2"), [0.0, 0.0]) {
|
||||
game_scene.add_player2();
|
||||
}
|
||||
ui.same_line(0.0);
|
||||
|
||||
if ui.button(im_str!("NPC Inspector"), [0.0, 0.0]) {
|
||||
self.npc_inspector_visible = !self.npc_inspector_visible;
|
||||
}
|
||||
});
|
||||
|
||||
if self.map_selector_visible {
|
||||
|
@ -299,6 +304,47 @@ impl LiveDebugger {
|
|||
});
|
||||
}
|
||||
|
||||
if self.npc_inspector_visible {
|
||||
Window::new(im_str!("NPC Inspector"))
|
||||
.position([80.0, 80.0], Condition::FirstUseEver)
|
||||
.size([280.0, 300.0], Condition::FirstUseEver)
|
||||
.scrollable(true)
|
||||
.always_vertical_scrollbar(true)
|
||||
.build(ui, || {
|
||||
for npc in game_scene.npc_list.iter_alive() {
|
||||
if CollapsingHeader::new(&ImString::from(format!("id={} type={}", npc.id, npc.npc_type))).default_open(false).build(&ui) {
|
||||
let mut position = [npc.x as f32 / 512.0, npc.y as f32 / 512.0];
|
||||
ui.input_float2(im_str!("Position:"), &mut position)
|
||||
.build();
|
||||
|
||||
npc.x = (position[0] * 512.0) as i32;
|
||||
npc.y = (position[1] * 512.0) as i32;
|
||||
|
||||
let content = &ImString::from(
|
||||
format!("\
|
||||
Velocity: ({:.1},{:.1})\n\
|
||||
Vel2/State2: ({:.1},{:.1} / {} {})\n\
|
||||
Animation: frame={}, counter={}\n\
|
||||
Action: num={}, counter={}, counter2={}\n\
|
||||
Health: {}, Experience drop: {}\n\
|
||||
Event ID: {}, Flag ID: {}\n\
|
||||
Parent: {}, Shock: {}, Size: {}",
|
||||
npc.vel_x as f32 / 512.0, npc.vel_y as f32 / 512.0,
|
||||
npc.vel_x2 as f32 / 512.0, npc.vel_y2 as f32 / 512.0, npc.vel_x2, npc.vel_y2,
|
||||
npc.anim_num, npc.anim_counter,
|
||||
npc.action_num, npc.action_counter, npc.action_counter2,
|
||||
npc.life, npc.exp,
|
||||
npc.event_num, npc.flag_num,
|
||||
npc.parent_id, npc.shock, npc.size
|
||||
));
|
||||
ui.text_wrapped(content);
|
||||
|
||||
cond_flags(&ui, &mut npc.cond);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let mut remove = -1;
|
||||
for (idx, (_, title, contents)) in self.text_windows.iter().enumerate() {
|
||||
let mut opened = true;
|
||||
|
|
274
src/npc/ai/curly.rs
Normal file
274
src/npc/ai/curly.rs
Normal file
|
@ -0,0 +1,274 @@
|
|||
use num_traits::{abs, clamp};
|
||||
|
||||
use crate::common::Direction;
|
||||
use crate::framework::error::GameResult;
|
||||
use crate::npc::list::NPCList;
|
||||
use crate::npc::NPC;
|
||||
use crate::player::Player;
|
||||
use crate::rng::RNG;
|
||||
use crate::shared_game_state::SharedGameState;
|
||||
use crate::weapon::bullet::BulletManager;
|
||||
|
||||
impl NPC {
|
||||
pub(crate) fn tick_n117_curly(
|
||||
&mut self,
|
||||
state: &mut SharedGameState,
|
||||
players: [&mut Player; 2],
|
||||
npc_list: &NPCList,
|
||||
) -> GameResult {
|
||||
match self.action_num {
|
||||
0 | 1 => {
|
||||
if self.action_num == 0 {
|
||||
let player = self.get_closest_player_mut(players);
|
||||
|
||||
if self.direction == Direction::FacingPlayer {
|
||||
self.direction = if self.x <= player.x { Direction::Right } else { Direction::Left };
|
||||
}
|
||||
|
||||
self.action_num = 1;
|
||||
self.anim_num = 0;
|
||||
self.anim_counter = 0;
|
||||
}
|
||||
|
||||
self.vel_x = 0;
|
||||
self.vel_y += 0x40;
|
||||
}
|
||||
3 | 4 => {
|
||||
if self.action_num == 3 {
|
||||
self.action_num = 4;
|
||||
self.anim_num = 1;
|
||||
self.anim_counter = 0;
|
||||
}
|
||||
|
||||
self.animate(4, 1, 4);
|
||||
|
||||
self.vel_x = self.direction.vector_x() * 0x200;
|
||||
self.vel_y += 0x40;
|
||||
}
|
||||
5 => {
|
||||
self.action_num = 6;
|
||||
self.anim_num = 5;
|
||||
npc_list.create_death_smoke(self.x, self.y, self.display_bounds.right, 8, state, &self.rng);
|
||||
}
|
||||
6 => {
|
||||
self.anim_num = 5;
|
||||
}
|
||||
10 | 11 => {
|
||||
let player = self.get_closest_player_mut(players);
|
||||
|
||||
if self.action_num == 10 {
|
||||
self.action_num = 11;
|
||||
self.anim_num = 1;
|
||||
self.anim_counter = 0;
|
||||
self.direction = if self.x <= player.x { Direction::Right } else { Direction::Left };
|
||||
}
|
||||
|
||||
self.animate(4, 1, 4);
|
||||
self.x += self.direction.vector_x() * 0x200;
|
||||
|
||||
if abs(self.x - player.x) > 0x2800 {
|
||||
self.action_num = 0;
|
||||
}
|
||||
}
|
||||
20 => {
|
||||
self.vel_x = 0;
|
||||
self.anim_num = 6;
|
||||
}
|
||||
21 => {
|
||||
self.vel_x = 0;
|
||||
self.anim_num = 9;
|
||||
}
|
||||
30 | 31 => {
|
||||
if self.action_num == 30 {
|
||||
self.action_num = 31;
|
||||
self.action_counter = 0;
|
||||
self.vel_y = -0x400;
|
||||
}
|
||||
|
||||
self.anim_num = 7;
|
||||
self.vel_x = self.direction.vector_x() * 0x200;
|
||||
self.vel_y += 0x40;
|
||||
|
||||
self.action_counter += 1;
|
||||
if self.action_counter > 0 && self.flags.hit_bottom_wall() {
|
||||
self.action_num = 32;
|
||||
}
|
||||
}
|
||||
32 => {
|
||||
self.vel_x = 0;
|
||||
self.vel_y += 0x40;
|
||||
self.anim_num = 8;
|
||||
}
|
||||
70 | 71 => {
|
||||
if self.action_num == 70 {
|
||||
self.action_num = 71;
|
||||
self.action_counter = 0;
|
||||
self.anim_num = 1;
|
||||
self.anim_counter = 0;
|
||||
}
|
||||
|
||||
self.animate(8, 1, 4);
|
||||
self.x += self.direction.vector_x() * 0x100;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
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 { 10 };
|
||||
|
||||
self.anim_rect = state.constants.npc.n117_curly[self.anim_num as usize + dir_offset];
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn tick_n118_curly_boss(
|
||||
&mut self,
|
||||
state: &mut SharedGameState,
|
||||
players: [&mut Player; 2],
|
||||
npc_list: &NPCList,
|
||||
bullet_manager: &BulletManager,
|
||||
) -> GameResult {
|
||||
match self.action_num {
|
||||
0 => {
|
||||
self.action_num = 1;
|
||||
self.anim_num = 0;
|
||||
self.anim_counter = 0;
|
||||
}
|
||||
10 | 11 => {
|
||||
if self.action_num == 10 {
|
||||
self.action_num = 11;
|
||||
self.action_counter = self.rng.range(50..100) as u16;
|
||||
self.anim_num = 0;
|
||||
|
||||
let player = self.get_closest_player_mut(players);
|
||||
self.direction = if self.x <= player.x { Direction::Right } else { Direction::Left };
|
||||
self.npc_flags.set_shootable(true);
|
||||
self.npc_flags.set_invulnerable(false);
|
||||
}
|
||||
|
||||
if self.action_counter > 0 {
|
||||
self.action_counter -= 1;
|
||||
} else {
|
||||
self.action_num = 13;
|
||||
}
|
||||
}
|
||||
13 | 14 => {
|
||||
if self.action_num == 13 {
|
||||
self.action_num = 14;
|
||||
self.action_counter = self.rng.range(50..100) as u16;
|
||||
self.anim_num = 3;
|
||||
|
||||
let player = self.get_closest_player_mut(players);
|
||||
self.direction = if self.x <= player.x { Direction::Right } else { Direction::Left };
|
||||
}
|
||||
|
||||
self.animate(2, 3, 6);
|
||||
|
||||
self.vel_x += self.direction.vector_x() * 0x40;
|
||||
|
||||
if self.action_counter > 0 {
|
||||
self.action_counter -= 1;
|
||||
} else {
|
||||
self.npc_flags.set_shootable(true);
|
||||
self.action_num = 20;
|
||||
self.action_counter = 0;
|
||||
state.sound_manager.play_sfx(103);
|
||||
}
|
||||
}
|
||||
20 => {
|
||||
let player = self.get_closest_player_mut(players);
|
||||
|
||||
self.direction = if self.x <= player.x { Direction::Right } else { Direction::Left };
|
||||
|
||||
self.vel_x = 8 * self.vel_x / 9;
|
||||
|
||||
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 = 21;
|
||||
self.action_counter = 0;
|
||||
}
|
||||
}
|
||||
21 => {
|
||||
self.action_counter += 1;
|
||||
if self.action_counter % 4 == 1 {
|
||||
let player = self.get_closest_player_mut(players);
|
||||
|
||||
let facing_up = (self.direction == Direction::Left && self.x < player.x)
|
||||
|| (self.direction == Direction::Right && self.x > player.x);
|
||||
|
||||
let mut npc = NPC::create(123, &state.npc_table);
|
||||
npc.cond.set_alive(true);
|
||||
|
||||
if facing_up {
|
||||
self.anim_num = 2;
|
||||
npc.x = self.x;
|
||||
npc.y = self.y - 0x1000;
|
||||
npc.direction = Direction::Up;
|
||||
} else {
|
||||
self.anim_num = 0;
|
||||
self.x += self.direction.opposite().vector_x() * 0x200;
|
||||
|
||||
npc.x = self.x + self.direction.vector_x() * 0x1000;
|
||||
npc.y = self.y + 0x800;
|
||||
npc.direction = self.direction;
|
||||
}
|
||||
|
||||
let _ = npc_list.spawn(256, npc);
|
||||
}
|
||||
|
||||
if self.action_counter > 30 {
|
||||
self.action_num = 10;
|
||||
}
|
||||
}
|
||||
30 => {
|
||||
self.anim_num += 1;
|
||||
if self.anim_num > 8 {
|
||||
self.anim_num = 7;
|
||||
}
|
||||
|
||||
self.action_counter += 1;
|
||||
if self.action_counter > 30 {
|
||||
self.action_num = 10;
|
||||
self.anim_num = 0;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if self.action_num > 10 && self.action_num < 30 && bullet_manager.count_bullets_type_idx_all(6) > 0 {
|
||||
self.action_num = 30;
|
||||
self.action_counter = 0;
|
||||
self.anim_num = 7;
|
||||
|
||||
self.vel_x = 0;
|
||||
self.npc_flags.set_shootable(false);
|
||||
self.npc_flags.set_invulnerable(true);
|
||||
}
|
||||
|
||||
self.vel_x = clamp(self.vel_x, -0x1ff, 0x1ff);
|
||||
self.vel_y += 0x20;
|
||||
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 { 9 };
|
||||
|
||||
self.anim_rect = state.constants.npc.n118_curly_boss[self.anim_num as usize + dir_offset];
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -100,11 +100,7 @@ impl NPC {
|
|||
self.x += self.vel_x;
|
||||
self.y += self.vel_y;
|
||||
|
||||
let dir_offset = if self.direction == Direction::Left {
|
||||
0
|
||||
} else {
|
||||
3
|
||||
};
|
||||
let dir_offset = if self.direction == Direction::Left { 0 } else { 3 };
|
||||
|
||||
self.anim_rect = state.constants.npc.n241_critter_red[self.anim_num as usize + dir_offset];
|
||||
|
||||
|
|
|
@ -362,8 +362,6 @@ impl NPC {
|
|||
}
|
||||
|
||||
pub(crate) fn tick_n081_giant_pignon(&mut self, state: &mut SharedGameState, players: [&mut Player; 2]) -> GameResult {
|
||||
let dir_offset = if self.direction == Direction::Left { 0 } else { 6 };
|
||||
|
||||
match self.action_num {
|
||||
0 | 1 => {
|
||||
if self.action_num == 0 {
|
||||
|
@ -371,25 +369,22 @@ impl NPC {
|
|||
self.anim_num = 0;
|
||||
self.anim_counter = 0;
|
||||
self.vel_x = 0;
|
||||
|
||||
self.anim_rect = state.constants.npc.n081_giant_pignon[self.anim_num as usize + dir_offset];
|
||||
}
|
||||
|
||||
if self.rng.range(0..100) == 1 {
|
||||
self.action_num = 2;
|
||||
self.action_counter = 0;
|
||||
self.anim_num = 1;
|
||||
} else {
|
||||
if self.rng.range(0..150) == 1 {
|
||||
self.direction = self.direction.opposite();
|
||||
}
|
||||
|
||||
self.anim_rect = state.constants.npc.n081_giant_pignon[self.anim_num as usize + dir_offset];
|
||||
}
|
||||
|
||||
|
||||
if self.rng.range(0..150) == 1 {
|
||||
self.action_num = 3;
|
||||
self.action_counter = 50;
|
||||
self.anim_num = 0;
|
||||
|
||||
self.anim_rect = state.constants.npc.n081_giant_pignon[self.anim_num as usize + dir_offset];
|
||||
if self.rng.range(0..150) == 1 {
|
||||
self.action_num = 3;
|
||||
self.action_counter = 50;
|
||||
self.anim_num = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
2 => {
|
||||
|
@ -397,8 +392,6 @@ impl NPC {
|
|||
if self.action_counter > 8 {
|
||||
self.action_num = 1;
|
||||
self.anim_num = 0;
|
||||
|
||||
self.anim_rect = state.constants.npc.n081_giant_pignon[self.anim_num as usize + dir_offset];
|
||||
}
|
||||
}
|
||||
3 | 4 => {
|
||||
|
@ -406,8 +399,6 @@ impl NPC {
|
|||
self.action_num = 4;
|
||||
self.anim_num = 2;
|
||||
self.anim_counter = 0;
|
||||
|
||||
self.anim_rect = state.constants.npc.n081_giant_pignon[self.anim_num as usize + dir_offset];
|
||||
}
|
||||
|
||||
if self.action_counter > 0 {
|
||||
|
@ -416,16 +407,7 @@ impl NPC {
|
|||
self.action_num = 0;
|
||||
}
|
||||
|
||||
self.anim_counter += 1;
|
||||
if self.anim_counter > 2 {
|
||||
self.anim_counter = 0;
|
||||
self.anim_num += 1;
|
||||
if self.anim_num > 4 {
|
||||
self.anim_num = 2;
|
||||
}
|
||||
|
||||
self.anim_rect = state.constants.npc.n081_giant_pignon[self.anim_num as usize + dir_offset];
|
||||
}
|
||||
self.animate(2, 2, 4);
|
||||
|
||||
if self.flags.hit_left_wall() {
|
||||
self.direction = Direction::Right;
|
||||
|
@ -435,7 +417,7 @@ impl NPC {
|
|||
self.direction = Direction::Left;
|
||||
}
|
||||
|
||||
self.vel_x = self.direction.vector_x() * 0x100; // 0.5fix9
|
||||
self.vel_x = self.direction.vector_x() * 0x100;
|
||||
}
|
||||
5 => {
|
||||
if self.flags.hit_bottom_wall() {
|
||||
|
@ -451,8 +433,6 @@ impl NPC {
|
|||
self.vel_y = -0x200;
|
||||
self.anim_num = 5;
|
||||
self.action_num = 5;
|
||||
|
||||
self.anim_rect = state.constants.npc.n081_giant_pignon[self.anim_num as usize + dir_offset];
|
||||
}
|
||||
|
||||
self.vel_y += 0x40;
|
||||
|
@ -464,6 +444,10 @@ impl NPC {
|
|||
self.x += self.vel_x;
|
||||
self.y += self.vel_y;
|
||||
|
||||
let dir_offset = if self.direction == Direction::Left { 0 } else { 6 };
|
||||
|
||||
self.anim_rect = state.constants.npc.n081_giant_pignon[self.anim_num as usize + dir_offset];
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -72,6 +72,7 @@ impl NPC {
|
|||
|
||||
if self.anim_num > 7 {
|
||||
self.cond.set_alive(false);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ pub mod balrog;
|
|||
pub mod booster;
|
||||
pub mod chaco;
|
||||
pub mod characters;
|
||||
pub mod curly;
|
||||
pub mod egg_corridor;
|
||||
pub mod first_cave;
|
||||
pub mod grasstown;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::mem::MaybeUninit;
|
||||
|
||||
use crate::weapon::bullet::BulletManager;
|
||||
use crate::common::{Direction, interpolate_fix9_scale};
|
||||
use crate::common::{interpolate_fix9_scale, Direction};
|
||||
use crate::components::flash::Flash;
|
||||
use crate::entity::GameEntity;
|
||||
use crate::frame::Frame;
|
||||
use crate::framework::context::Context;
|
||||
|
@ -11,6 +11,7 @@ use crate::npc::NPC;
|
|||
use crate::player::Player;
|
||||
use crate::shared_game_state::SharedGameState;
|
||||
use crate::stage::Stage;
|
||||
use crate::weapon::bullet::BulletManager;
|
||||
|
||||
pub mod balfrog;
|
||||
pub mod ballos;
|
||||
|
@ -45,33 +46,41 @@ impl BossNPC {
|
|||
parts[0].cond.set_alive(true);
|
||||
|
||||
for (i, part) in parts.iter_mut().enumerate() {
|
||||
part.rng.load_state(((i as u32)
|
||||
.wrapping_add(3271284409)
|
||||
.rotate_left(5)
|
||||
.wrapping_mul(3815776271)
|
||||
.rotate_right(9)
|
||||
.wrapping_sub(2626817629) & 0xffffffff) as u32);
|
||||
part.rng.load_state(
|
||||
((i as u32)
|
||||
.wrapping_add(3271284409)
|
||||
.rotate_left(5)
|
||||
.wrapping_mul(3815776271)
|
||||
.rotate_right(9)
|
||||
.wrapping_sub(2626817629)
|
||||
& 0xffffffff) as u32,
|
||||
);
|
||||
}
|
||||
|
||||
BossNPC {
|
||||
boss_type: 0,
|
||||
parts,
|
||||
hurt_sound: [0; 20],
|
||||
death_sound: [0; 20],
|
||||
}
|
||||
BossNPC { boss_type: 0, parts, hurt_sound: [0; 20], death_sound: [0; 20] }
|
||||
}
|
||||
}
|
||||
|
||||
impl GameEntity<([&mut Player; 2], &NPCList, &mut Stage, &BulletManager)> for BossNPC {
|
||||
fn tick(&mut self, state: &mut SharedGameState, (players, npc_list, _stage, bullet_manager): ([&mut Player; 2], &NPCList, &mut Stage, &BulletManager)) -> GameResult {
|
||||
impl GameEntity<([&mut Player; 2], &NPCList, &mut Stage, &BulletManager, &mut Flash)> for BossNPC {
|
||||
fn tick(
|
||||
&mut self,
|
||||
state: &mut SharedGameState,
|
||||
(players, npc_list, _stage, bullet_manager, flash): (
|
||||
[&mut Player; 2],
|
||||
&NPCList,
|
||||
&mut Stage,
|
||||
&BulletManager,
|
||||
&mut Flash,
|
||||
),
|
||||
) -> GameResult {
|
||||
if !self.parts[0].cond.alive() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
match self.boss_type {
|
||||
1 => self.tick_b01_omega(state, players, npc_list, bullet_manager),
|
||||
1 => self.tick_b01_omega(state, players, npc_list, bullet_manager, flash),
|
||||
2 => self.tick_b02_balfrog(state, players, npc_list),
|
||||
3 => self.tick_b03_monster_x(state, players, npc_list),
|
||||
3 => self.tick_b03_monster_x(state, players, npc_list, flash),
|
||||
4 => self.tick_b04_core(),
|
||||
5 => self.tick_b05_ironhead(),
|
||||
6 => self.tick_b06_twins(),
|
||||
|
@ -90,25 +99,27 @@ impl GameEntity<([&mut Player; 2], &NPCList, &mut Stage, &BulletManager)> for Bo
|
|||
}
|
||||
|
||||
fn draw(&self, state: &mut SharedGameState, ctx: &mut Context, frame: &Frame) -> GameResult {
|
||||
let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, state.npc_table.tex_npc2_name.as_str())?;
|
||||
let batch =
|
||||
state.texture_set.get_or_load_batch(ctx, &state.constants, state.npc_table.tex_npc2_name.as_str())?;
|
||||
|
||||
for npc in self.parts.iter().rev() {
|
||||
if !npc.cond.alive() || npc.cond.hidden() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let off_x = if npc.direction == Direction::Left { npc.display_bounds.left } else { npc.display_bounds.right } as i32;
|
||||
let shock = if npc.shock > 0 {
|
||||
(2 * ((npc.shock as i32 / 2) % 2) - 1) as f32
|
||||
} else { 0.0 };
|
||||
let off_x =
|
||||
if npc.direction == Direction::Left { npc.display_bounds.left } else { npc.display_bounds.right }
|
||||
as i32;
|
||||
let shock = if npc.shock > 0 { (2 * ((npc.shock as i32 / 2) % 2) - 1) as f32 } else { 0.0 };
|
||||
|
||||
batch.add_rect(
|
||||
interpolate_fix9_scale(npc.prev_x - off_x - frame.prev_x,
|
||||
npc.x - off_x - frame.x,
|
||||
state.frame_time) + shock,
|
||||
interpolate_fix9_scale(npc.prev_y - npc.display_bounds.top as i32 - frame.prev_y,
|
||||
npc.y - npc.display_bounds.top as i32 - frame.y,
|
||||
state.frame_time),
|
||||
interpolate_fix9_scale(npc.prev_x - off_x - frame.prev_x, npc.x - off_x - frame.x, state.frame_time)
|
||||
+ shock,
|
||||
interpolate_fix9_scale(
|
||||
npc.prev_y - npc.display_bounds.top as i32 - frame.prev_y,
|
||||
npc.y - npc.display_bounds.top as i32 - frame.y,
|
||||
state.frame_time,
|
||||
),
|
||||
&npc.anim_rect,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use num_traits::{abs, clamp};
|
||||
|
||||
use crate::caret::CaretType;
|
||||
use crate::common::{CDEG_RAD, Direction, Rect};
|
||||
use crate::common::{Direction, Rect, CDEG_RAD};
|
||||
use crate::components::flash::Flash;
|
||||
use crate::framework::context::Context;
|
||||
use crate::framework::error::GameResult;
|
||||
use crate::npc::boss::BossNPC;
|
||||
|
@ -12,7 +13,11 @@ use crate::rng::RNG;
|
|||
use crate::shared_game_state::SharedGameState;
|
||||
|
||||
impl NPC {
|
||||
pub(crate) fn tick_n158_fish_missile(&mut self, state: &mut SharedGameState, players: [&mut Player; 2]) -> GameResult {
|
||||
pub(crate) fn tick_n158_fish_missile(
|
||||
&mut self,
|
||||
state: &mut SharedGameState,
|
||||
players: [&mut Player; 2],
|
||||
) -> GameResult {
|
||||
match self.action_num {
|
||||
0 | 1 => {
|
||||
if self.action_num == 0 {
|
||||
|
@ -72,7 +77,13 @@ impl NPC {
|
|||
}
|
||||
|
||||
impl BossNPC {
|
||||
pub(crate) fn tick_b03_monster_x(&mut self, state: &mut SharedGameState, players: [&mut Player; 2], npc_list: &NPCList) {
|
||||
pub(crate) fn tick_b03_monster_x(
|
||||
&mut self,
|
||||
state: &mut SharedGameState,
|
||||
players: [&mut Player; 2],
|
||||
npc_list: &NPCList,
|
||||
flash: &mut Flash,
|
||||
) {
|
||||
match self.parts[0].action_num {
|
||||
0 => {
|
||||
self.parts[0].life = 1;
|
||||
|
@ -87,12 +98,8 @@ impl BossNPC {
|
|||
self.parts[0].y = 200 * 0x200;
|
||||
self.parts[0].size = 3;
|
||||
self.parts[0].event_num = 1000;
|
||||
self.parts[0].hit_bounds = Rect {
|
||||
left: 24 * 0x200,
|
||||
top: 24 * 0x200,
|
||||
right: 24 * 0x200,
|
||||
bottom: 24 * 0x200,
|
||||
};
|
||||
self.parts[0].hit_bounds =
|
||||
Rect { left: 24 * 0x200, top: 24 * 0x200, right: 24 * 0x200, bottom: 24 * 0x200 };
|
||||
self.parts[0].npc_flags.set_ignore_solidity(true);
|
||||
self.parts[0].npc_flags.set_event_when_killed(true);
|
||||
self.parts[0].npc_flags.set_show_damage(true);
|
||||
|
@ -101,12 +108,8 @@ impl BossNPC {
|
|||
self.parts[1].cond.set_alive(true);
|
||||
self.parts[1].size = 3;
|
||||
self.parts[1].direction = Direction::Left;
|
||||
self.parts[1].display_bounds = Rect {
|
||||
left: 24 * 0x200,
|
||||
top: 24 * 0x200,
|
||||
right: 24 * 0x200,
|
||||
bottom: 24 * 0x200,
|
||||
};
|
||||
self.parts[1].display_bounds =
|
||||
Rect { left: 24 * 0x200, top: 24 * 0x200, right: 24 * 0x200, bottom: 24 * 0x200 };
|
||||
self.parts[1].npc_flags.set_ignore_solidity(true);
|
||||
|
||||
self.parts[2] = self.parts[1].clone();
|
||||
|
@ -116,18 +119,10 @@ impl BossNPC {
|
|||
self.parts[3].life = 60;
|
||||
self.parts[3].size = 2;
|
||||
self.parts[3].target_x = 0;
|
||||
self.parts[3].display_bounds = Rect {
|
||||
left: 8 * 0x200,
|
||||
top: 8 * 0x200,
|
||||
right: 8 * 0x200,
|
||||
bottom: 8 * 0x200,
|
||||
};
|
||||
self.parts[3].hit_bounds = Rect {
|
||||
left: 5 * 0x200,
|
||||
top: 5 * 0x200,
|
||||
right: 5 * 0x200,
|
||||
bottom: 5 * 0x200,
|
||||
};
|
||||
self.parts[3].display_bounds =
|
||||
Rect { left: 8 * 0x200, top: 8 * 0x200, right: 8 * 0x200, bottom: 8 * 0x200 };
|
||||
self.parts[3].hit_bounds =
|
||||
Rect { left: 5 * 0x200, top: 5 * 0x200, right: 5 * 0x200, bottom: 5 * 0x200 };
|
||||
self.parts[3].npc_flags.set_ignore_solidity(true);
|
||||
self.hurt_sound[3] = 54;
|
||||
self.death_sound[3] = 71;
|
||||
|
@ -147,18 +142,10 @@ impl BossNPC {
|
|||
self.parts[7].y = self.parts[0].y;
|
||||
self.parts[7].size = 3;
|
||||
self.parts[7].anim_num = 0;
|
||||
self.parts[7].display_bounds = Rect {
|
||||
left: 52 * 0x200,
|
||||
top: 24 * 0x200,
|
||||
right: 52 * 0x200,
|
||||
bottom: 24 * 0x200,
|
||||
};
|
||||
self.parts[7].hit_bounds = Rect {
|
||||
left: 8 * 0x200,
|
||||
top: 24 * 0x200,
|
||||
right: 8 * 0x200,
|
||||
bottom: 16 * 0x200,
|
||||
};
|
||||
self.parts[7].display_bounds =
|
||||
Rect { left: 52 * 0x200, top: 24 * 0x200, right: 52 * 0x200, bottom: 24 * 0x200 };
|
||||
self.parts[7].hit_bounds =
|
||||
Rect { left: 8 * 0x200, top: 24 * 0x200, right: 8 * 0x200, bottom: 16 * 0x200 };
|
||||
self.parts[7].npc_flags.set_ignore_solidity(true);
|
||||
|
||||
self.parts[9].cond.set_alive(true);
|
||||
|
@ -167,18 +154,10 @@ impl BossNPC {
|
|||
self.parts[9].size = 3;
|
||||
self.parts[9].action_num = 0;
|
||||
self.parts[9].direction = Direction::Up;
|
||||
self.parts[9].display_bounds = Rect {
|
||||
left: 36 * 0x200,
|
||||
top: 8 * 0x200,
|
||||
right: 36 * 0x200,
|
||||
bottom: 24 * 0x200,
|
||||
};
|
||||
self.parts[9].hit_bounds = Rect {
|
||||
left: 28 * 0x200,
|
||||
top: 8 * 0x200,
|
||||
right: 28 * 0x200,
|
||||
bottom: 16 * 0x200,
|
||||
};
|
||||
self.parts[9].display_bounds =
|
||||
Rect { left: 36 * 0x200, top: 8 * 0x200, right: 36 * 0x200, bottom: 24 * 0x200 };
|
||||
self.parts[9].hit_bounds =
|
||||
Rect { left: 28 * 0x200, top: 8 * 0x200, right: 28 * 0x200, bottom: 16 * 0x200 };
|
||||
self.hurt_sound[9] = 52;
|
||||
self.parts[9].npc_flags.set_rear_and_top_not_hurt(true);
|
||||
self.parts[9].npc_flags.set_ignore_solidity(true);
|
||||
|
@ -201,12 +180,8 @@ impl BossNPC {
|
|||
self.parts[12].x = self.parts[0].x + 64 * 0x200;
|
||||
|
||||
self.parts[13] = self.parts[9].clone();
|
||||
self.parts[13].display_bounds = Rect {
|
||||
left: 30 * 0x200,
|
||||
top: 16 * 0x200,
|
||||
right: 42 * 0x200,
|
||||
bottom: 16 * 0x200,
|
||||
};
|
||||
self.parts[13].display_bounds =
|
||||
Rect { left: 30 * 0x200, top: 16 * 0x200, right: 42 * 0x200, bottom: 16 * 0x200 };
|
||||
self.parts[13].action_counter2 = 9;
|
||||
self.parts[13].anim_num = 0;
|
||||
self.parts[13].npc_flags.0 = 0;
|
||||
|
@ -318,8 +293,11 @@ impl BossNPC {
|
|||
}
|
||||
|
||||
if self.parts[0].action_counter > 50 {
|
||||
if !self.parts[3].cond.alive() && !self.parts[4].cond.alive()
|
||||
&& !self.parts[5].cond.alive() && !self.parts[6].cond.alive() {
|
||||
if !self.parts[3].cond.alive()
|
||||
&& !self.parts[4].cond.alive()
|
||||
&& !self.parts[5].cond.alive()
|
||||
&& !self.parts[6].cond.alive()
|
||||
{
|
||||
self.parts[0].action_num = 600;
|
||||
} else {
|
||||
self.parts[0].action_num = 500;
|
||||
|
@ -343,8 +321,11 @@ impl BossNPC {
|
|||
}
|
||||
|
||||
if self.parts[0].action_counter > 50 {
|
||||
if !self.parts[3].cond.alive() && !self.parts[4].cond.alive()
|
||||
&& !self.parts[5].cond.alive() && !self.parts[6].cond.alive() {
|
||||
if !self.parts[3].cond.alive()
|
||||
&& !self.parts[4].cond.alive()
|
||||
&& !self.parts[5].cond.alive()
|
||||
&& !self.parts[6].cond.alive()
|
||||
{
|
||||
self.parts[0].action_num = 600;
|
||||
} else {
|
||||
self.parts[0].action_num = 500;
|
||||
|
@ -366,8 +347,11 @@ impl BossNPC {
|
|||
self.parts[0].action_counter = 0;
|
||||
}
|
||||
|
||||
if !self.parts[3].cond.alive() && !self.parts[4].cond.alive()
|
||||
&& !self.parts[5].cond.alive() && !self.parts[6].cond.alive() {
|
||||
if !self.parts[3].cond.alive()
|
||||
&& !self.parts[4].cond.alive()
|
||||
&& !self.parts[5].cond.alive()
|
||||
&& !self.parts[6].cond.alive()
|
||||
{
|
||||
self.parts[0].action_num = 502;
|
||||
self.parts[0].action_counter = 0;
|
||||
}
|
||||
|
@ -399,7 +383,8 @@ impl BossNPC {
|
|||
|
||||
self.parts[0].action_counter += 1;
|
||||
if (self.parts[0].life as i32) < self.parts[0].vel_y2.saturating_sub(200)
|
||||
|| self.parts[0].action_counter > 300 {
|
||||
|| self.parts[0].action_counter > 300
|
||||
{
|
||||
self.parts[0].action_num = 602;
|
||||
self.parts[0].action_counter = 0;
|
||||
}
|
||||
|
@ -437,7 +422,7 @@ impl BossNPC {
|
|||
if self.parts[0].action_counter > 100 {
|
||||
self.parts[0].action_num = 1001;
|
||||
self.parts[0].action_counter = 0;
|
||||
// todo flash
|
||||
flash.set_cross(self.parts[0].x, self.parts[0].y);
|
||||
state.sound_manager.play_sfx(35);
|
||||
}
|
||||
}
|
||||
|
@ -472,7 +457,8 @@ impl BossNPC {
|
|||
self.tick_b03_monster_x_track(11, state, &players);
|
||||
self.tick_b03_monster_x_track(12, state, &players);
|
||||
|
||||
self.parts[0].x += (((self.parts[9].x + self.parts[10].x + self.parts[11].x + self.parts[12].x) / 4) - self.parts[0].x) / 16;
|
||||
self.parts[0].x +=
|
||||
(((self.parts[9].x + self.parts[10].x + self.parts[11].x + self.parts[12].x) / 4) - self.parts[0].x) / 16;
|
||||
self.tick_b03_monster_x_face(7, state);
|
||||
|
||||
self.tick_b03_monster_x_frame(13, state, npc_list);
|
||||
|
@ -483,10 +469,18 @@ impl BossNPC {
|
|||
self.tick_b03_monster_x_shield(1, state);
|
||||
self.tick_b03_monster_x_shield(2, state);
|
||||
|
||||
if self.parts[3].cond.alive() { self.tick_b03_monster_x_eye(3, state, &players, npc_list); }
|
||||
if self.parts[4].cond.alive() { self.tick_b03_monster_x_eye(4, state, &players, npc_list); }
|
||||
if self.parts[5].cond.alive() { self.tick_b03_monster_x_eye(5, state, &players, npc_list); }
|
||||
if self.parts[6].cond.alive() { self.tick_b03_monster_x_eye(6, state, &players, npc_list); }
|
||||
if self.parts[3].cond.alive() {
|
||||
self.tick_b03_monster_x_eye(3, state, &players, npc_list);
|
||||
}
|
||||
if self.parts[4].cond.alive() {
|
||||
self.tick_b03_monster_x_eye(4, state, &players, npc_list);
|
||||
}
|
||||
if self.parts[5].cond.alive() {
|
||||
self.tick_b03_monster_x_eye(5, state, &players, npc_list);
|
||||
}
|
||||
if self.parts[6].cond.alive() {
|
||||
self.tick_b03_monster_x_eye(6, state, &players, npc_list);
|
||||
}
|
||||
|
||||
if self.parts[0].life == 0 && self.parts[0].action_num < 1000 {
|
||||
self.parts[0].action_num = 1000;
|
||||
|
@ -776,7 +770,13 @@ impl BossNPC {
|
|||
self.parts[i].anim_rect = state.constants.npc.b03_monster_x[dir_offset];
|
||||
}
|
||||
|
||||
fn tick_b03_monster_x_eye(&mut self, i: usize, state: &mut SharedGameState, players: &[&mut Player; 2], npc_list: &NPCList) {
|
||||
fn tick_b03_monster_x_eye(
|
||||
&mut self,
|
||||
i: usize,
|
||||
state: &mut SharedGameState,
|
||||
players: &[&mut Player; 2],
|
||||
npc_list: &NPCList,
|
||||
) {
|
||||
match self.parts[i].action_num {
|
||||
0 => {
|
||||
self.parts[i].npc_flags.set_shootable(false);
|
||||
|
@ -789,8 +789,8 @@ impl BossNPC {
|
|||
self.parts[i].npc_flags.set_shootable(true);
|
||||
}
|
||||
|
||||
self.parts[i].anim_num = if self.parts[i].action_counter < 16
|
||||
&& self.parts[i].action_counter / 2 % 2 != 0 { 1 } else { 0 };
|
||||
self.parts[i].anim_num =
|
||||
if self.parts[i].action_counter < 16 && self.parts[i].action_counter / 2 % 2 != 0 { 1 } else { 0 };
|
||||
|
||||
if self.parts[i].action_counter > 0 {
|
||||
self.parts[i].action_counter -= 1;
|
||||
|
@ -799,8 +799,7 @@ impl BossNPC {
|
|||
let px = self.parts[i].x - players[player_idx].x;
|
||||
let py = self.parts[i].y - players[player_idx].y;
|
||||
|
||||
let deg = f64::atan2(py as f64, px as f64)
|
||||
+ self.parts[i].rng.range(-2..2) as f64 * CDEG_RAD;
|
||||
let deg = f64::atan2(py as f64, px as f64) + self.parts[i].rng.range(-2..2) as f64 * CDEG_RAD;
|
||||
|
||||
let mut npc = NPC::create(156, &state.npc_table);
|
||||
npc.cond.set_alive(true);
|
||||
|
@ -838,6 +837,7 @@ impl BossNPC {
|
|||
_ => {}
|
||||
}
|
||||
|
||||
self.parts[i].anim_rect = state.constants.npc.b03_monster_x[21 + self.parts[i].target_x as usize + 4 * self.parts[i].anim_num as usize];
|
||||
self.parts[i].anim_rect = state.constants.npc.b03_monster_x
|
||||
[21 + self.parts[i].target_x as usize + 4 * self.parts[i].anim_num as usize];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
|
||||
|
||||
use crate::weapon::bullet::BulletManager;
|
||||
use crate::caret::CaretType;
|
||||
use crate::common::{Direction, Rect};
|
||||
use crate::components::flash::Flash;
|
||||
use crate::framework::context::Context;
|
||||
use crate::framework::error::GameResult;
|
||||
use crate::npc::boss::BossNPC;
|
||||
use crate::npc::list::NPCList;
|
||||
use crate::npc::NPC;
|
||||
use crate::player::Player;
|
||||
use crate::rng::RNG;
|
||||
use crate::shared_game_state::SharedGameState;
|
||||
use crate::framework::context::Context;
|
||||
use crate::framework::error::GameResult;
|
||||
use crate::weapon::bullet::BulletManager;
|
||||
|
||||
impl NPC {
|
||||
pub(crate) fn tick_n048_omega_projectiles(&mut self, state: &mut SharedGameState) -> GameResult {
|
||||
if (self.flags.hit_left_wall() && self.vel_x < 0)
|
||||
|| (self.flags.hit_right_wall() && self.vel_x > 0) {
|
||||
if (self.flags.hit_left_wall() && self.vel_x < 0) || (self.flags.hit_right_wall() && self.vel_x > 0) {
|
||||
self.vel_x = -self.vel_x;
|
||||
} else if self.flags.hit_bottom_wall() {
|
||||
self.action_counter2 += 1;
|
||||
|
@ -53,7 +51,14 @@ impl NPC {
|
|||
}
|
||||
|
||||
impl BossNPC {
|
||||
pub(crate) fn tick_b01_omega(&mut self, state: &mut SharedGameState, players: [&mut Player; 2], npc_list: &NPCList, bullet_manager: &BulletManager) {
|
||||
pub(crate) fn tick_b01_omega(
|
||||
&mut self,
|
||||
state: &mut SharedGameState,
|
||||
players: [&mut Player; 2],
|
||||
npc_list: &NPCList,
|
||||
bullet_manager: &BulletManager,
|
||||
flash: &mut Flash,
|
||||
) {
|
||||
match self.parts[0].action_num {
|
||||
0 => {
|
||||
self.parts[0].cond.set_alive(true);
|
||||
|
@ -68,26 +73,14 @@ impl BossNPC {
|
|||
self.parts[0].y = 16 * 16 * 0x200;
|
||||
self.parts[0].target_x = self.parts[0].x;
|
||||
self.parts[0].target_y = self.parts[0].y;
|
||||
self.parts[0].display_bounds = Rect {
|
||||
left: 40 * 0x200,
|
||||
top: 40 * 0x200,
|
||||
right: 40 * 0x200,
|
||||
bottom: 16 * 0x200,
|
||||
};
|
||||
self.parts[0].hit_bounds = Rect {
|
||||
left: 8 * 0x200,
|
||||
top: 24 * 0x200,
|
||||
right: 8 * 0x200,
|
||||
bottom: 16 * 0x200,
|
||||
};
|
||||
self.parts[0].display_bounds =
|
||||
Rect { left: 40 * 0x200, top: 40 * 0x200, right: 40 * 0x200, bottom: 16 * 0x200 };
|
||||
self.parts[0].hit_bounds =
|
||||
Rect { left: 8 * 0x200, top: 24 * 0x200, right: 8 * 0x200, bottom: 16 * 0x200 };
|
||||
|
||||
self.parts[1].cond.set_alive(true);
|
||||
self.parts[1].display_bounds = Rect {
|
||||
left: 12 * 0x200,
|
||||
top: 8 * 0x200,
|
||||
right: 12 * 0x200,
|
||||
bottom: 8 * 0x200,
|
||||
};
|
||||
self.parts[1].display_bounds =
|
||||
Rect { left: 12 * 0x200, top: 8 * 0x200, right: 12 * 0x200, bottom: 8 * 0x200 };
|
||||
self.parts[1].npc_flags.set_ignore_solidity(true);
|
||||
self.parts[1].direction = Direction::Left;
|
||||
|
||||
|
@ -101,18 +94,10 @@ impl BossNPC {
|
|||
self.parts[3].direction = Direction::Left;
|
||||
self.parts[3].x = self.parts[0].x + 16 * 0x200;
|
||||
self.parts[3].y = self.parts[0].y;
|
||||
self.parts[3].display_bounds = Rect {
|
||||
left: 24 * 0x200,
|
||||
top: 16 * 0x200,
|
||||
right: 16 * 0x200,
|
||||
bottom: 16 * 0x200,
|
||||
};
|
||||
self.parts[3].hit_bounds = Rect {
|
||||
left: 8 * 0x200,
|
||||
top: 8 * 0x200,
|
||||
right: 8 * 0x200,
|
||||
bottom: 8 * 0x200,
|
||||
};
|
||||
self.parts[3].display_bounds =
|
||||
Rect { left: 24 * 0x200, top: 16 * 0x200, right: 16 * 0x200, bottom: 16 * 0x200 };
|
||||
self.parts[3].hit_bounds =
|
||||
Rect { left: 8 * 0x200, top: 8 * 0x200, right: 8 * 0x200, bottom: 8 * 0x200 };
|
||||
self.hurt_sound[3] = 52;
|
||||
|
||||
self.parts[4].cond.set_alive(true);
|
||||
|
@ -191,11 +176,7 @@ impl BossNPC {
|
|||
npc.y = self.parts[0].y - 16 * 0x200;
|
||||
npc.vel_x = self.parts[0].rng.range(-0x100..0x100) as i32;
|
||||
npc.vel_y = -0x333;
|
||||
npc.direction = if self.parts[0].rng.range(0..9) <= 7 {
|
||||
Direction::Left
|
||||
} else {
|
||||
Direction::Right
|
||||
};
|
||||
npc.direction = if self.parts[0].rng.range(0..9) <= 7 { Direction::Left } else { Direction::Right };
|
||||
|
||||
let _ = npc_list.spawn(0x100, npc);
|
||||
state.sound_manager.play_sfx(39);
|
||||
|
@ -264,12 +245,13 @@ impl BossNPC {
|
|||
if self.parts[0].anim_counter > 2 {
|
||||
self.parts[0].anim_counter = 0;
|
||||
self.parts[0].anim_num += 1;
|
||||
if self.parts[0].anim_num == 3 {
|
||||
self.parts[0].action_num = 120;
|
||||
self.parts[0].action_counter = 0;
|
||||
self.parts[0].hit_bounds.left = 16 * 0x200;
|
||||
self.parts[0].hit_bounds.right = 16 * 0x200;
|
||||
}
|
||||
}
|
||||
|
||||
if self.parts[0].anim_num == 3 {
|
||||
self.parts[0].action_num = 120;
|
||||
self.parts[0].action_counter = 0;
|
||||
self.parts[0].hit_bounds.left = 16 * 0x200;
|
||||
self.parts[0].hit_bounds.right = 16 * 0x200;
|
||||
}
|
||||
}
|
||||
120 => {
|
||||
|
@ -282,7 +264,7 @@ impl BossNPC {
|
|||
state.sound_manager.play_sfx(102);
|
||||
}
|
||||
|
||||
if self.parts[0].action_counter <= 29 && self.parts[0].action_counter % 5 == 0 {
|
||||
if self.parts[0].action_counter < 30 && self.parts[0].action_counter % 5 == 0 {
|
||||
let mut npc = NPC::create(48, &state.npc_table);
|
||||
npc.cond.set_alive(true);
|
||||
npc.x = self.parts[0].x;
|
||||
|
@ -300,30 +282,33 @@ impl BossNPC {
|
|||
if self.parts[0].anim_counter > 2 {
|
||||
self.parts[0].anim_counter = 0;
|
||||
self.parts[0].anim_num -= 1;
|
||||
}
|
||||
|
||||
match self.parts[0].anim_num {
|
||||
1 => self.parts[0].damage = 20,
|
||||
0 => {
|
||||
self.parts[0].action_num = 140;
|
||||
self.parts[0].npc_flags.set_shootable(true);
|
||||
self.parts[0].hit_bounds.left = 16 * 0x200;
|
||||
self.parts[0].hit_bounds.right = 16 * 0x200;
|
||||
let player = self.parts[0].get_closest_player_mut(players);
|
||||
self.parts[0].vel_x = (player.x - self.parts[0].x).signum() * 0x100;
|
||||
self.parts[0].damage = 0;
|
||||
self.parts[0].hit_bounds.top = 36 * 0x200;
|
||||
}
|
||||
_ => {}
|
||||
match self.parts[0].anim_num {
|
||||
0 => {
|
||||
self.parts[0].action_num = 140;
|
||||
self.parts[0].npc_flags.set_shootable(true);
|
||||
self.parts[0].hit_bounds.left = 16 * 0x200;
|
||||
self.parts[0].hit_bounds.right = 16 * 0x200;
|
||||
let player = self.parts[0].get_closest_player_mut(players);
|
||||
self.parts[0].vel_x = (player.x - self.parts[0].x).signum() * 0x100;
|
||||
self.parts[0].vel_y = -0x5ff;
|
||||
self.parts[0].damage = 0;
|
||||
self.parts[5].hit_bounds.top = 0x4800;
|
||||
|
||||
state.sound_manager.play_sfx(12);
|
||||
state.sound_manager.play_sfx(25);
|
||||
state.sound_manager.play_sfx(102);
|
||||
}
|
||||
1 => {
|
||||
self.parts[0].damage = 20;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
140 => {
|
||||
let player = self.parts[5].get_closest_player_mut(players);
|
||||
self.parts[5].damage = if player.flags.hit_bottom_wall() && self.parts[0].vel_y > 0 {
|
||||
20
|
||||
} else {
|
||||
0
|
||||
};
|
||||
self.parts[5].damage = if player.flags.hit_bottom_wall() && self.parts[0].vel_y > 0 { 20 } else { 0 };
|
||||
self.parts[0].vel_y += 0x24;
|
||||
if self.parts[0].vel_y > 0x5ff {
|
||||
self.parts[0].vel_y = 0x5ff;
|
||||
|
@ -352,20 +337,15 @@ impl BossNPC {
|
|||
state.sound_manager.play_sfx(52);
|
||||
}
|
||||
|
||||
let dest_x = self.parts[0].x + self.parts[0].rng.range(-0x30..0x30) as i32 * 0x200;
|
||||
let dest_y = self.parts[0].y + self.parts[0].rng.range(-0x30..0x18) as i32 * 0x200;
|
||||
let dest_x = self.parts[0].x + self.parts[0].rng.range(-0x30..0x30) * 0x200;
|
||||
let dest_y = self.parts[0].y + self.parts[0].rng.range(-0x30..0x18) * 0x200;
|
||||
|
||||
let mut npc = NPC::create(4, &state.npc_table);
|
||||
npc.cond.set_alive(true);
|
||||
npc.x = dest_x;
|
||||
npc.y = dest_y;
|
||||
let _ = npc_list.spawn(0x100, npc);
|
||||
state.create_caret(dest_x, dest_y, CaretType::Explosion, Direction::Left);
|
||||
npc_list.create_death_smoke(dest_x, dest_y, 1, 1, state, &self.parts[0].rng);
|
||||
|
||||
if self.parts[0].action_counter > 100 {
|
||||
self.parts[0].action_num = 160;
|
||||
self.parts[0].action_counter = 0;
|
||||
// todo flash
|
||||
flash.set_cross(self.parts[0].x, self.parts[0].y);
|
||||
state.sound_manager.play_sfx(35);
|
||||
}
|
||||
}
|
||||
|
@ -397,30 +377,27 @@ impl BossNPC {
|
|||
self.parts[i].y = self.parts[0].y;
|
||||
|
||||
match i {
|
||||
3 => self.parts[i].x = self.parts[0].x - 16 * 0x200,
|
||||
4 => self.parts[i].x = self.parts[0].x + 16 * 0x200,
|
||||
3 => self.parts[i].x = self.parts[0].x - 0x2000,
|
||||
4 => self.parts[i].x = self.parts[0].x + 0x2000,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
3 => {
|
||||
self.parts[i].target_y = self.parts[0].y + 24 * 0x200;
|
||||
self.parts[i].target_y = self.parts[0].y + 0x3000;
|
||||
|
||||
match i {
|
||||
3 => self.parts[i].x = self.parts[0].x - 16 * 0x200,
|
||||
4 => self.parts[i].x = self.parts[0].x + 16 * 0x200,
|
||||
3 => self.parts[i].x = self.parts[0].x - 0x2000,
|
||||
4 => self.parts[i].x = self.parts[0].x + 0x2000,
|
||||
_ => {}
|
||||
}
|
||||
|
||||
self.parts[i].y += (self.parts[0].target_y - self.parts[0].y) / 2;
|
||||
self.parts[i].y += (self.parts[i].target_y - self.parts[i].y) / 2;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if self.parts[i].flags.hit_bottom_wall() || self.parts[i].y <= self.parts[i].target_y {
|
||||
self.parts[i].anim_num = 0;
|
||||
} else {
|
||||
self.parts[i].anim_num = 1;
|
||||
}
|
||||
self.parts[i].anim_num =
|
||||
if !self.parts[i].flags.hit_bottom_wall() && self.parts[i].y > self.parts[i].target_y { 1 } else { 0 };
|
||||
|
||||
let dir_offset = if self.parts[i].direction == Direction::Left { 0 } else { 2 };
|
||||
|
||||
|
@ -429,7 +406,7 @@ impl BossNPC {
|
|||
|
||||
for &i in [1, 2].iter() {
|
||||
self.parts[i].x = self.parts[0].x + self.parts[i].direction.vector_x() * 16 * 0x200;
|
||||
self.parts[i].y = (self.parts[0].y + self.parts[i + 2].y - 8 * 0x200) / 2;
|
||||
self.parts[i].y = (self.parts[0].y + self.parts[i + 2].y - 0x1000) / 2;
|
||||
|
||||
let dir_offset = if self.parts[i].direction == Direction::Left { 0 } else { 1 };
|
||||
|
||||
|
@ -440,12 +417,8 @@ impl BossNPC {
|
|||
self.parts[5].action_num = 1;
|
||||
self.parts[5].npc_flags.set_solid_soft(true);
|
||||
self.parts[5].npc_flags.set_ignore_solidity(true);
|
||||
self.parts[5].hit_bounds = Rect {
|
||||
left: 20 * 0x200,
|
||||
top: 36 * 0x200,
|
||||
right: 20 * 0x200,
|
||||
bottom: 16 * 0x200,
|
||||
};
|
||||
self.parts[5].hit_bounds =
|
||||
Rect { left: 20 * 0x200, top: 36 * 0x200, right: 20 * 0x200, bottom: 16 * 0x200 };
|
||||
}
|
||||
|
||||
self.parts[5].x = self.parts[0].x;
|
||||
|
|
|
@ -140,7 +140,7 @@ impl NPC {
|
|||
}
|
||||
|
||||
impl GameEntity<([&mut Player; 2], &NPCList, &mut Stage, &BulletManager)> for NPC {
|
||||
fn tick(&mut self, state: &mut SharedGameState, (players, npc_list, stage, _bullet_manager): ([&mut Player; 2], &NPCList, &mut Stage, &BulletManager)) -> GameResult {
|
||||
fn tick(&mut self, state: &mut SharedGameState, (players, npc_list, stage, bullet_manager): ([&mut Player; 2], &NPCList, &mut Stage, &BulletManager)) -> GameResult {
|
||||
match self.npc_type {
|
||||
0 => self.tick_n000_null(),
|
||||
1 => self.tick_n001_experience(state),
|
||||
|
@ -256,6 +256,8 @@ impl GameEntity<([&mut Player; 2], &NPCList, &mut Stage, &BulletManager)> for NP
|
|||
113 => self.tick_n113_professor_booster(state),
|
||||
114 => self.tick_n114_press(state, players, npc_list),
|
||||
116 => self.tick_n116_red_petals(state),
|
||||
117 => self.tick_n117_curly(state, players, npc_list),
|
||||
118 => self.tick_n118_curly_boss(state, players, npc_list, bullet_manager),
|
||||
119 => self.tick_n119_table_chair(state),
|
||||
120 => self.tick_n120_colon_a(state),
|
||||
124 => self.tick_n124_sunstone(state),
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use log::info;
|
||||
use num_traits::{abs, clamp};
|
||||
|
||||
use crate::weapon::bullet::BulletManager;
|
||||
use crate::caret::CaretType;
|
||||
use crate::common::{fix9_scale, interpolate_fix9_scale, Color, Direction, FadeDirection, FadeState, Rect};
|
||||
use crate::components::boss_life_bar::BossLifeBar;
|
||||
use crate::components::draw_common::{draw_number, Alignment};
|
||||
use crate::components::flash::Flash;
|
||||
use crate::components::hud::HUD;
|
||||
use crate::components::stage_select::StageSelect;
|
||||
use crate::entity::GameEntity;
|
||||
|
@ -30,6 +30,7 @@ use crate::shared_game_state::{Season, SharedGameState};
|
|||
use crate::stage::{BackgroundType, Stage};
|
||||
use crate::text_script::{ConfirmSelection, ScriptMode, TextScriptExecutionState, TextScriptLine, TextScriptVM};
|
||||
use crate::texture_set::SizedBatch;
|
||||
use crate::weapon::bullet::BulletManager;
|
||||
use crate::weapon::WeaponType;
|
||||
|
||||
pub struct GameScene {
|
||||
|
@ -37,6 +38,7 @@ pub struct GameScene {
|
|||
pub stage: Stage,
|
||||
pub boss_life_bar: BossLifeBar,
|
||||
pub stage_select: StageSelect,
|
||||
pub flash: Flash,
|
||||
pub hud_player1: HUD,
|
||||
pub hud_player2: HUD,
|
||||
pub frame: Frame,
|
||||
|
@ -86,6 +88,7 @@ impl GameScene {
|
|||
inventory_player2: Inventory::new(),
|
||||
boss_life_bar: BossLifeBar::new(),
|
||||
stage_select: StageSelect::new(),
|
||||
flash: Flash::new(),
|
||||
hud_player1: HUD::new(Alignment::Left),
|
||||
hud_player2: HUD::new(Alignment::Right),
|
||||
frame: Frame {
|
||||
|
@ -1104,7 +1107,13 @@ impl GameScene {
|
|||
}
|
||||
self.boss.tick(
|
||||
state,
|
||||
([&mut self.player1, &mut self.player2], &self.npc_list, &mut self.stage, &self.bullet_manager),
|
||||
(
|
||||
[&mut self.player1, &mut self.player2],
|
||||
&self.npc_list,
|
||||
&mut self.stage,
|
||||
&self.bullet_manager,
|
||||
&mut self.flash,
|
||||
),
|
||||
)?;
|
||||
|
||||
self.player1.tick_map_collisions(state, &self.npc_list, &mut self.stage);
|
||||
|
@ -1365,12 +1374,15 @@ impl Scene for GameScene {
|
|||
_ => {}
|
||||
}
|
||||
|
||||
self.flash.tick(state, ())?;
|
||||
TextScriptVM::run(state, self, ctx)?;
|
||||
|
||||
#[cfg(feature = "scripting")]
|
||||
state.lua.scene_tick(self);
|
||||
|
||||
self.tick = self.tick.wrapping_add(1);
|
||||
if state.control_flags.control_enabled() {
|
||||
self.tick = self.tick.wrapping_add(1);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1458,6 +1470,7 @@ impl Scene for GameScene {
|
|||
{
|
||||
self.draw_light_map(state, ctx)?;
|
||||
}
|
||||
self.flash.draw(state, ctx, &self.frame)?;
|
||||
|
||||
/*graphics::set_canvas(ctx, None);
|
||||
state.game_canvas.draw(ctx, DrawParam::new()
|
||||
|
|
142
src/sound/mod.rs
142
src/sound/mod.rs
|
@ -2,24 +2,24 @@ use std::sync::mpsc;
|
|||
use std::sync::mpsc::{Receiver, Sender};
|
||||
use std::time::Duration;
|
||||
|
||||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||
use cpal::Sample;
|
||||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||
use lewton::inside_ogg::OggStreamReader;
|
||||
use num_traits::clamp;
|
||||
|
||||
use crate::engine_constants::EngineConstants;
|
||||
use crate::framework::context::Context;
|
||||
use crate::framework::error::GameError::{AudioError, InvalidValue};
|
||||
use crate::framework::error::{GameError, GameResult};
|
||||
use crate::framework::error::GameError::{AudioError, InvalidValue};
|
||||
use crate::framework::filesystem;
|
||||
use crate::framework::filesystem::File;
|
||||
use crate::settings::Settings;
|
||||
use crate::sound::ogg_playback::{OggPlaybackEngine, SavedOggPlaybackState};
|
||||
use crate::sound::org_playback::{OrgPlaybackEngine, SavedOrganyaPlaybackState};
|
||||
use crate::sound::organya::Song;
|
||||
use crate::sound::pixtone::PixTonePlayback;
|
||||
use crate::sound::wave_bank::SoundBank;
|
||||
use crate::str;
|
||||
use crate::settings::Settings;
|
||||
|
||||
mod ogg_playback;
|
||||
mod org_playback;
|
||||
|
@ -47,15 +47,10 @@ impl SoundManager {
|
|||
let (tx, rx): (Sender<PlaybackMessage>, Receiver<PlaybackMessage>) = mpsc::channel();
|
||||
|
||||
let host = cpal::default_host();
|
||||
let device = host
|
||||
.default_output_device()
|
||||
.ok_or_else(|| AudioError(str!("Error initializing audio device.")))?;
|
||||
let device = host.default_output_device().ok_or_else(|| AudioError(str!("Error initializing audio device.")))?;
|
||||
let config = device.default_output_config()?;
|
||||
|
||||
let bnk = wave_bank::SoundBank::load_from(filesystem::open(
|
||||
ctx,
|
||||
"/builtin/organya-wavetable-doukutsu.bin",
|
||||
)?)?;
|
||||
let bnk = wave_bank::SoundBank::load_from(filesystem::open(ctx, "/builtin/organya-wavetable-doukutsu.bin")?)?;
|
||||
|
||||
std::thread::spawn(move || {
|
||||
if let Err(err) = match config.sample_format() {
|
||||
|
@ -67,24 +62,14 @@ impl SoundManager {
|
|||
}
|
||||
});
|
||||
|
||||
Ok(SoundManager {
|
||||
tx: tx.clone(),
|
||||
prev_song_id: 0,
|
||||
current_song_id: 0,
|
||||
})
|
||||
Ok(SoundManager { tx: tx.clone(), prev_song_id: 0, current_song_id: 0 })
|
||||
}
|
||||
|
||||
pub fn play_sfx(&mut self, id: u8) {
|
||||
let _ = self.tx.send(PlaybackMessage::PlaySample(id));
|
||||
}
|
||||
|
||||
pub fn play_song(
|
||||
&mut self,
|
||||
song_id: usize,
|
||||
constants: &EngineConstants,
|
||||
settings: &Settings,
|
||||
ctx: &mut Context,
|
||||
) -> GameResult {
|
||||
pub fn play_song(&mut self, song_id: usize, constants: &EngineConstants, settings: &Settings, ctx: &mut Context) -> GameResult {
|
||||
if self.current_song_id == song_id {
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -100,35 +85,22 @@ impl SoundManager {
|
|||
} else if let Some(song_name) = constants.music_table.get(song_id) {
|
||||
let mut paths = constants.organya_paths.clone();
|
||||
|
||||
paths.insert(0, "/Soundtracks/".to_owned() + &settings.soundtrack + "/");
|
||||
|
||||
if let Some(soundtrack) = constants.soundtracks.get(&settings.soundtrack) {
|
||||
paths.insert(0, soundtrack.clone());
|
||||
}
|
||||
|
||||
let songs_paths = paths.iter().map(|prefix| {
|
||||
[
|
||||
(
|
||||
SongFormat::OggMultiPart,
|
||||
vec![
|
||||
format!("{}{}_intro.ogg", prefix, song_name),
|
||||
format!("{}{}_loop.ogg", prefix, song_name),
|
||||
],
|
||||
),
|
||||
(
|
||||
SongFormat::OggSinglePart,
|
||||
vec![format!("{}{}.ogg", prefix, song_name)],
|
||||
),
|
||||
(
|
||||
SongFormat::Organya,
|
||||
vec![format!("{}{}.org", prefix, song_name)],
|
||||
),
|
||||
(SongFormat::OggMultiPart, vec![format!("{}{}_intro.ogg", prefix, song_name), format!("{}{}_loop.ogg", prefix, song_name)]),
|
||||
(SongFormat::OggSinglePart, vec![format!("{}{}.ogg", prefix, song_name)]),
|
||||
(SongFormat::Organya, vec![format!("{}{}.org", prefix, song_name)]),
|
||||
]
|
||||
});
|
||||
|
||||
for songs in songs_paths {
|
||||
for (format, paths) in songs
|
||||
.iter()
|
||||
.filter(|(_, paths)| paths.iter().all(|path| filesystem::exists(ctx, path)))
|
||||
{
|
||||
for (format, paths) in songs.iter().filter(|(_, paths)| paths.iter().all(|path| filesystem::exists(ctx, path))) {
|
||||
match format {
|
||||
SongFormat::Organya => {
|
||||
// we're sure that there's one element
|
||||
|
@ -141,8 +113,7 @@ impl SoundManager {
|
|||
self.prev_song_id = self.current_song_id;
|
||||
self.current_song_id = song_id;
|
||||
self.tx.send(PlaybackMessage::SaveState)?;
|
||||
self.tx
|
||||
.send(PlaybackMessage::PlayOrganyaSong(Box::new(org)))?;
|
||||
self.tx.send(PlaybackMessage::PlayOrganyaSong(Box::new(org)))?;
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -155,28 +126,19 @@ impl SoundManager {
|
|||
// we're sure that there's one element
|
||||
let path = unsafe { paths.get_unchecked(0) };
|
||||
|
||||
match filesystem::open(ctx, path).map(|f| {
|
||||
OggStreamReader::new(f)
|
||||
.map_err(|e| GameError::ResourceLoadError(e.to_string()))
|
||||
}) {
|
||||
match filesystem::open(ctx, path).map(|f| OggStreamReader::new(f).map_err(|e| GameError::ResourceLoadError(e.to_string()))) {
|
||||
Ok(Ok(song)) => {
|
||||
log::info!("Playing single part Ogg BGM: {} {}", song_id, path);
|
||||
|
||||
self.prev_song_id = self.current_song_id;
|
||||
self.current_song_id = song_id;
|
||||
self.tx.send(PlaybackMessage::SaveState)?;
|
||||
self.tx.send(PlaybackMessage::PlayOggSongSinglePart(
|
||||
Box::new(song),
|
||||
))?;
|
||||
self.tx.send(PlaybackMessage::PlayOggSongSinglePart(Box::new(song)))?;
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
Ok(Err(err)) | Err(err) => {
|
||||
log::warn!(
|
||||
"Failed to load single part Ogg BGM {}: {}",
|
||||
song_id,
|
||||
err
|
||||
);
|
||||
log::warn!("Failed to load single part Ogg BGM {}: {}", song_id, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -186,42 +148,21 @@ impl SoundManager {
|
|||
let path_loop = unsafe { paths.get_unchecked(1) };
|
||||
|
||||
match (
|
||||
filesystem::open(ctx, path_intro).map(|f| {
|
||||
OggStreamReader::new(f)
|
||||
.map_err(|e| GameError::ResourceLoadError(e.to_string()))
|
||||
}),
|
||||
filesystem::open(ctx, path_loop).map(|f| {
|
||||
OggStreamReader::new(f)
|
||||
.map_err(|e| GameError::ResourceLoadError(e.to_string()))
|
||||
}),
|
||||
filesystem::open(ctx, path_intro).map(|f| OggStreamReader::new(f).map_err(|e| GameError::ResourceLoadError(e.to_string()))),
|
||||
filesystem::open(ctx, path_loop).map(|f| OggStreamReader::new(f).map_err(|e| GameError::ResourceLoadError(e.to_string()))),
|
||||
) {
|
||||
(Ok(Ok(song_intro)), Ok(Ok(song_loop))) => {
|
||||
log::info!(
|
||||
"Playing multi part Ogg BGM: {} {} + {}",
|
||||
song_id,
|
||||
path_intro,
|
||||
path_loop
|
||||
);
|
||||
log::info!("Playing multi part Ogg BGM: {} {} + {}", song_id, path_intro, path_loop);
|
||||
|
||||
self.prev_song_id = self.current_song_id;
|
||||
self.current_song_id = song_id;
|
||||
self.tx.send(PlaybackMessage::SaveState)?;
|
||||
self.tx.send(PlaybackMessage::PlayOggSongMultiPart(
|
||||
Box::new(song_intro),
|
||||
Box::new(song_loop),
|
||||
))?;
|
||||
self.tx.send(PlaybackMessage::PlayOggSongMultiPart(Box::new(song_intro), Box::new(song_loop)))?;
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
(Ok(Err(err)), _)
|
||||
| (Err(err), _)
|
||||
| (_, Ok(Err(err)))
|
||||
| (_, Err(err)) => {
|
||||
log::warn!(
|
||||
"Failed to load multi part Ogg BGM {}: {}",
|
||||
song_id,
|
||||
err
|
||||
);
|
||||
(Ok(Err(err)), _) | (Err(err), _) | (_, Ok(Err(err))) | (_, Err(err)) => {
|
||||
log::warn!("Failed to load multi part Ogg BGM {}: {}", song_id, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -285,12 +226,7 @@ enum PlaybackStateType {
|
|||
Ogg(SavedOggPlaybackState),
|
||||
}
|
||||
|
||||
fn run<T>(
|
||||
rx: Receiver<PlaybackMessage>,
|
||||
bank: SoundBank,
|
||||
device: &cpal::Device,
|
||||
config: &cpal::StreamConfig,
|
||||
) -> GameResult
|
||||
fn run<T>(rx: Receiver<PlaybackMessage>, bank: SoundBank, device: &cpal::Device, config: &cpal::StreamConfig) -> GameResult
|
||||
where
|
||||
T: cpal::Sample,
|
||||
{
|
||||
|
@ -388,12 +324,8 @@ where
|
|||
Ok(PlaybackMessage::SaveState) => {
|
||||
saved_state = match state {
|
||||
PlaybackState::Stopped => PlaybackStateType::None,
|
||||
PlaybackState::PlayingOrg => {
|
||||
PlaybackStateType::Organya(org_engine.get_state())
|
||||
}
|
||||
PlaybackState::PlayingOgg => {
|
||||
PlaybackStateType::Ogg(ogg_engine.get_state())
|
||||
}
|
||||
PlaybackState::PlayingOrg => PlaybackStateType::Organya(org_engine.get_state()),
|
||||
PlaybackState::PlayingOgg => PlaybackStateType::Ogg(ogg_engine.get_state()),
|
||||
};
|
||||
}
|
||||
Ok(PlaybackMessage::RestoreState) => {
|
||||
|
@ -493,28 +425,16 @@ where
|
|||
}
|
||||
|
||||
if frame.len() >= 2 {
|
||||
let sample_l = clamp(
|
||||
(((bgm_sample_l ^ 0x8000) as i16) as isize)
|
||||
+ (((pxt_sample ^ 0x8000) as i16) as isize),
|
||||
-0x7fff,
|
||||
0x7fff,
|
||||
) as u16
|
||||
^ 0x8000;
|
||||
let sample_r = clamp(
|
||||
(((bgm_sample_r ^ 0x8000) as i16) as isize)
|
||||
+ (((pxt_sample ^ 0x8000) as i16) as isize),
|
||||
-0x7fff,
|
||||
0x7fff,
|
||||
) as u16
|
||||
^ 0x8000;
|
||||
let sample_l =
|
||||
clamp((((bgm_sample_l ^ 0x8000) as i16) as isize) + (((pxt_sample ^ 0x8000) as i16) as isize), -0x7fff, 0x7fff) as u16 ^ 0x8000;
|
||||
let sample_r =
|
||||
clamp((((bgm_sample_r ^ 0x8000) as i16) as isize) + (((pxt_sample ^ 0x8000) as i16) as isize), -0x7fff, 0x7fff) as u16 ^ 0x8000;
|
||||
|
||||
frame[0] = Sample::from::<u16>(&sample_l);
|
||||
frame[1] = Sample::from::<u16>(&sample_r);
|
||||
} else {
|
||||
let sample = clamp(
|
||||
((((bgm_sample_l ^ 0x8000) as i16) + ((bgm_sample_r ^ 0x8000) as i16)) / 2)
|
||||
as isize
|
||||
+ (((pxt_sample ^ 0x8000) as i16) as isize),
|
||||
((((bgm_sample_l ^ 0x8000) as i16) + ((bgm_sample_r ^ 0x8000) as i16)) / 2) as isize + (((pxt_sample ^ 0x8000) as i16) as isize),
|
||||
-0x7fff,
|
||||
0x7fff,
|
||||
) as u16
|
||||
|
|
|
@ -1544,6 +1544,11 @@ impl TextScriptVM {
|
|||
|
||||
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
|
||||
}
|
||||
OpCode::FLA => {
|
||||
game_scene.flash.set_blink();
|
||||
|
||||
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
|
||||
}
|
||||
OpCode::INI => {
|
||||
exec_state = TextScriptExecutionState::Reset;
|
||||
}
|
||||
|
@ -1572,7 +1577,6 @@ impl TextScriptVM {
|
|||
| OpCode::KE2
|
||||
| OpCode::CRE
|
||||
| OpCode::CSS
|
||||
| OpCode::FLA
|
||||
| OpCode::MLP
|
||||
| OpCode::SPS
|
||||
| OpCode::FR2
|
||||
|
|
|
@ -76,6 +76,7 @@ impl BulletManager {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Bullet {
|
||||
pub btype: u16,
|
||||
pub x: i32,
|
||||
|
@ -90,6 +91,7 @@ pub struct Bullet {
|
|||
pub lifetime: u16,
|
||||
pub damage: i16,
|
||||
pub counter1: u16,
|
||||
pub counter2: u16,
|
||||
pub rng: Xoroshiro32PlusPlus,
|
||||
pub owner: TargetPlayer,
|
||||
pub cond: Condition,
|
||||
|
@ -135,6 +137,7 @@ impl Bullet {
|
|||
lifetime: bullet.lifetime,
|
||||
damage: bullet.damage as i16,
|
||||
counter1: 0,
|
||||
counter2: 0,
|
||||
rng: Xoroshiro32PlusPlus::new(1),
|
||||
owner,
|
||||
cond: Condition(0x80),
|
||||
|
@ -668,25 +671,25 @@ impl Bullet {
|
|||
return;
|
||||
}
|
||||
|
||||
if self.action_counter == 0 {
|
||||
self.action_counter = 1;
|
||||
if self.action_num == 0 {
|
||||
self.action_num = 1;
|
||||
|
||||
match self.direction {
|
||||
Direction::Left => {
|
||||
self.vel_x = self.rng.range(-0x400..-0x200);
|
||||
self.vel_y = self.rng.range(-4..4) * 0x200 / 2;
|
||||
self.vel_y = (self.rng.range(-4..4) * 0x200) / 2;
|
||||
}
|
||||
Direction::Up => {
|
||||
self.vel_y = self.rng.range(-0x400..-0x200);
|
||||
self.vel_x = self.rng.range(-4..4) * 0x200 / 2;
|
||||
self.vel_x = (self.rng.range(-4..4) * 0x200) / 2;
|
||||
}
|
||||
Direction::Right => {
|
||||
self.vel_x = self.rng.range(0x200..0x400);
|
||||
self.vel_y = self.rng.range(-4..4) * 0x200 / 2;
|
||||
self.vel_y = (self.rng.range(-4..4) * 0x200) / 2;
|
||||
}
|
||||
Direction::Bottom => {
|
||||
self.vel_y = self.rng.range(0x80..0x100);
|
||||
self.vel_x = self.rng.range(-4..4) * 0x200 / 2;
|
||||
self.vel_x = (self.rng.range(-4..4) * 0x200) / 2;
|
||||
}
|
||||
Direction::FacingPlayer => unreachable!(),
|
||||
}
|
||||
|
@ -987,6 +990,178 @@ impl Bullet {
|
|||
}
|
||||
}
|
||||
|
||||
fn tick_super_missile(&mut self, state: &mut SharedGameState, players: [&Player; 2], new_bullets: &mut Vec<Bullet>) {
|
||||
let player = players[self.owner.index()];
|
||||
|
||||
self.action_counter += 1;
|
||||
if self.action_counter > self.lifetime {
|
||||
self.cond.set_alive(false);
|
||||
state.create_caret(self.x, self.y, CaretType::Shoot, Direction::Left);
|
||||
return;
|
||||
}
|
||||
|
||||
if match self.direction {
|
||||
Direction::Left if self.flags.hit_left_wall() => true,
|
||||
Direction::Left if self.flags.hit_left_slope() => true,
|
||||
Direction::Left if self.flags.flag_x80() => true,
|
||||
Direction::Right if self.flags.hit_right_wall() => true,
|
||||
Direction::Right if self.flags.hit_right_slope() => true,
|
||||
Direction::Right if self.flags.flag_x40() => true,
|
||||
Direction::Up if self.flags.hit_top_wall() => true,
|
||||
Direction::Bottom if self.flags.hit_bottom_wall() => true,
|
||||
_ => false,
|
||||
} {
|
||||
let bomb_bullet = match self.btype {
|
||||
28 => 31,
|
||||
29 => 32,
|
||||
30 => 33,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let bullet = Bullet::new(self.x, self.y, bomb_bullet, self.owner, self.direction, &state.constants);
|
||||
new_bullets.push(bullet);
|
||||
|
||||
self.cond.set_alive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if self.action_num == 0 {
|
||||
self.action_num = 1;
|
||||
|
||||
match self.direction {
|
||||
Direction::Left | Direction::Right => {
|
||||
self.target_y = self.y;
|
||||
self.enemy_hit_height = 0x1000;
|
||||
self.hit_bounds.top = 0x1000;
|
||||
self.hit_bounds.bottom = 0x1000;
|
||||
}
|
||||
Direction::Up | Direction::Bottom => {
|
||||
self.target_x = self.x;
|
||||
self.enemy_hit_width = 0x1000;
|
||||
self.hit_bounds.left = 0x1000;
|
||||
self.hit_bounds.right = 0x1000;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if self.btype == 30 {
|
||||
match self.direction {
|
||||
Direction::Left | Direction::Right => {
|
||||
self.vel_y = (self.y - player.y).signum() * 0x100;
|
||||
self.vel_x = self.rng.range(-0x200..0x200);
|
||||
}
|
||||
Direction::Up | Direction::Bottom => {
|
||||
self.vel_x = (self.x - player.x).signum() * 0x100;
|
||||
self.vel_y = self.rng.range(-0x200..0x200);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
self.counter1 = match self.counter1 {
|
||||
1 => 256,
|
||||
2 => 170,
|
||||
_ => 512,
|
||||
};
|
||||
}
|
||||
|
||||
match self.direction {
|
||||
Direction::Left => self.vel_x -= self.counter1 as i32,
|
||||
Direction::Up => self.vel_y -= self.counter1 as i32,
|
||||
Direction::Right => self.vel_x += self.counter1 as i32,
|
||||
Direction::Bottom => self.vel_y += self.counter1 as i32,
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if self.btype == 30 {
|
||||
match self.direction {
|
||||
Direction::Left | Direction::Right => {
|
||||
self.vel_y = (player.y - self.y).signum() * 0x40;
|
||||
}
|
||||
Direction::Up | Direction::Bottom => {
|
||||
self.vel_x = (player.x - self.x).signum() * 0x40;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
self.vel_x = clamp(self.vel_x, -0x1400, 0x1400);
|
||||
self.vel_y = clamp(self.vel_y, -0x1400, 0x1400);
|
||||
|
||||
self.x += self.vel_x;
|
||||
self.y += self.vel_y;
|
||||
|
||||
self.counter2 += 1;
|
||||
|
||||
if self.counter2 > 2 {
|
||||
self.counter2 = 0;
|
||||
|
||||
match self.direction {
|
||||
Direction::Left => {
|
||||
state.create_caret(self.x + 0x1000, self.y, CaretType::Exhaust, self.direction.opposite());
|
||||
}
|
||||
Direction::Up => {
|
||||
state.create_caret(self.x, self.y + 0x1000, CaretType::Exhaust, self.direction.opposite());
|
||||
}
|
||||
Direction::Right => {
|
||||
state.create_caret(self.x - 0x1000, self.y, CaretType::Exhaust, self.direction.opposite());
|
||||
}
|
||||
Direction::Bottom => {
|
||||
state.create_caret(self.x, self.y - 0x1000, CaretType::Exhaust, self.direction.opposite());
|
||||
}
|
||||
Direction::FacingPlayer => {}
|
||||
}
|
||||
}
|
||||
|
||||
match self.btype {
|
||||
28 | 30 => {
|
||||
self.anim_rect = state.constants.weapon.bullet_rects.b028_super_missile_l1[self.direction as usize];
|
||||
}
|
||||
29 => {
|
||||
self.anim_rect = state.constants.weapon.bullet_rects.b029_super_missile_l2[self.direction as usize];
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn tick_super_missile_explosion(&mut self, state: &mut SharedGameState, npc_list: &NPCList) {
|
||||
if self.action_num == 0 {
|
||||
self.action_num = 1;
|
||||
|
||||
self.action_counter = match self.btype {
|
||||
31 => 10,
|
||||
32 => 14,
|
||||
33 => 6,
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
state.sound_manager.play_sfx(44);
|
||||
}
|
||||
|
||||
if self.action_counter % 3 == 0 {
|
||||
let radius = match self.btype {
|
||||
31 => 16,
|
||||
32 => 32,
|
||||
33 => 40,
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
npc_list.create_death_smoke_up(
|
||||
self.x + self.rng.range(-radius..radius) * 0x200,
|
||||
self.y + self.rng.range(-radius..radius) * 0x200,
|
||||
self.enemy_hit_width as usize,
|
||||
2,
|
||||
state,
|
||||
&self.rng,
|
||||
);
|
||||
}
|
||||
|
||||
self.action_counter -= 1;
|
||||
if self.action_counter == 0 {
|
||||
self.cond.set_alive(false);
|
||||
}
|
||||
}
|
||||
|
||||
fn tick_nemesis(&mut self, state: &mut SharedGameState, npc_list: &NPCList) {
|
||||
self.action_counter += 1;
|
||||
if self.action_counter > self.lifetime {
|
||||
|
@ -1214,6 +1389,8 @@ impl Bullet {
|
|||
25 => self.tick_blade_1(state),
|
||||
26 => self.tick_blade_2(state),
|
||||
27 => self.tick_blade_3(state, new_bullets),
|
||||
28 | 29 | 30 => self.tick_super_missile(state, players, new_bullets),
|
||||
31 | 32 | 33 => self.tick_super_missile_explosion(state, npc_list),
|
||||
34 | 35 | 36 => self.tick_nemesis(state, npc_list),
|
||||
37 | 38 | 39 => self.tick_spur(state, new_bullets),
|
||||
40 | 41 | 42 => self.tick_spur_trail(state),
|
||||
|
|
|
@ -2,8 +2,8 @@ use crate::caret::CaretType;
|
|||
use crate::common::Direction;
|
||||
use crate::player::{Player, TargetPlayer};
|
||||
use crate::shared_game_state::SharedGameState;
|
||||
use crate::weapon::{Weapon, WeaponLevel};
|
||||
use crate::weapon::bullet::BulletManager;
|
||||
use crate::weapon::{Weapon, WeaponLevel};
|
||||
|
||||
impl Weapon {
|
||||
pub(in crate::weapon) fn tick_fireball(
|
||||
|
@ -14,60 +14,52 @@ impl Weapon {
|
|||
state: &mut SharedGameState,
|
||||
) {
|
||||
let max_bullets = self.level as usize + 1;
|
||||
if player.controller.trigger_shoot() && bullet_manager.count_bullets_multi(&[7, 8, 9], player_id) < max_bullets {
|
||||
let btype = match self.level {
|
||||
WeaponLevel::Level1 => 7,
|
||||
WeaponLevel::Level2 => 8,
|
||||
WeaponLevel::Level3 => 9,
|
||||
WeaponLevel::None => {
|
||||
unreachable!()
|
||||
}
|
||||
};
|
||||
|
||||
if !self.consume_ammo(1) {
|
||||
// todo switch to first weapon
|
||||
return;
|
||||
}
|
||||
|
||||
if player.up {
|
||||
match player.direction {
|
||||
Direction::Left => {
|
||||
bullet_manager.create_bullet(player.x - 0x800, player.y - 0x1000, btype, player_id, Direction::Up, &state.constants);
|
||||
state.create_caret(player.x - 0x800, player.y - 0x1000, CaretType::Shoot, Direction::Left);
|
||||
}
|
||||
Direction::Right => {
|
||||
bullet_manager.create_bullet(player.x + 0x800, player.y - 0x1000, btype, player_id, Direction::Up, &state.constants);
|
||||
state.create_caret(player.x + 0x800, player.y - 0x1000, CaretType::Shoot, Direction::Left);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
} else if player.down {
|
||||
match player.direction {
|
||||
Direction::Left => {
|
||||
bullet_manager.create_bullet(player.x - 0x800, player.y + 0x1000, btype, player_id, Direction::Bottom, &state.constants);
|
||||
state.create_caret(player.x - 0x800, player.y + 0x1000, CaretType::Shoot, Direction::Left);
|
||||
}
|
||||
Direction::Right => {
|
||||
bullet_manager.create_bullet(player.x + 0x800, player.y + 0x1000, btype, player_id, Direction::Bottom, &state.constants);
|
||||
state.create_caret(player.x + 0x800, player.y + 0x1000, CaretType::Shoot, Direction::Left);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
} else {
|
||||
match player.direction {
|
||||
Direction::Left => {
|
||||
bullet_manager.create_bullet(player.x - 0xc00, player.y + 0x400, btype, player_id, Direction::Left, &state.constants);
|
||||
state.create_caret(player.x - 0x1800, player.y + 0x400, CaretType::Shoot, Direction::Left);
|
||||
}
|
||||
Direction::Right => {
|
||||
bullet_manager.create_bullet(player.x + 0xc00, player.y + 0x400, btype, player_id, Direction::Right, &state.constants);
|
||||
state.create_caret(player.x + 0x1800, player.y + 0x400, CaretType::Shoot, Direction::Right);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
state.sound_manager.play_sfx(34)
|
||||
if !player.controller.trigger_shoot() || bullet_manager.count_bullets_multi(&[7, 8, 9], player_id) >= max_bullets {
|
||||
return;
|
||||
}
|
||||
|
||||
let btype = match self.level {
|
||||
WeaponLevel::Level1 => 7,
|
||||
WeaponLevel::Level2 => 8,
|
||||
WeaponLevel::Level3 => 9,
|
||||
WeaponLevel::None => {
|
||||
unreachable!()
|
||||
}
|
||||
};
|
||||
|
||||
if !self.consume_ammo(1) {
|
||||
// todo switch to first weapon
|
||||
return;
|
||||
}
|
||||
|
||||
match player.direction {
|
||||
Direction::Left if player.up => {
|
||||
bullet_manager.create_bullet(player.x - 0x800, player.y - 0x1000, btype, player_id, Direction::Up, &state.constants);
|
||||
state.create_caret(player.x - 0x800, player.y - 0x1000, CaretType::Shoot, Direction::Left);
|
||||
}
|
||||
Direction::Right if player.up => {
|
||||
bullet_manager.create_bullet(player.x + 0x800, player.y - 0x1000, btype, player_id, Direction::Up, &state.constants);
|
||||
state.create_caret(player.x + 0x800, player.y - 0x1000, CaretType::Shoot, Direction::Left);
|
||||
}
|
||||
Direction::Left if player.down => {
|
||||
bullet_manager.create_bullet(player.x - 0x800, player.y + 0x1000, btype, player_id, Direction::Bottom, &state.constants);
|
||||
state.create_caret(player.x - 0x800, player.y + 0x1000, CaretType::Shoot, Direction::Left);
|
||||
}
|
||||
Direction::Right if player.down => {
|
||||
bullet_manager.create_bullet(player.x + 0x800, player.y + 0x1000, btype, player_id, Direction::Bottom, &state.constants);
|
||||
state.create_caret(player.x + 0x800, player.y + 0x1000, CaretType::Shoot, Direction::Left);
|
||||
}
|
||||
Direction::Left => {
|
||||
bullet_manager.create_bullet(player.x - 0xc00, player.y + 0x400, btype, player_id, Direction::Left, &state.constants);
|
||||
state.create_caret(player.x - 0x1800, player.y + 0x400, CaretType::Shoot, Direction::Left);
|
||||
}
|
||||
Direction::Right => {
|
||||
bullet_manager.create_bullet(player.x + 0xc00, player.y + 0x400, btype, player_id, Direction::Right, &state.constants);
|
||||
state.create_caret(player.x + 0x1800, player.y + 0x400, CaretType::Shoot, Direction::Right);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
state.sound_manager.play_sfx(34)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use crate::caret::CaretType;
|
||||
use crate::common::Direction;
|
||||
use crate::player::{Player, TargetPlayer};
|
||||
use crate::shared_game_state::SharedGameState;
|
||||
use crate::weapon::bullet::BulletManager;
|
||||
use crate::weapon::bullet::{Bullet, BulletManager};
|
||||
use crate::weapon::{Weapon, WeaponLevel};
|
||||
|
||||
impl Weapon {
|
||||
|
@ -12,12 +14,162 @@ impl Weapon {
|
|||
state: &mut SharedGameState,
|
||||
) {
|
||||
const BULLETS: [u16; 6] = [28, 29, 30, 31, 32, 33];
|
||||
|
||||
|
||||
if !player.controller.trigger_shoot() {
|
||||
return;
|
||||
}
|
||||
|
||||
let btype = match self.level {
|
||||
WeaponLevel::Level1 => 28,
|
||||
WeaponLevel::Level2 => 29,
|
||||
WeaponLevel::Level3 => 30,
|
||||
WeaponLevel::None => unreachable!(),
|
||||
};
|
||||
|
||||
match self.level {
|
||||
WeaponLevel::Level1 if bullet_manager.count_bullets_multi(&BULLETS, player_id) > 0 => {
|
||||
return;
|
||||
}
|
||||
WeaponLevel::Level2 if bullet_manager.count_bullets_multi(&BULLETS, player_id) > 1 => {
|
||||
return;
|
||||
}
|
||||
WeaponLevel::Level3 if bullet_manager.count_bullets_multi(&BULLETS, player_id) > 3 => {
|
||||
return;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if !self.consume_ammo(1) {
|
||||
state.sound_manager.play_sfx(37);
|
||||
// todo switch to first weapon
|
||||
return;
|
||||
}
|
||||
|
||||
fn increment(weapon: &mut Weapon, bullet: &mut Bullet) {
|
||||
weapon.counter2 = (weapon.counter2 + 1) % 3;
|
||||
bullet.counter1 = weapon.counter2;
|
||||
}
|
||||
|
||||
match player.direction {
|
||||
Direction::Left if player.up => {
|
||||
let mut bullet = Bullet::new(player.x - 0x200, player.y - 0x1000, btype, player_id, Direction::Up, &state.constants);
|
||||
increment(self, &mut bullet);
|
||||
|
||||
bullet_manager.push_bullet(bullet.clone());
|
||||
|
||||
state.create_caret(player.x - 0x200, player.y - 0x1000, CaretType::Shoot, Direction::Left);
|
||||
|
||||
if self.level == WeaponLevel::Level3 {
|
||||
bullet.x = player.x - 0x600;
|
||||
bullet.y = player.y;
|
||||
increment(self, &mut bullet);
|
||||
bullet_manager.push_bullet(bullet.clone());
|
||||
|
||||
bullet.x = player.x + 0x600;
|
||||
increment(self, &mut bullet);
|
||||
bullet_manager.push_bullet(bullet);
|
||||
}
|
||||
}
|
||||
Direction::Right if player.up => {
|
||||
let mut bullet = Bullet::new(player.x + 0x200, player.y - 0x1000, btype, player_id, Direction::Up, &state.constants);
|
||||
increment(self, &mut bullet);
|
||||
|
||||
bullet_manager.push_bullet(bullet.clone());
|
||||
|
||||
state.create_caret(player.x + 0x200, player.y - 0x1000, CaretType::Shoot, Direction::Left);
|
||||
|
||||
if self.level == WeaponLevel::Level3 {
|
||||
bullet.x = player.x - 0x600;
|
||||
bullet.y = player.y;
|
||||
increment(self, &mut bullet);
|
||||
bullet_manager.push_bullet(bullet.clone());
|
||||
|
||||
bullet.x = player.x + 0x600;
|
||||
increment(self, &mut bullet);
|
||||
bullet_manager.push_bullet(bullet);
|
||||
}
|
||||
}
|
||||
Direction::Left if player.down => {
|
||||
let mut bullet = Bullet::new(player.x - 0x200, player.y + 0x1000, btype, player_id, Direction::Bottom, &state.constants);
|
||||
increment(self, &mut bullet);
|
||||
|
||||
bullet_manager.push_bullet(bullet.clone());
|
||||
|
||||
state.create_caret(player.x - 0x200, player.y + 0x1000, CaretType::Shoot, Direction::Left);
|
||||
|
||||
if self.level == WeaponLevel::Level3 {
|
||||
bullet.x = player.x - 0x600;
|
||||
bullet.y = player.y;
|
||||
increment(self, &mut bullet);
|
||||
bullet_manager.push_bullet(bullet.clone());
|
||||
|
||||
bullet.x = player.x + 0x600;
|
||||
increment(self, &mut bullet);
|
||||
bullet_manager.push_bullet(bullet);
|
||||
}
|
||||
}
|
||||
Direction::Right if player.down => {
|
||||
let mut bullet = Bullet::new(player.x + 0x200, player.y + 0x1000, btype, player_id, Direction::Bottom, &state.constants);
|
||||
increment(self, &mut bullet);
|
||||
|
||||
bullet_manager.push_bullet(bullet.clone());
|
||||
|
||||
state.create_caret(player.x + 0x200, player.y + 0x1000, CaretType::Shoot, Direction::Left);
|
||||
|
||||
if self.level == WeaponLevel::Level3 {
|
||||
bullet.x = player.x - 0x600;
|
||||
bullet.y = player.y;
|
||||
increment(self, &mut bullet);
|
||||
bullet_manager.push_bullet(bullet.clone());
|
||||
|
||||
bullet.x = player.x + 0x600;
|
||||
increment(self, &mut bullet);
|
||||
bullet_manager.push_bullet(bullet);
|
||||
}
|
||||
}
|
||||
Direction::Left => {
|
||||
let mut bullet = Bullet::new(player.x - 0xc00, player.y, btype, player_id, Direction::Left, &state.constants);
|
||||
increment(self, &mut bullet);
|
||||
|
||||
bullet_manager.push_bullet(bullet.clone());
|
||||
|
||||
state.create_caret(player.x - 0x1800, player.y, CaretType::Shoot, Direction::Left);
|
||||
|
||||
if self.level == WeaponLevel::Level3 {
|
||||
bullet.x = player.x;
|
||||
bullet.y = player.y - 0x1000;
|
||||
increment(self, &mut bullet);
|
||||
bullet_manager.push_bullet(bullet.clone());
|
||||
|
||||
bullet.x = player.x - 0x800;
|
||||
bullet.y = player.y - 0x200;
|
||||
increment(self, &mut bullet);
|
||||
bullet_manager.push_bullet(bullet);
|
||||
}
|
||||
}
|
||||
Direction::Right => {
|
||||
let mut bullet = Bullet::new(player.x + 0xc00, player.y, btype, player_id, Direction::Right, &state.constants);
|
||||
increment(self, &mut bullet);
|
||||
|
||||
bullet_manager.push_bullet(bullet.clone());
|
||||
|
||||
state.create_caret(player.x + 0x1800, player.y, CaretType::Shoot, Direction::Left);
|
||||
|
||||
if self.level == WeaponLevel::Level3 {
|
||||
bullet.x = player.x;
|
||||
bullet.y = player.y - 0x1000;
|
||||
increment(self, &mut bullet);
|
||||
bullet_manager.push_bullet(bullet.clone());
|
||||
|
||||
bullet.x = player.x + 0x800;
|
||||
bullet.y = player.y - 0x200;
|
||||
increment(self, &mut bullet);
|
||||
bullet_manager.push_bullet(bullet);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
state.sound_manager.play_sfx(32)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue