diff --git a/examples/the-dungeon-puzzlers-lament/src/game/simulation.rs b/examples/the-dungeon-puzzlers-lament/src/game/simulation.rs index ce42c8ec..8d9e36bb 100644 --- a/examples/the-dungeon-puzzlers-lament/src/game/simulation.rs +++ b/examples/the-dungeon-puzzlers-lament/src/game/simulation.rs @@ -41,7 +41,10 @@ impl Simulation { let mut entities = EntityMap::default(); let mut animation = Animation::default(); - for (item, location) in a { + let mut entities_to_add: Vec<_> = a.collect(); + entities_to_add.sort_unstable_by_key(|(_, location)| location.x + location.y * 100); + + for (item, location) in entities_to_add { animation.populate(entities.add(item, location), sfx); } diff --git a/examples/the-dungeon-puzzlers-lament/src/game/simulation/entity.rs b/examples/the-dungeon-puzzlers-lament/src/game/simulation/entity.rs index a9c46b04..72b06082 100644 --- a/examples/the-dungeon-puzzlers-lament/src/game/simulation/entity.rs +++ b/examples/the-dungeon-puzzlers-lament/src/game/simulation/entity.rs @@ -5,7 +5,7 @@ use core::ops::Neg; use agb::fixnum::Vector2D; -use alloc::{boxed::Box, collections::VecDeque, vec::Vec}; +use alloc::{boxed::Box, vec::Vec}; use slotmap::{new_key_type, SlotMap}; use crate::{ @@ -311,7 +311,7 @@ impl EntityMap { let mut animations = Vec::new(); - let mut entities_to_try_update = self + let entities_to_try_update = self .map .iter() .map(|(key, entity)| (key, entity.desired_action(hero))) @@ -321,13 +321,6 @@ impl EntityMap { }) .collect::>(); - entities_to_try_update.sort_unstable_by_key(|(e, _)| { - let e = self.map.get(*e).unwrap(); - e.location.x + e.location.y * 1000 - }); - - let entities_to_try_update = entities_to_try_update; - for (entity_to_update_key, direction) in entities_to_try_update.iter().copied() { let (_, hero_has_died_result, win_has_triggered_result) = self .attempt_move_in_direction(