Better textured, better collisions

Bu işleme şunda yer alıyor:
Thomas Forgione 2018-10-06 18:59:17 +02:00
ebeveyn 6bfdfb247e
işleme 7fe182b609
5 değiştirilmiş dosya ile 8 ekleme ve 3 silme

İkili dosya gösterilmiyor.

Önce

Genişlik:  |  Yükseklik:  |  Boyut: 3.7 KiB

Sonra

Genişlik:  |  Yükseklik:  |  Boyut: 3.7 KiB

İkili dosya gösterilmiyor.

Önce

Genişlik:  |  Yükseklik:  |  Boyut: 2.5 KiB

Sonra

Genişlik:  |  Yükseklik:  |  Boyut: 3.6 KiB

Dosyayı Görüntüle

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

Dosyayı Görüntüle

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

Dosyayı Görüntüle

@ -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",
);