Working on collisions

This commit is contained in:
2018-10-06 11:32:44 +02:00
parent a4b5a735ae
commit 89295b9283
8 changed files with 21 additions and 9 deletions
+6 -6
View File
@@ -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
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

+4
View File
@@ -229,4 +229,8 @@ impl Drawable for Character {
fn position(&self) -> Vector2<f32> {
self.position
}
fn origin(&self) -> Vector2<f32> {
Vector2::new(16.0, 16.0)
}
}
+6 -2
View File
@@ -234,6 +234,10 @@ impl Drawable for PositionedTile {
fn position(&self) -> Vector2<f32> {
self.position.into()
}
fn origin(&self) -> Vector2<f32> {
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 {
+4
View File
@@ -32,6 +32,9 @@ pub trait Drawable {
/// Returns the position on which the drawable should be drawn.
fn position(&self) -> Vector2<f32>;
/// Returns the origin of the sprite.
fn origin(&self) -> Vector2<f32>;
}
/// 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);
}
+1 -1
View File
@@ -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",
);