diff --git a/assets/levels/level1.txt b/assets/levels/level1.txt index 46a3f55..bc85445 100644 --- a/assets/levels/level1.txt +++ b/assets/levels/level1.txt @@ -4,12 +4,12 @@ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 +1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 +1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 diff --git a/assets/test-textures/mario.png b/assets/test-textures/mario.png new file mode 100644 index 0000000..52a20c4 Binary files /dev/null and b/assets/test-textures/mario.png differ diff --git a/assets/test-textures/overworld-raw.png b/assets/test-textures/overworld-raw.png new file mode 100644 index 0000000..f56b851 Binary files /dev/null and b/assets/test-textures/overworld-raw.png differ diff --git a/assets/test-textures/overworld.png b/assets/test-textures/overworld.png new file mode 100644 index 0000000..255680b Binary files /dev/null and b/assets/test-textures/overworld.png differ diff --git a/src/engine/character/mod.rs b/src/engine/character/mod.rs index c775681..2ec938b 100644 --- a/src/engine/character/mod.rs +++ b/src/engine/character/mod.rs @@ -229,4 +229,8 @@ impl Drawable for Character { fn position(&self) -> Vector2 { self.position } + + fn origin(&self) -> Vector2 { + Vector2::new(16.0, 16.0) + } } diff --git a/src/engine/map/mod.rs b/src/engine/map/mod.rs index 5a4a564..dc6ae77 100644 --- a/src/engine/map/mod.rs +++ b/src/engine/map/mod.rs @@ -234,6 +234,10 @@ impl Drawable for PositionedTile { fn position(&self) -> Vector2 { self.position.into() } + + fn origin(&self) -> Vector2 { + Vector2::new(0.0, 0.0) + } } /// The map represents the tiles contained in a level. @@ -363,8 +367,8 @@ impl Map { // Find tile on x, y if x > 0.0 && y > 0.0 { - let row = (y / 16.0) as usize + 2; - let col = (x / 16.0) as usize + 1; + let row = (y / 16.0) as usize; + let col = (x / 16.0) as usize; if let Some((tile, _)) = self.tiles.get((row, col)) { if tile.from_top { diff --git a/src/engine/renderer/mod.rs b/src/engine/renderer/mod.rs index eb383d7..9b040b2 100644 --- a/src/engine/renderer/mod.rs +++ b/src/engine/renderer/mod.rs @@ -32,6 +32,9 @@ pub trait Drawable { /// Returns the position on which the drawable should be drawn. fn position(&self) -> Vector2; + + /// Returns the origin of the sprite. + fn origin(&self) -> Vector2; } /// The game window. @@ -89,6 +92,7 @@ impl Renderer { use sfml::graphics::Transformable; sprite.set_position(drawable.position()); + sprite.set_origin(drawable.origin()); self.window.draw(&sprite); } diff --git a/src/engine/texture/mod.rs b/src/engine/texture/mod.rs index 3d63099..3d554e1 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/textures/mario.png", + Mario, mario, make_mario_texture, "../../../assets/test-textures/mario.png", Overworld, overworld, make_overworld_texture, "../../../assets/textures/overworld.png", );