Improvements
This commit is contained in:
parent
93171a5123
commit
a00e39e3f5
|
@ -108,7 +108,9 @@ impl Renderer {
|
|||
}
|
||||
|
||||
for c in scene.characters() {
|
||||
self.draw(c);
|
||||
if c.is_alive() {
|
||||
self.draw(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue