technically adds jitter

main
Elijah Voigt 3 months ago
parent 808674d2df
commit 0873380d11

@ -1,6 +1,8 @@
// Bevy basically forces "complex types" with Querys // Bevy basically forces "complex types" with Querys
#![allow(clippy::type_complexity)] #![allow(clippy::type_complexity)]
use bevy::platform::hash::RandomState;
use std::hash::BuildHasher;
use games::physics2d::*; use games::physics2d::*;
use games::*; use games::*;
@ -83,7 +85,7 @@ fn main() {
} }
fn tweak_camera(camera: Single<&mut Camera>) { fn tweak_camera(camera: Single<&mut Camera>) {
info!("Tweaking camera"); debug!("Tweaking camera");
let mut c = camera.into_inner(); let mut c = camera.into_inner();
c.clear_color = ClearColorConfig::Custom(WHITE.into()); 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 // This is considerably more complexity so can be implemented later, but would keep memory
// overhead fairly static. // overhead fairly static.
(1..10).for_each(|i| { (1..10).for_each(|i| {
// TODO: Jitter up/down/close/far of pipes for challenge // TODO: Jitter close/far of pipes for challenge
let above = let jitter: f32 = {
Transform::from_xyz(300.0 * i as f32, 300.0, -1.0).with_scale(Vec3::splat(100.0)); 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)); commands.spawn((pipe.clone(), above));
let below = let below = {
Transform::from_xyz(300.0 * i as f32, -200.0, -1.0).with_scale(Vec3::splat(100.0)); 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)); commands.spawn((pipe.clone(), below));
let hitbox_pos = let hitbox_pos =
@ -346,12 +360,12 @@ fn end_rewind(_trigger: Trigger<Pointer<Released>>, mut next: ResMut<NextState<P
} }
fn flap_button( fn flap_button(
trigger: Trigger<Pointer<Pressed>>, _trigger: Trigger<Pointer<Pressed>>,
mut commands: Commands, mut commands: Commands,
bird: Single<Entity, With<Bird>>, bird: Single<Entity, With<Bird>>,
) { ) {
let e = *bird; let e = *bird;
info!("Flapping {:?}", e); debug!("Flapping {:?}", e);
commands.trigger_targets(Flap, e); commands.trigger_targets(Flap, e);
} }
@ -402,7 +416,7 @@ fn flap_kb(
); );
birds.iter().for_each(|e| { birds.iter().for_each(|e| {
info!("Flapping {:?}", e); debug!("Flapping {:?}", e);
commands.trigger_targets(Flap, e); commands.trigger_targets(Flap, e);
}); });
} }
@ -580,7 +594,7 @@ fn scoring(
.read() .read()
.filter(|CollisionEnded(a, b)| bird.contains(*a) && hitboxes.contains(*b)) .filter(|CollisionEnded(a, b)| bird.contains(*a) && hitboxes.contains(*b))
.for_each(|_| { .for_each(|_| {
info!("Hit event while {:?}", state.get()); debug!("Hit event while {:?}", state.get());
match state.get() { match state.get() {
PlayerState::Alive => score.0 = score.0.saturating_add(1), PlayerState::Alive => score.0 = score.0.saturating_add(1),
PlayerState::Rewind => score.0 = score.0.saturating_sub(1), PlayerState::Rewind => score.0 = score.0.saturating_sub(1),

Loading…
Cancel
Save