Better textured, better collisions

This commit is contained in:
Thomas Forgione 2018-10-06 18:59:17 +02:00
parent 6bfdfb247e
commit 7fe182b609
5 changed files with 8 additions and 3 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@ -149,7 +149,7 @@ impl Character {
/// Returns the collision bounding box of the character.
pub fn bbox(&self) -> FloatRect {
FloatRect::new(self.position.x, self.position.y, 32.0, 32.0)
FloatRect::new(self.position.x + 8.0, self.position.y + 16.0, 16.0, 16.0)
}
}

View File

@ -1,5 +1,6 @@
use std::time::Duration;
use sfml::system::Vector2;
use sfml::window::Event;
use sfml::graphics::View;
@ -76,10 +77,14 @@ impl Scene {
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;
c.update(duration);
if let Some((axis, position)) = self.map.collides_bbox(old, c.bbox()) {
c.position = position;
c.position = position - offset;
if axis.is_x() {
c.speed.x = 0.0;
}

View File

@ -57,7 +57,7 @@ macro_rules! make_textures {
}
make_textures!(
Mario, mario, make_mario_texture, "../../../assets/test-textures/mario.png",
Mario, mario, make_mario_texture, "../../../assets/textures/mario.png",
Overworld, overworld, make_overworld_texture, "../../../assets/textures/overworld.png",
);