Improvements

This commit is contained in:
Thomas Forgione 2019-03-30 14:36:04 +01:00
parent 93171a5123
commit a00e39e3f5
No known key found for this signature in database
GPG Key ID: BFD17A2D71B3B5E7
2 changed files with 29 additions and 20 deletions

View File

@ -108,7 +108,9 @@ impl Renderer {
} }
for c in scene.characters() { for c in scene.characters() {
self.draw(c); if c.is_alive() {
self.draw(c);
}
} }
} }

View File

@ -89,31 +89,38 @@ impl Scene {
let mut state = State::Finished; let mut state = State::Finished;
for c in &mut self.characters { for c in &mut self.characters {
let old = c.bbox();
// Compute the offset between position and bbox // Don't need to update if the character is dead
let offset = Vector2::new(old.left, old.top) - c.position; if c.is_alive() {
c.update(duration); let old = c.bbox();
if let Some((axis, position, damage)) = self.map.collides_bbox(old, c.bbox()) { // Compute the offset between position and bbox
c.position = position - offset; let offset = Vector2::new(old.left, old.top) - c.position;
if axis.is_x() {
c.speed.x = 0.0; c.update(duration);
}
if axis.is_y() { if let Some((axis, position, damage)) = self.map.collides_bbox(old, c.bbox()) {
c.speed.y = 0.0; c.position = position - offset;
c.ground_collision(); 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;
} }
} }