From 0873380d11b908b160b2bbcaff8201c15b36e860 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Mon, 4 Aug 2025 11:52:55 -0700 Subject: [PATCH] technically adds jitter --- src/bin/flappy/main.rs | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/bin/flappy/main.rs b/src/bin/flappy/main.rs index 43b03fb..766989e 100644 --- a/src/bin/flappy/main.rs +++ b/src/bin/flappy/main.rs @@ -1,6 +1,8 @@ // Bevy basically forces "complex types" with Querys #![allow(clippy::type_complexity)] +use bevy::platform::hash::RandomState; +use std::hash::BuildHasher; use games::physics2d::*; use games::*; @@ -83,7 +85,7 @@ fn main() { } fn tweak_camera(camera: Single<&mut Camera>) { - info!("Tweaking camera"); + debug!("Tweaking camera"); let mut c = camera.into_inner(); c.clear_color = ClearColorConfig::Custom(WHITE.into()); } @@ -215,13 +217,25 @@ fn init_obstacles( // This is considerably more complexity so can be implemented later, but would keep memory // overhead fairly static. (1..10).for_each(|i| { - // TODO: Jitter up/down/close/far of pipes for challenge - let above = - Transform::from_xyz(300.0 * i as f32, 300.0, -1.0).with_scale(Vec3::splat(100.0)); + // TODO: Jitter close/far of pipes for challenge + let jitter: f32 = { + let h = RandomState::default(); + let x: u64 = h.hash_one(i); + ((x % 10) * 20) as f32 - 100.0 + }; + info!("Jitter for {i} is {jitter}"); + let above = { + let x = 300.0 * i as f32; + let y = 300.0 + jitter; + Transform::from_xyz(x, y, -1.0).with_scale(Vec3::splat(100.0)) + }; commands.spawn((pipe.clone(), above)); - let below = - Transform::from_xyz(300.0 * i as f32, -200.0, -1.0).with_scale(Vec3::splat(100.0)); + let below = { + let x = 300.0 * i as f32; + let y = -200.0 + jitter; + Transform::from_xyz(x, y, -1.0).with_scale(Vec3::splat(100.0)) + }; commands.spawn((pipe.clone(), below)); let hitbox_pos = @@ -346,12 +360,12 @@ fn end_rewind(_trigger: Trigger>, mut next: ResMut>, + _trigger: Trigger>, mut commands: Commands, bird: Single>, ) { let e = *bird; - info!("Flapping {:?}", e); + debug!("Flapping {:?}", e); commands.trigger_targets(Flap, e); } @@ -402,7 +416,7 @@ fn flap_kb( ); birds.iter().for_each(|e| { - info!("Flapping {:?}", e); + debug!("Flapping {:?}", e); commands.trigger_targets(Flap, e); }); } @@ -580,7 +594,7 @@ fn scoring( .read() .filter(|CollisionEnded(a, b)| bird.contains(*a) && hitboxes.contains(*b)) .for_each(|_| { - info!("Hit event while {:?}", state.get()); + debug!("Hit event while {:?}", state.get()); match state.get() { PlayerState::Alive => score.0 = score.0.saturating_add(1), PlayerState::Rewind => score.0 = score.0.saturating_sub(1),