diff --git a/src/bin/flappy/main.rs b/src/bin/flappy/main.rs index 928e259..3b7d01f 100644 --- a/src/bin/flappy/main.rs +++ b/src/bin/flappy/main.rs @@ -101,6 +101,7 @@ fn main() { .add_observer(flap) .add_observer(populate_batch) .add_observer(populate_pipe) + .add_observer(move_pipe) .add_observer(populate_ground) .add_observer(populate_ceiling) .add_observer(populate_hitbox) @@ -110,7 +111,7 @@ fn main() { fn tweak_camera(camera: Single<(Entity, &mut Camera)>, mut commands: Commands) { debug!("Tweaking camera"); let (e, mut c) = camera.into_inner(); - c.clear_color = ClearColorConfig::Custom(DEEP_SKY_BLUE.into()); + c.clear_color = ClearColorConfig::Custom(SKY_BLUE.into()); commands.entity(e).insert(ColorGrading { ..default() }); } @@ -340,18 +341,49 @@ fn populate_ceiling( )); } +fn move_pipe( + trigger: Trigger, + mut pipes: Query<(&Batch, &Pipe, &mut Transform)>, + rand: Res, +) { + if let Ok((Batch(id), pipe, mut pipe_t)) = pipes.get_mut(trigger.target()) { + *pipe_t = { + let offset = { + let val = rand.0.hash_one(id); + + let option = val % 3; + + match option { + 0 => 100.0, + 1 => 0.0, + 2 => -100.0, + _ => panic!("Can only pick 1 of 3 pipe offsets"), + } + }; + + match pipe { + Pipe::Top => { + Transform::from_xyz(0.0, 300.0 + offset, -2.0).with_scale(Vec3::splat(100.0)) + } + Pipe::Bottom => { + Transform::from_xyz(0.0, -300.0 + offset, -2.0).with_scale(Vec3::splat(100.0)) + } + } + }; + } +} + /// Based on if this is a Top or Bottom pipe the placement changes /// Otherwise this just spawns in the center of the batch. fn populate_pipe( trigger: Trigger, - pipes: Query<(&Pipe, &Batch)>, + pipes: Query<(&Batch, &Pipe)>, pipe_assets: Res, mut commands: Commands, rand: Res, ) { let pipe_t = { - let (pipe, Batch(id)) = pipes.get(trigger.target()).unwrap(); - + let (Batch(id), pipe) = pipes.get(trigger.target()).unwrap(); let offset = { let val = rand.0.hash_one(id); @@ -374,8 +406,9 @@ fn populate_pipe( } } }; + commands.entity(trigger.target()).insert(( - pipe_t, + pipe_t, pipe_assets.material.clone(), pipe_assets.mesh.clone(), RigidBody::Static, @@ -440,14 +473,14 @@ fn init_assets( ground_assets.material = MeshMaterial2d(materials.add(ColorMaterial { texture: Some(server.load("flappy/ground.png")), - color: Srgba::new(0.9, 0.9, 0.9, 1.0).into(), + color: Srgba::new(0.1, 0.1, 0.1, 1.0).into(), ..default() })); ground_assets.mesh = Mesh2d(meshes.add(Rectangle::new(1.0, 1.0))); ceiling_assets.material = MeshMaterial2d(materials.add(ColorMaterial { texture: Some(server.load("flappy/ceiling.png")), - color: Srgba::new(0.9, 0.9, 0.9, 1.0).into(), + color: Srgba::new(0.1, 0.1, 0.1, 1.0).into(), ..default() })); ceiling_assets.mesh = Mesh2d(meshes.add(Rectangle::new(1.0, 0.777))); @@ -716,12 +749,12 @@ fn init_background( let mesh = Mesh2d(meshes.add(Rectangle::new(1.0, 1.0))); { let t = Transform::from_xyz(-325.0, 0.0, -32.0).with_scale(Vec3::splat(650.0)); - commands.spawn((ParallaxDepth(4.0), mesh.clone(), material.clone(), t)); + commands.spawn((ParallaxDepth(24.0), mesh.clone(), material.clone(), t)); } { let t = Transform::from_xyz(325.0, 0.0, -32.0).with_scale(Vec3::splat(650.0)); - commands.spawn((ParallaxDepth(4.0), mesh.clone(), material.clone(), t)); + commands.spawn((ParallaxDepth(24.0), mesh.clone(), material.clone(), t)); } } { @@ -734,11 +767,11 @@ fn init_background( let mesh = Mesh2d(meshes.add(Rectangle::new(1.0, 1.0))); { let t = Transform::from_xyz(-325.0, 0.0, -64.0).with_scale(Vec3::splat(650.0)); - commands.spawn((ParallaxDepth(8.0), mesh.clone(), material.clone(), t)); + commands.spawn((ParallaxDepth(32.0), mesh.clone(), material.clone(), t)); } { let t = Transform::from_xyz(325.0, 0.0, -64.0).with_scale(Vec3::splat(650.0)); - commands.spawn((ParallaxDepth(8.0), mesh.clone(), material.clone(), t)); + commands.spawn((ParallaxDepth(32.0), mesh.clone(), material.clone(), t)); } } } diff --git a/src/parallax.rs b/src/parallax.rs index 79681ab..7d06133 100644 --- a/src/parallax.rs +++ b/src/parallax.rs @@ -76,7 +76,7 @@ fn wrap_parallax_items( // for each item in the paralax items items.iter_mut().for_each(|(mut t, gt, v, Mesh2d(m))| { if !v.get() { - info!("Item is not visible"); + debug!("Item is not visible"); // Get the total size (window + scale) let half_extents = { let Aabb { half_extents, .. } = meshes.get(m).unwrap().compute_aabb().unwrap(); @@ -84,16 +84,16 @@ fn wrap_parallax_items( }; let object_size = t.scale.truncate() * 2.0; let total_size = window_size_in_world_space + (object_size * half_extents); - info!("Sizes:\n\twindow {window_size_in_world_space}\n\tobject size: {object_size}\n\tAabb Half extents: {half_extents}\n\tTotal size: {total_size}"); + debug!("Sizes:\n\twindow {window_size_in_world_space}\n\tobject size: {object_size}\n\tAabb Half extents: {half_extents}\n\tTotal size: {total_size}"); // Double check that item is out of bounds let bounds_check = Vec2::abs(cam_gt.translation().truncate() - gt.translation().truncate()); let out_of_bounds = (total_size / 2.0) - bounds_check; - info!("Bounds check {bounds_check} | Out of bounds: {out_of_bounds:?}"); + debug!("Bounds check {bounds_check} | Out of bounds: {out_of_bounds:?}"); - info!("Starting position: {:?}", t.translation); + debug!("Starting position: {:?}", t.translation); if out_of_bounds.x < 0.0 { - info!("Object is actually out of bounds horizontally"); + debug!("Object is actually out of bounds horizontally"); // determine if should move to the left or right relative to camera let move_right = cam_gt.translation().x > gt.translation().x; @@ -105,7 +105,7 @@ fn wrap_parallax_items( } } if out_of_bounds.y < 0.0 { - info!("Object is actually out of bounds vertically"); + debug!("Object is actually out of bounds vertically"); let move_up = cam_gt.translation().y > gt.translation().y; // move up or down @@ -115,7 +115,7 @@ fn wrap_parallax_items( t.translation.y -= total_size.y; } } - info!("Moved to {:?}", t.translation); + debug!("Moved to {:?}", t.translation); } }); }