bevy-learning

A learning project of mine.
git clone git://archive.git.mtrnord.blog/MTRNord/bevy-learning.git
Log | Files | Refs

commit b45f4a2513bf9e4f124c2124fe15066fae03bb03
parent c20a67816e7114cc32bccdf45c6b7555cf915888
Author: MTRNord <mtrnord1@gmail.com>
Date:   Tue, 16 Mar 2021 14:50:25 +0100

Fix some collision issues

Took 27 minutes

Diffstat:
Msrc/plugins/player.rs | 27++++++++++-----------------
Msrc/plugins/world.rs | 4++--
2 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/src/plugins/player.rs b/src/plugins/player.rs @@ -68,7 +68,7 @@ fn spawn_player( player_start.px[0] as f32, // The player y position is the entity's y position from the map data, but // multiplied by negative one because in the LDtk map +y means down and not up. - -(player_start.px[1]) as f32, + -(player_start.px[1] - 1) as f32, // Spawn the player with the z value we determined earlier player_z, ); @@ -176,22 +176,15 @@ fn player_movement( // assuming there is exactly one player entity, so this is OK if let Some((_, mut player_transform)) = player.iter_mut().next() { - let new_coords = player_transform.translation + translation; - let rounded_x = new_coords.x.round(); - let rounded_y = new_coords.y.round(); - let rounded_cords = Vec3::new(rounded_x, rounded_y, new_coords.z); - if can_move_to_requested_coordinate(&game_state, rounded_cords, 16, 16) { - player_transform.translation += translation; - } - } - // assuming there is exactly one camera entity, so this is OK - if let Some(mut camera_transform) = camera.iter_mut().next() { - let new_coords = camera_transform.translation + translation; - let rounded_x = new_coords.x.round(); - let rounded_y = new_coords.y.round(); - let rounded_cords = Vec3::new(rounded_x, rounded_y, new_coords.z); - if can_move_to_requested_coordinate(&game_state, rounded_cords, 16, 16) { - camera_transform.translation += translation; + if let Some(mut camera_transform) = camera.iter_mut().next() { + let new_coords = player_transform.translation + translation; + let rounded_x = new_coords.x.round(); + let rounded_y = new_coords.y.round(); + let rounded_cords = Vec3::new(rounded_x, rounded_y, new_coords.z); + if can_move_to_requested_coordinate(&game_state, rounded_cords, 16, 16) { + player_transform.translation += translation; + camera_transform.translation += translation; + } } } } diff --git a/src/plugins/world.rs b/src/plugins/world.rs @@ -77,8 +77,8 @@ fn one_d_to_two_d_coordinate( tile_height: f32, ) -> Vec2 { Vec2::new( - (((coordinate % row_length) * tile_width) + (tile_width / 2.0)).round() as f32, - ((-(coordinate / row_length * tile_height)) - (tile_height / 2.0)).round() as f32, + ((coordinate % row_length).round() * tile_width + 11.0).round() as f32, + (-((coordinate / row_length).round() * tile_height + 8.0)).round() as f32, ) }