diff --git a/src/engine/renderer/mod.rs b/src/engine/renderer/mod.rs index b144751..f36f0d9 100644 --- a/src/engine/renderer/mod.rs +++ b/src/engine/renderer/mod.rs @@ -108,7 +108,9 @@ impl Renderer { } for c in scene.characters() { - self.draw(c); + if c.is_alive() { + self.draw(c); + } } } diff --git a/src/engine/scene/mod.rs b/src/engine/scene/mod.rs index 4fff52a..59ee924 100644 --- a/src/engine/scene/mod.rs +++ b/src/engine/scene/mod.rs @@ -89,31 +89,38 @@ impl Scene { let mut state = State::Finished; for c in &mut self.characters { - let old = c.bbox(); - // Compute the offset between position and bbox - let offset = Vector2::new(old.left, old.top) - c.position; + // Don't need to update if the character is dead + if c.is_alive() { - c.update(duration); + let old = c.bbox(); - if let Some((axis, position, damage)) = self.map.collides_bbox(old, c.bbox()) { - c.position = position - offset; - if axis.is_x() { - c.speed.x = 0.0; - } - if axis.is_y() { - c.speed.y = 0.0; - c.ground_collision(); + // Compute the offset between position and bbox + let offset = Vector2::new(old.left, old.top) - c.position; + + c.update(duration); + + if let Some((axis, position, damage)) = self.map.collides_bbox(old, c.bbox()) { + c.position = position - offset; + if axis.is_x() { + c.speed.x = 0.0; + } + if axis.is_y() { + c.speed.y = 0.0; + c.ground_collision(); + } + + c.take_damage(damage); + + } else { + c.fall_off(); } - c.take_damage(damage); + // If a character is alive and still have controls, the game should continue + if c.controls().is_some() { + state = State::Running; + } - } else { - c.fall_off(); - } - - if c.controls().is_some() && c.is_alive() { - state = State::Running; } }