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() {
self.draw(c);
if c.is_alive() {
self.draw(c);
}
}
}

View File

@ -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;
}
}