Fix render order
This commit is contained in:
parent
a79f0e7c90
commit
00fa6edb20
@ -279,6 +279,9 @@ impl MapRenderer {
|
|||||||
camera,
|
camera,
|
||||||
);
|
);
|
||||||
let player_position = na::Vector2::new(player_position.x, player_position.y * -1.0);
|
let player_position = na::Vector2::new(player_position.x, player_position.y * -1.0);
|
||||||
|
// Get the tile width and height
|
||||||
|
let tile_width = 128;
|
||||||
|
let tile_height = 128;
|
||||||
|
|
||||||
// Handle each layer from the bottom up
|
// Handle each layer from the bottom up
|
||||||
for layer in self.map.layers() {
|
for layer in self.map.layers() {
|
||||||
@ -289,10 +292,6 @@ impl MapRenderer {
|
|||||||
let mut sampler_x = 0;
|
let mut sampler_x = 0;
|
||||||
let mut sampler_y = 0;
|
let mut sampler_y = 0;
|
||||||
|
|
||||||
// Get the tile width and height
|
|
||||||
let tile_width = 128;
|
|
||||||
let tile_height = 128;
|
|
||||||
|
|
||||||
// Loop until we have covered all tiles on the screen
|
// Loop until we have covered all tiles on the screen
|
||||||
for y in (world_win_top_left.y as i64)..(world_win_bottom_right.y as i64) {
|
for y in (world_win_top_left.y as i64)..(world_win_bottom_right.y as i64) {
|
||||||
// Convert the pixel coordinates to tile coordinates
|
// Convert the pixel coordinates to tile coordinates
|
||||||
@ -331,12 +330,43 @@ impl MapRenderer {
|
|||||||
Color::WHITE,
|
Color::WHITE,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tiled::LayerType::ObjectLayer(_) => todo!(),
|
||||||
|
tiled::LayerType::ImageLayer(_) => todo!(),
|
||||||
|
tiled::LayerType::GroupLayer(_) => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep track of our sampler X and Y values
|
||||||
|
let mut sampler_x = 0;
|
||||||
|
let mut sampler_y = 0;
|
||||||
|
|
||||||
|
// Loop until we have covered all tiles on the screen
|
||||||
|
for y in (world_win_top_left.y as i64)..(world_win_bottom_right.y as i64) {
|
||||||
|
// Convert the pixel coordinates to tile coordinates
|
||||||
|
let tile_y = (y as f32 / tile_height as f32).floor() as i32;
|
||||||
|
|
||||||
|
// If we are looking at a new tile, update the sampler
|
||||||
|
if sampler_y != tile_y {
|
||||||
|
sampler_y = tile_y;
|
||||||
|
|
||||||
|
for x in (world_win_top_left.x as i64)..(world_win_bottom_right.x as i64) {
|
||||||
|
// Convert the pixel coordinates to tile coordinates
|
||||||
|
let tile_x = (x as f32 / tile_width as f32).floor() as i32;
|
||||||
|
// debug!("Tile: ({}, {})", tile_x, tile_y);
|
||||||
|
|
||||||
|
// If we are looking at a new tile, update the sampler
|
||||||
|
if sampler_x != tile_x {
|
||||||
|
sampler_x = tile_x;
|
||||||
|
|
||||||
// Check if there is an object at this tile
|
// Check if there is an object at this tile
|
||||||
for obj_ref in &self.world_objects.object_references {
|
for obj_ref in &self.world_objects.object_references {
|
||||||
if obj_ref.get_tile_space_position().x == sampler_x as f32
|
if obj_ref.get_tile_space_position().x == sampler_x as f32
|
||||||
&& obj_ref.get_tile_space_position().y
|
&& obj_ref.get_tile_space_position().y == sampler_y as f32
|
||||||
== sampler_y as f32
|
|
||||||
{
|
{
|
||||||
// Get access to the actual object definition
|
// Get access to the actual object definition
|
||||||
let object_key = obj_ref.into_key();
|
let object_key = obj_ref.into_key();
|
||||||
@ -356,8 +386,7 @@ impl MapRenderer {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
tex.render_automatic(
|
tex.render_automatic(
|
||||||
draw_handle,
|
draw_handle,
|
||||||
obj_ref.get_world_space_position()
|
obj_ref.get_world_space_position() - (tex.size() / 2.0),
|
||||||
- (tex.size() / 2.0),
|
|
||||||
None,
|
None,
|
||||||
Some(tex.size() / 2.0),
|
Some(tex.size() / 2.0),
|
||||||
Some(obj_ref.rotation_degrees),
|
Some(obj_ref.rotation_degrees),
|
||||||
@ -369,8 +398,7 @@ impl MapRenderer {
|
|||||||
.bottom_static_textures
|
.bottom_static_textures
|
||||||
.get_mut(&object_key)
|
.get_mut(&object_key)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let p: Vector2 =
|
let p: Vector2 = obj_ref.get_world_space_position().into();
|
||||||
obj_ref.get_world_space_position().into();
|
|
||||||
let r1 = Rectangle {
|
let r1 = Rectangle {
|
||||||
x: 0.0,
|
x: 0.0,
|
||||||
y: 0.0,
|
y: 0.0,
|
||||||
@ -401,12 +429,9 @@ impl MapRenderer {
|
|||||||
if let Some(top_texture) = &obj_def.top_texture {
|
if let Some(top_texture) = &obj_def.top_texture {
|
||||||
// We need to detect if the player is in the footprint of the object
|
// We need to detect if the player is in the footprint of the object
|
||||||
let mut tint = Color::WHITE;
|
let mut tint = Color::WHITE;
|
||||||
if let Some(footprint_radius) =
|
if let Some(footprint_radius) = obj_def.visualization_radius {
|
||||||
obj_def.visualization_radius
|
let player_dist_to_object =
|
||||||
{
|
(obj_ref.get_world_space_position() - player_position)
|
||||||
let player_dist_to_object = (obj_ref
|
|
||||||
.get_world_space_position()
|
|
||||||
- player_position)
|
|
||||||
.norm();
|
.norm();
|
||||||
// debug!(
|
// debug!(
|
||||||
// "Player dist to object: {}",
|
// "Player dist to object: {}",
|
||||||
@ -425,8 +450,7 @@ impl MapRenderer {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
tex.render_automatic(
|
tex.render_automatic(
|
||||||
draw_handle,
|
draw_handle,
|
||||||
obj_ref.get_world_space_position()
|
obj_ref.get_world_space_position() - (tex.size() / 2.0),
|
||||||
- (tex.size() / 2.0),
|
|
||||||
None,
|
None,
|
||||||
Some(tex.size() / 2.0),
|
Some(tex.size() / 2.0),
|
||||||
Some(obj_ref.rotation_degrees),
|
Some(obj_ref.rotation_degrees),
|
||||||
@ -438,8 +462,7 @@ impl MapRenderer {
|
|||||||
.top_static_textures
|
.top_static_textures
|
||||||
.get_mut(&object_key)
|
.get_mut(&object_key)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let p: Vector2 =
|
let p: Vector2 = obj_ref.get_world_space_position().into();
|
||||||
obj_ref.get_world_space_position().into();
|
|
||||||
let r1 = Rectangle {
|
let r1 = Rectangle {
|
||||||
x: 0.0,
|
x: 0.0,
|
||||||
y: 0.0,
|
y: 0.0,
|
||||||
@ -484,12 +507,6 @@ impl MapRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tiled::LayerType::ObjectLayer(_) => todo!(),
|
|
||||||
tiled::LayerType::ImageLayer(_) => todo!(),
|
|
||||||
tiled::LayerType::GroupLayer(_) => todo!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the list of world colliders
|
/// Get the list of world colliders
|
||||||
pub fn get_world_colliders(&self) -> Vec<WorldSpaceObjectCollider> {
|
pub fn get_world_colliders(&self) -> Vec<WorldSpaceObjectCollider> {
|
||||||
|
Reference in New Issue
Block a user