Doc strings for the batches + children observer pattern

main
Elijah Voigt 3 months ago
parent ec64a3358c
commit dad9c05234

@ -184,6 +184,13 @@ fn init_first_batches(
commands.spawn(Batch(4)); commands.spawn(Batch(4));
} }
/// We have the concept of an environment "batch" which contains:
/// * The ground obstacle
/// * The pipe obstacle
/// * The pipe scoring sensor
///
/// These are all populated via `OnAdd` observers for the respected components.
/// This makes it much more concise to spawn each part of the environment.
fn populate_batch( fn populate_batch(
trigger: Trigger<OnAdd, Batch>, trigger: Trigger<OnAdd, Batch>,
batches: Query<&Batch>, batches: Query<&Batch>,
@ -207,6 +214,8 @@ fn populate_batch(
}); });
} }
/// The ground population spawns a center peace and two pieces of ground
/// to the left and right of the center.
fn populate_ground( fn populate_ground(
trigger: Trigger<OnAdd, Ground>, trigger: Trigger<OnAdd, Ground>,
grounds: Query<&Ground>, grounds: Query<&Ground>,
@ -223,6 +232,8 @@ fn populate_ground(
)); ));
} }
/// 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( fn populate_pipe(
trigger: Trigger<OnAdd, Pipe>, trigger: Trigger<OnAdd, Pipe>,
pipes: Query<&Pipe>, pipes: Query<&Pipe>,
@ -242,6 +253,8 @@ fn populate_pipe(
)); ));
} }
/// The hitbox should cover the entire height of the screen so if the player
/// passes between the pipes it registers a point
fn populate_hitbox( fn populate_hitbox(
trigger: Trigger<OnAdd, Hitbox>, trigger: Trigger<OnAdd, Hitbox>,
mut commands: Commands, mut commands: Commands,
@ -268,6 +281,7 @@ struct PipeComponents {
mesh: Mesh2d, mesh: Mesh2d,
} }
/// Initialize some materials and meshes used by the environment obstacles
fn init_obstacle_assets( fn init_obstacle_assets(
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>, mut materials: ResMut<Assets<ColorMaterial>>,
@ -413,9 +427,6 @@ fn un_pause_game(mut next: ResMut<NextState<PlayerState>>) {
next.set(PlayerState::Alive); next.set(PlayerState::Alive);
} }
// TODO: Create floor (and ceiling?)
// Q: Move bird + camera or move world around bird & camera?
// TODO: Obstacles
#[derive(Component, Clone, Event)] #[derive(Component, Clone, Event)]
struct Flap; struct Flap;

Loading…
Cancel
Save