use crate::sprites::Spr; use bevy::prelude::*; use bevy::sprite::Anchor; pub const TW: f32 = 64.0; pub const TH: f32 = 32.0; pub const PX: f32 = 2.0; pub fn to_screen(p: Vec2) -> Vec2 { Vec2::new((p.x - p.y) * TW, -(p.x + p.y) * TH) } pub fn to_grid(s: Vec2) -> Vec2 { let a = s.x / TW; let b = -s.y / TH; Vec2::new((a + b) * 0.5, (b - a) * 0.5) } pub fn depth(p: Vec2) -> f32 { (p.x + p.y) * 0.01 } pub fn cell(p: Vec2) -> IVec2 { IVec2::new(p.x.floor() as i32, p.y.floor() as i32) } pub fn anchor(s: &Spr) -> Anchor { Anchor(Vec2::new(s.origin.0 / s.cell.0 as f32 - 0.5, 0.5 - s.origin.1 / s.cell.1 as f32)) } pub fn hash(x: i32, y: i32, salt: u32) -> f32 { let mut h = (x as u32).wrapping_mul(0x8da6b343) ^ (y as u32).wrapping_mul(0xd8163841) ^ salt.wrapping_mul(0xcb1ab31f); h ^= h >> 13; h = h.wrapping_mul(0x5bd1e995); h ^= h >> 15; (h & 0xffffff) as f32 / 16777216.0 }