pub mod z_layers {
pub const BACKGROUND: f32 = -100.0;
pub const TILEMAP_OFFSET: f32 = 10.0;
pub const TILEMAP_LAYER_BASE: f32 = -2.0;
pub const TILEMAP_LAYER_STEP: f32 = 0.5;
pub const OBJECTS: f32 = 0.0;
pub const PLAYER: f32 = 1.0;
pub const OBJECT_BEHIND_PLAYER: f32 = -1.0;
pub const OBJECT_IN_FRONT_OF_PLAYER: f32 = 1.0;
pub const EFFECTS: f32 = 5.0;
pub const UI_BACKGROUND: f32 = 10.0;
pub const UI_FOREGROUND: f32 = 20.0;
pub const OVERLAY: f32 = 100.0;
}
#[inline]
pub fn calculate_tilemap_layer_z(layer_index: usize, total_layers: usize) -> f32 {
z_layers::TILEMAP_LAYER_BASE
- (total_layers as f32 - 1.0 - layer_index as f32) * z_layers::TILEMAP_LAYER_STEP
}
#[inline]
pub fn calculate_tilemap_layer_z_with_config(
layer_index: usize,
total_layers: usize,
z_base: f32,
z_step: f32,
) -> f32 {
z_base - (total_layers as f32 - 1.0 - layer_index as f32) * z_step
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_tilemap_layer_z_ordering() {
let z0 = calculate_tilemap_layer_z(0, 5);
let z4 = calculate_tilemap_layer_z(4, 5);
assert!(z0 < z4, "Layer 0 should be behind layer 4");
}
#[test]
fn test_tilemap_layer_z_step() {
let z0 = calculate_tilemap_layer_z(0, 5);
let z1 = calculate_tilemap_layer_z(1, 5);
let diff = (z1 - z0).abs();
assert!(
(diff - z_layers::TILEMAP_LAYER_STEP).abs() < 0.001,
"Adjacent layers should be separated by TILEMAP_LAYER_STEP"
);
}
}