|
|
|
@ -101,6 +101,7 @@ fn main() {
|
|
|
|
.add_observer(flap)
|
|
|
|
.add_observer(flap)
|
|
|
|
.add_observer(populate_batch)
|
|
|
|
.add_observer(populate_batch)
|
|
|
|
.add_observer(populate_pipe)
|
|
|
|
.add_observer(populate_pipe)
|
|
|
|
|
|
|
|
.add_observer(move_pipe)
|
|
|
|
.add_observer(populate_ground)
|
|
|
|
.add_observer(populate_ground)
|
|
|
|
.add_observer(populate_ceiling)
|
|
|
|
.add_observer(populate_ceiling)
|
|
|
|
.add_observer(populate_hitbox)
|
|
|
|
.add_observer(populate_hitbox)
|
|
|
|
@ -110,7 +111,7 @@ fn main() {
|
|
|
|
fn tweak_camera(camera: Single<(Entity, &mut Camera)>, mut commands: Commands) {
|
|
|
|
fn tweak_camera(camera: Single<(Entity, &mut Camera)>, mut commands: Commands) {
|
|
|
|
debug!("Tweaking camera");
|
|
|
|
debug!("Tweaking camera");
|
|
|
|
let (e, mut c) = camera.into_inner();
|
|
|
|
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() });
|
|
|
|
commands.entity(e).insert(ColorGrading { ..default() });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -340,18 +341,49 @@ fn populate_ceiling(
|
|
|
|
));
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn move_pipe(
|
|
|
|
|
|
|
|
trigger: Trigger<OnInsert, Batch>,
|
|
|
|
|
|
|
|
mut pipes: Query<(&Batch, &Pipe, &mut Transform)>,
|
|
|
|
|
|
|
|
rand: Res<Rand>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
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
|
|
|
|
/// Based on if this is a Top or Bottom pipe the placement changes
|
|
|
|
/// Otherwise this just spawns in the center of the batch.
|
|
|
|
/// Otherwise this just spawns in the center of the batch.
|
|
|
|
fn populate_pipe(
|
|
|
|
fn populate_pipe(
|
|
|
|
trigger: Trigger<OnAdd, Pipe>,
|
|
|
|
trigger: Trigger<OnAdd, Pipe>,
|
|
|
|
pipes: Query<(&Pipe, &Batch)>,
|
|
|
|
pipes: Query<(&Batch, &Pipe)>,
|
|
|
|
pipe_assets: Res<PipeAssets>,
|
|
|
|
pipe_assets: Res<PipeAssets>,
|
|
|
|
mut commands: Commands,
|
|
|
|
mut commands: Commands,
|
|
|
|
rand: Res<Rand>,
|
|
|
|
rand: Res<Rand>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
let pipe_t = {
|
|
|
|
let pipe_t = {
|
|
|
|
let (pipe, Batch(id)) = pipes.get(trigger.target()).unwrap();
|
|
|
|
let (Batch(id), pipe) = pipes.get(trigger.target()).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let offset = {
|
|
|
|
let offset = {
|
|
|
|
let val = rand.0.hash_one(id);
|
|
|
|
let val = rand.0.hash_one(id);
|
|
|
|
|
|
|
|
|
|
|
|
@ -374,6 +406,7 @@ fn populate_pipe(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
commands.entity(trigger.target()).insert((
|
|
|
|
commands.entity(trigger.target()).insert((
|
|
|
|
pipe_t,
|
|
|
|
pipe_t,
|
|
|
|
pipe_assets.material.clone(),
|
|
|
|
pipe_assets.material.clone(),
|
|
|
|
@ -440,14 +473,14 @@ fn init_assets(
|
|
|
|
|
|
|
|
|
|
|
|
ground_assets.material = MeshMaterial2d(materials.add(ColorMaterial {
|
|
|
|
ground_assets.material = MeshMaterial2d(materials.add(ColorMaterial {
|
|
|
|
texture: Some(server.load("flappy/ground.png")),
|
|
|
|
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()
|
|
|
|
..default()
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
ground_assets.mesh = Mesh2d(meshes.add(Rectangle::new(1.0, 1.0)));
|
|
|
|
ground_assets.mesh = Mesh2d(meshes.add(Rectangle::new(1.0, 1.0)));
|
|
|
|
|
|
|
|
|
|
|
|
ceiling_assets.material = MeshMaterial2d(materials.add(ColorMaterial {
|
|
|
|
ceiling_assets.material = MeshMaterial2d(materials.add(ColorMaterial {
|
|
|
|
texture: Some(server.load("flappy/ceiling.png")),
|
|
|
|
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()
|
|
|
|
..default()
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
ceiling_assets.mesh = Mesh2d(meshes.add(Rectangle::new(1.0, 0.777)));
|
|
|
|
ceiling_assets.mesh = Mesh2d(meshes.add(Rectangle::new(1.0, 0.777)));
|
|
|
|
|