Used hash for coordinates like a smart person

main
Elijah Voigt 4 months ago
parent 9171fee250
commit ff6609cb2f

@ -4,6 +4,8 @@
mod mono;
use bevy::platform::hash::RandomState;
use std::hash::BuildHasher;
use games::*;
use mono::*;
@ -557,6 +559,8 @@ fn spawn_debug_buttons(
.observe(toggle_debug_button_color_over)
.observe(toggle_debug_button_color_out);
});
// Spawn a tree too to make the game feel like it's doing something
commands.spawn((Tree, TreeMonologue(handle.clone())));
}
});
}
@ -624,7 +628,6 @@ fn spawn_monologue_tree(
/// TODO: This can be an `on_add` hook intead, just a little more clunky
fn populate_tree(
trigger: Trigger<OnAdd, TreeMonologue>,
time: Res<Time>,
trees: Query<Entity, With<Tree>>,
server: Res<AssetServer>,
mut commands: Commands,
@ -641,14 +644,15 @@ fn populate_tree(
// 3. Re-interpret as i8s
// 4. Cast to f32
let transform = {
let [a, b, c, d] = time.elapsed().as_secs_f32().to_be_bytes();
info!("Time bits: {a} {b} {c} {d}");
let x = c as i8 / 4;
let y = d as i8 / 4;
let n = RandomState::default().hash_one(trigger.target());
let [a, b, ..] = n.to_be_bytes();
let x: f32 = a.cast_signed().wrapping_div(4).into();
let y: f32 = b.cast_signed().wrapping_div(4).into();
// Avoid mesh clipping by offsetting each on the z axis
let z = trees.iter().len() as f32;
info!("Coordiantes: {x} {y}");
Transform::from_xyz(x.into(), z, y.into()).with_scale(Vec3::splat(10.0))
Transform::from_xyz(x, z, y).with_scale(Vec3::splat(10.0))
};
let material = MeshMaterial3d(materials.add(StandardMaterial {

Loading…
Cancel
Save