1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2024-11-22 05:33:02 +00:00

Fixed order of operations for bullets (Fixes #131)

This commit is contained in:
dawnDus 2022-08-20 18:43:48 -04:00
parent 59da01b7b9
commit 92bc887663
No known key found for this signature in database
GPG key ID: 972AABDE81848F21
3 changed files with 36 additions and 33 deletions

View file

@ -778,27 +778,26 @@ impl NPC {
npc.x = self.x + 0x800;
npc.y = self.y;
// Same as Egg Corridor? Bomb
match self.action_counter {
0 => {
npc.tsc_direction = 0;
let _ = npc_list.spawn(0x100, npc);
let _ = npc_list.spawn(0x180, npc);
}
50 => {
npc.tsc_direction = 1;
let _ = npc_list.spawn(0x100, npc);
let _ = npc_list.spawn(0x180, npc);
}
100 => {
npc.tsc_direction = 2;
let _ = npc_list.spawn(0x100, npc);
let _ = npc_list.spawn(0x180, npc);
}
150 => {
npc.tsc_direction = 3;
let _ = npc_list.spawn(0x100, npc);
let _ = npc_list.spawn(0x180, npc);
}
200 => {
npc.tsc_direction = 4;
let _ = npc_list.spawn(0x100, npc);
let _ = npc_list.spawn(0x180, npc);
}
250 => {
self.hit_bounds.right = 0x6000;

View file

@ -1420,9 +1420,26 @@ impl GameScene {
self.tick_npc_splash(state);
}
self.bullet_manager.tick_map_collisions(state, &self.npc_list, &mut self.stage);
self.tick_npc_bullet_collissions(state);
self.bullet_manager.tick_bullets(state, [&self.player1, &self.player2], &self.npc_list, &mut self.stage);
if state.control_flags.control_enabled() {
self.inventory_player1.tick_weapons(
state,
&mut self.player1,
TargetPlayer::Player1,
&mut self.bullet_manager,
);
self.inventory_player2.tick_weapons(
state,
&mut self.player2,
TargetPlayer::Player2,
&mut self.bullet_manager,
);
}
self.bullet_manager.tick_bullets(state, [&self.player1, &self.player2], &self.npc_list);
state.tick_carets();
match self.frame.update_target {
@ -1490,19 +1507,6 @@ impl GameScene {
self.frame.update(state, &self.stage);
if state.control_flags.control_enabled() {
self.inventory_player1.tick_weapons(
state,
&mut self.player1,
TargetPlayer::Player1,
&mut self.bullet_manager,
);
self.inventory_player2.tick_weapons(
state,
&mut self.player2,
TargetPlayer::Player2,
&mut self.bullet_manager,
);
self.hud_player1.tick(state, (&self.player1, &mut self.inventory_player1))?;
self.hud_player2.tick(state, (&self.player2, &mut self.inventory_player2))?;
self.boss_life_bar.tick(state, (&self.npc_list, &self.boss))?;

View file

@ -47,26 +47,14 @@ impl BulletManager {
self.bullets.push(bullet);
}
pub fn tick_bullets(
&mut self,
state: &mut SharedGameState,
players: [&Player; 2],
npc_list: &NPCList,
stage: &mut Stage,
) {
pub fn tick_bullets(&mut self, state: &mut SharedGameState, players: [&Player; 2], npc_list: &NPCList) {
let mut i = 0;
while i < self.bullets.len() {
{
let bullet = unsafe { self.bullets.get_unchecked_mut(i) };
i += 1;
if bullet.life < 1 {
bullet.cond.set_alive(false);
continue;
}
bullet.tick(state, players, npc_list, &mut self.new_bullets);
bullet.tick_map_collisions(state, npc_list, stage);
}
for bullet in &mut self.new_bullets {
@ -79,6 +67,18 @@ impl BulletManager {
self.bullets.retain(|b| !b.is_dead());
}
pub fn tick_map_collisions(&mut self, state: &mut SharedGameState, npc_list: &NPCList, stage: &mut Stage) {
let mut i = 0;
while i < self.bullets.len() {
{
let bullet = unsafe { self.bullets.get_unchecked_mut(i) };
i += 1;
bullet.tick_map_collisions(state, npc_list, stage);
}
}
}
pub fn count_bullets(&self, btype: u16, player_id: TargetPlayer) -> usize {
self.bullets.iter().filter(|b| b.owner == player_id && b.btype == btype).count()
}