From c48be4d41bb032930c91e9b50d633b4d50014c19 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Tue, 12 Aug 2025 20:19:25 -0700 Subject: [PATCH] Pipes extend off the screen --- assets/flappy/pipe.png | 4 +- src/bin/flappy/main.rs | 92 +++++------------------------------------- 2 files changed, 11 insertions(+), 85 deletions(-) diff --git a/assets/flappy/pipe.png b/assets/flappy/pipe.png index 6d93bba..3c368b4 100644 --- a/assets/flappy/pipe.png +++ b/assets/flappy/pipe.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d73f8490b64829f8102f23a5bd8461566e9b53741d5eba6d0c8c24c5d46a6f1c -size 127 +oid sha256:1f291a3023d0f6e69da445c20b233aeddb1bc1a2858d60b71081bf406a47df84 +size 243 diff --git a/src/bin/flappy/main.rs b/src/bin/flappy/main.rs index aa228b2..43fa7ad 100644 --- a/src/bin/flappy/main.rs +++ b/src/bin/flappy/main.rs @@ -1,6 +1,7 @@ // Bevy basically forces "complex types" with Querys #![allow(clippy::type_complexity)] +use bevy::render::view::{ColorGrading, ColorGradingGlobal}; use games::physics2d::*; use games::*; use std::hash::BuildHasher; @@ -36,8 +37,7 @@ fn main() { ), ) .add_systems(OnEnter(PlayerState::Alive), alive_bird) - .add_systems(OnEnter(PlayerState::Rewind), (invert_colors, alive_bird)) - .add_systems(OnExit(PlayerState::Rewind), uninvert_colors) + .add_systems(OnEnter(PlayerState::Rewind), alive_bird) .add_systems(OnEnter(PlayerState::Pause), pause_bird) .add_systems(OnEnter(PlayerState::Stasis), pause_bird) .add_systems( @@ -98,10 +98,11 @@ fn main() { .run(); } -fn tweak_camera(camera: Single<&mut Camera>) { +fn tweak_camera(camera: Single<(Entity, &mut Camera)>, mut commands: Commands) { debug!("Tweaking camera"); - let mut c = camera.into_inner(); + let (e, mut c) = camera.into_inner(); c.clear_color = ClearColorConfig::Custom(WHITE.into()); + commands.entity(e).insert(ColorGrading { ..default() }); } #[derive(Component)] @@ -282,10 +283,10 @@ fn populate_pipe( match pipe { Pipe::Top => { - Transform::from_xyz(0.0, 200.0 + offset, -1.0).with_scale(Vec3::splat(100.0)) + Transform::from_xyz(0.0, 400.0 + offset, -2.0).with_scale(Vec3::splat(100.0)) } Pipe::Bottom => { - Transform::from_xyz(0.0, -100.0 + offset, -1.0).with_scale(Vec3::splat(100.0)) + Transform::from_xyz(0.0, -200.0 + offset, -2.0).with_scale(Vec3::splat(100.0)) } } }; @@ -294,7 +295,7 @@ fn populate_pipe( pipe_assets.material.clone(), pipe_assets.mesh.clone(), RigidBody::Static, - Collider::rectangle(1.0, 1.0), + Collider::rectangle(1.0, 4.0), Name::new("pipe"), )); } @@ -315,21 +316,18 @@ fn populate_hitbox(trigger: Trigger, mut commands: Commands) { #[derive(Resource, Default)] struct BirdAssets { material: MeshMaterial2d, - rewind_material: MeshMaterial2d, mesh: Mesh2d, } #[derive(Resource, Default)] struct GroundAssets { material: MeshMaterial2d, - rewind_material: MeshMaterial2d, mesh: Mesh2d, } #[derive(Resource, Default)] struct PipeAssets { material: MeshMaterial2d, - rewind_material: MeshMaterial2d, mesh: Mesh2d, } @@ -347,23 +345,13 @@ fn init_assets( color: GREEN.into(), ..default() })); - pipe_assets.rewind_material = MeshMaterial2d(materials.add(ColorMaterial { - texture: Some(server.load("flappy/pipe.png")), - color: (WHITE - GREEN).with_alpha(1.0).into(), - ..default() - })); - pipe_assets.mesh = Mesh2d(meshes.add(Rectangle::new(1.0, 1.0))); + pipe_assets.mesh = Mesh2d(meshes.add(Rectangle::new(1.0, 4.0))); ground_assets.material = MeshMaterial2d(materials.add(ColorMaterial { texture: Some(server.load("flappy/ground.png")), color: BLACK.into(), ..default() })); - ground_assets.rewind_material = MeshMaterial2d(materials.add(ColorMaterial { - texture: Some(server.load("flappy/ground.png")), - color: WHITE.into(), - ..default() - })); ground_assets.mesh = Mesh2d(meshes.add(Rectangle::new(1.0, 1.0))); bird_assets.material = MeshMaterial2d(materials.add(ColorMaterial { @@ -372,12 +360,6 @@ fn init_assets( alpha_mode: AlphaMode2d::Blend, ..default() })); - bird_assets.rewind_material = MeshMaterial2d(materials.add(ColorMaterial { - texture: Some(server.load("flappy/bird.png")), - color: (WHITE - ORANGE).with_alpha(1.0).into(), - alpha_mode: AlphaMode2d::Blend, - ..default() - })); bird_assets.mesh = Mesh2d(meshes.add(Rectangle::new(1.0, 1.2))); } @@ -911,59 +893,3 @@ fn update_tooltip( }) }); } - -fn invert_colors( - camera: Single<&mut Camera>, - mut materials: Query<&mut MeshMaterial2d>, - birds: Query>, - bird_assets: ResMut, - pipes: Query>, - pipe_assets: ResMut, - grounds: Query>, - ground_assets: ResMut, -) { - // Invert bird - birds.iter().for_each(|e| { - *materials.get_mut(e).unwrap() = bird_assets.rewind_material.clone(); - }); - // Set pipes - pipes.iter().for_each(|e| { - *materials.get_mut(e).unwrap() = pipe_assets.rewind_material.clone(); - }); - // Set ground - grounds.iter().for_each(|e| { - *materials.get_mut(e).unwrap() = ground_assets.rewind_material.clone(); - }); - - // Set background color - let mut c = camera.into_inner(); - c.clear_color = ClearColorConfig::Custom(BLACK.into()); -} - -fn uninvert_colors( - camera: Single<&mut Camera>, - mut materials: Query<&mut MeshMaterial2d>, - birds: Query>, - bird_assets: ResMut, - pipes: Query>, - pipe_assets: ResMut, - grounds: Query>, - ground_assets: ResMut, -) { - // Set bird - birds.iter().for_each(|e| { - *materials.get_mut(e).unwrap() = bird_assets.material.clone(); - }); - // Set pipes - pipes.iter().for_each(|e| { - *materials.get_mut(e).unwrap() = pipe_assets.material.clone(); - }); - // Set ground - grounds.iter().for_each(|e| { - *materials.get_mut(e).unwrap() = ground_assets.material.clone(); - }); - - // Set background color - let mut c = camera.into_inner(); - c.clear_color = ClearColorConfig::Custom(WHITE.into()); -}