forge
Explore
Log in

Don't you dare go Hollow

courier

Clone
★ 0

0 watching0 forksRustAGPL-3.05.3 MiB6d9eeb9Tahinli21 days ago3 commits

iso.rs37 lines, 931 bytesHistoryRawDownload
1use crate::sprites::Spr;
2use bevy::prelude::*;
3use bevy::sprite::Anchor;
4
5pub const TW: f32 = 64.0;
6pub const TH: f32 = 32.0;
7pub const PX: f32 = 2.0;
8
9pub fn to_screen(p: Vec2) -> Vec2 {
10 Vec2::new((p.x - p.y) * TW, -(p.x + p.y) * TH)
11}
12
13pub fn to_grid(s: Vec2) -> Vec2 {
14 let a = s.x / TW;
15 let b = -s.y / TH;
16 Vec2::new((a + b) * 0.5, (b - a) * 0.5)
17}
18
19pub fn depth(p: Vec2) -> f32 {
20 (p.x + p.y) * 0.01
21}
22
23pub fn cell(p: Vec2) -> IVec2 {
24 IVec2::new(p.x.floor() as i32, p.y.floor() as i32)
25}
26
27pub fn anchor(s: &Spr) -> Anchor {
28 Anchor(Vec2::new(s.origin.0 / s.cell.0 as f32 - 0.5, 0.5 - s.origin.1 / s.cell.1 as f32))
29}
30
31pub fn hash(x: i32, y: i32, salt: u32) -> f32 {
32 let mut h = (x as u32).wrapping_mul(0x8da6b343) ^ (y as u32).wrapping_mul(0xd8163841) ^ salt.wrapping_mul(0xcb1ab31f);
33 h ^= h >> 13;
34 h = h.wrapping_mul(0x5bd1e995);
35 h ^= h >> 15;
36 (h & 0xffffff) as f32 / 16777216.0
37}