diff --git a/assets/test-textures/mario.png b/assets/test-textures/mario.png index 52a20c4..a5f72f8 100644 Binary files a/assets/test-textures/mario.png and b/assets/test-textures/mario.png differ diff --git a/assets/textures/mario.png b/assets/textures/mario.png index 296341a..343a39f 100644 Binary files a/assets/textures/mario.png and b/assets/textures/mario.png differ diff --git a/src/engine/character/mod.rs b/src/engine/character/mod.rs index de850f3..d06b2de 100644 --- a/src/engine/character/mod.rs +++ b/src/engine/character/mod.rs @@ -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) } } diff --git a/src/engine/scene/mod.rs b/src/engine/scene/mod.rs index b47e01b..7b2c3bd 100644 --- a/src/engine/scene/mod.rs +++ b/src/engine/scene/mod.rs @@ -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; } diff --git a/src/engine/texture/mod.rs b/src/engine/texture/mod.rs index 3d554e1..3d63099 100644 --- a/src/engine/texture/mod.rs +++ b/src/engine/texture/mod.rs @@ -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", );