main
Elijah Voigt 3 months ago
parent 6f3b4f7e82
commit 8566a46347

@ -0,0 +1,9 @@
Programming: Elijah Voigt
Art Assets: Kenney.nl
1-Bit Platformer Pack
Engine: Bevy
Physics: Avian2D
Inspired by the 2013 Flappy Bird by Dong Nguyen

@ -113,6 +113,8 @@ enum PlayerState {
Alive,
Rewind,
Stasis,
// Kind of a hack, but we need a state for this
Credits,
#[default]
Pause,
}
@ -335,7 +337,8 @@ fn init_obstacle_assets(
}
fn init_ui(mut commands: Commands) {
commands.spawn((
commands
.spawn((
Node {
align_self: AlignSelf::Center,
justify_self: JustifySelf::Center,
@ -343,37 +346,95 @@ fn init_ui(mut commands: Commands) {
..default()
},
PlayerState::Stasis,
children![
(
Text::new("You Died"),
TextLayout::new_with_justify(JustifyText::Center)
),
(
))
.with_children(|parent| {
parent.spawn((
Text::new("Game Over...?"),
TextLayout::new_with_justify(JustifyText::Center),
));
parent.spawn((
SyncResource::<Score>::default(),
Text::default(),
TextLayout::new_with_justify(JustifyText::Center)
),
(
TextLayout::new_with_justify(JustifyText::Center),
));
parent.spawn((
SyncResource::<Flaps>::default(),
Text::default(),
TextLayout::new_with_justify(JustifyText::Center)
),
(
TextLayout::new_with_justify(JustifyText::Center),
));
parent.spawn((
SyncResource::<RewindFrames>::default(),
Text::default(),
TextLayout::new_with_justify(JustifyText::Center)
),
(
TextLayout::new_with_justify(JustifyText::Center),
));
parent.spawn((
SyncResource::<Deaths>::default(),
Text::default(),
TextLayout::new_with_justify(JustifyText::Center)
),
(
TextLayout::new_with_justify(JustifyText::Center),
));
parent.spawn((
Text::new("Press R to Rewind"),
TextLayout::new_with_justify(JustifyText::Center)
),
],
TextLayout::new_with_justify(JustifyText::Center),
));
parent
.spawn((Node {
flex_direction: FlexDirection::Row,
justify_content: JustifyContent::SpaceEvenly,
..default()
},))
.with_children(|parent| {
fn quit_game(
_trigger: Trigger<Pointer<Click>>,
mut exit: EventWriter<AppExit>,
) {
warn!("Quitting game");
exit.write(AppExit::Success);
}
fn show_credits(
_trigger: Trigger<Pointer<Click>>,
mut state: ResMut<NextState<PlayerState>>,
) {
state.set(PlayerState::Credits);
}
parent
.spawn((
Button,
Node { ..default() },
children![Text::new("Credits")],
))
.observe(show_credits);
parent
.spawn((Button, Node { ..default() }, children![Text::new("Quit"),]))
.observe(quit_game);
});
});
fn hide_credits(_trigger: Trigger<Pointer<Click>>, mut state: ResMut<NextState<PlayerState>>) {
state.set(PlayerState::Stasis)
}
let credits_str = include_str!("../../../assets/flappy/CREDITS");
commands
.spawn((
Node {
align_self: AlignSelf::Center,
justify_self: JustifySelf::Center,
flex_direction: FlexDirection::Column,
..default()
},
PlayerState::Credits,
children![(Text::new(credits_str), TextLayout::new_with_justify(JustifyText::Center))],
))
.with_children(|parent| {
parent.spawn((Node {
align_self: AlignSelf::End,
justify_self: JustifySelf::End,
..default()
}, Button, children![Text::new("Close")]));
}).observe(hide_credits);
fn start_game(_trigger: Trigger<Pointer<Click>>, mut next: ResMut<NextState<PlayerState>>) {
next.set(PlayerState::Alive);
@ -707,7 +768,6 @@ fn manage_score(
}
}
fn debug_collision_events(
mut end: EventReader<CollisionEnded>,
mut start: EventReader<CollisionStarted>,
@ -725,14 +785,24 @@ fn debug_collision_start_observations(
trigger: Trigger<OnCollisionStart>,
state: Res<State<PlayerState>>,
) {
debug!("Collision started between {} and {} in {:?}", trigger.target(), trigger.collider, state.get());
debug!(
"Collision started between {} and {} in {:?}",
trigger.target(),
trigger.collider,
state.get()
);
}
fn debug_collision_end_observations(
trigger: Trigger<OnCollisionEnd>,
state: Res<State<PlayerState>>,
) {
debug!("Collision end between {} and {} in {:?}", trigger.target(), trigger.collider, state.get());
debug!(
"Collision end between {} and {} in {:?}",
trigger.target(),
trigger.collider,
state.get()
);
}
/// When the player moves forward while alive

Loading…
Cancel
Save