Pipes extend off the screen

main
Elijah Voigt 3 months ago
parent f900f3b388
commit c48be4d41b

BIN
assets/flappy/pipe.png (Stored with Git LFS)

Binary file not shown.

@ -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<OnAdd, Hitbox>, mut commands: Commands) {
#[derive(Resource, Default)]
struct BirdAssets {
material: MeshMaterial2d<ColorMaterial>,
rewind_material: MeshMaterial2d<ColorMaterial>,
mesh: Mesh2d,
}
#[derive(Resource, Default)]
struct GroundAssets {
material: MeshMaterial2d<ColorMaterial>,
rewind_material: MeshMaterial2d<ColorMaterial>,
mesh: Mesh2d,
}
#[derive(Resource, Default)]
struct PipeAssets {
material: MeshMaterial2d<ColorMaterial>,
rewind_material: MeshMaterial2d<ColorMaterial>,
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<ColorMaterial>>,
birds: Query<Entity, With<Bird>>,
bird_assets: ResMut<BirdAssets>,
pipes: Query<Entity, With<Pipe>>,
pipe_assets: ResMut<PipeAssets>,
grounds: Query<Entity, With<Ground>>,
ground_assets: ResMut<GroundAssets>,
) {
// 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<ColorMaterial>>,
birds: Query<Entity, With<Bird>>,
bird_assets: ResMut<BirdAssets>,
pipes: Query<Entity, With<Pipe>>,
pipe_assets: ResMut<PipeAssets>,
grounds: Query<Entity, With<Ground>>,
ground_assets: ResMut<GroundAssets>,
) {
// 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());
}

Loading…
Cancel
Save