|
|
|
@ -113,6 +113,8 @@ enum PlayerState {
|
|
|
|
Alive,
|
|
|
|
Alive,
|
|
|
|
Rewind,
|
|
|
|
Rewind,
|
|
|
|
Stasis,
|
|
|
|
Stasis,
|
|
|
|
|
|
|
|
// Kind of a hack, but we need a state for this
|
|
|
|
|
|
|
|
Credits,
|
|
|
|
#[default]
|
|
|
|
#[default]
|
|
|
|
Pause,
|
|
|
|
Pause,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -335,7 +337,8 @@ fn init_obstacle_assets(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn init_ui(mut commands: Commands) {
|
|
|
|
fn init_ui(mut commands: Commands) {
|
|
|
|
commands.spawn((
|
|
|
|
commands
|
|
|
|
|
|
|
|
.spawn((
|
|
|
|
Node {
|
|
|
|
Node {
|
|
|
|
align_self: AlignSelf::Center,
|
|
|
|
align_self: AlignSelf::Center,
|
|
|
|
justify_self: JustifySelf::Center,
|
|
|
|
justify_self: JustifySelf::Center,
|
|
|
|
@ -343,37 +346,95 @@ fn init_ui(mut commands: Commands) {
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PlayerState::Stasis,
|
|
|
|
PlayerState::Stasis,
|
|
|
|
children![
|
|
|
|
))
|
|
|
|
(
|
|
|
|
.with_children(|parent| {
|
|
|
|
Text::new("You Died"),
|
|
|
|
parent.spawn((
|
|
|
|
TextLayout::new_with_justify(JustifyText::Center)
|
|
|
|
Text::new("Game Over...?"),
|
|
|
|
),
|
|
|
|
TextLayout::new_with_justify(JustifyText::Center),
|
|
|
|
(
|
|
|
|
));
|
|
|
|
|
|
|
|
parent.spawn((
|
|
|
|
SyncResource::<Score>::default(),
|
|
|
|
SyncResource::<Score>::default(),
|
|
|
|
Text::default(),
|
|
|
|
Text::default(),
|
|
|
|
TextLayout::new_with_justify(JustifyText::Center)
|
|
|
|
TextLayout::new_with_justify(JustifyText::Center),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
(
|
|
|
|
parent.spawn((
|
|
|
|
SyncResource::<Flaps>::default(),
|
|
|
|
SyncResource::<Flaps>::default(),
|
|
|
|
Text::default(),
|
|
|
|
Text::default(),
|
|
|
|
TextLayout::new_with_justify(JustifyText::Center)
|
|
|
|
TextLayout::new_with_justify(JustifyText::Center),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
(
|
|
|
|
parent.spawn((
|
|
|
|
SyncResource::<RewindFrames>::default(),
|
|
|
|
SyncResource::<RewindFrames>::default(),
|
|
|
|
Text::default(),
|
|
|
|
Text::default(),
|
|
|
|
TextLayout::new_with_justify(JustifyText::Center)
|
|
|
|
TextLayout::new_with_justify(JustifyText::Center),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
(
|
|
|
|
parent.spawn((
|
|
|
|
SyncResource::<Deaths>::default(),
|
|
|
|
SyncResource::<Deaths>::default(),
|
|
|
|
Text::default(),
|
|
|
|
Text::default(),
|
|
|
|
TextLayout::new_with_justify(JustifyText::Center)
|
|
|
|
TextLayout::new_with_justify(JustifyText::Center),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
(
|
|
|
|
parent.spawn((
|
|
|
|
Text::new("Press R to Rewind"),
|
|
|
|
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>>) {
|
|
|
|
fn start_game(_trigger: Trigger<Pointer<Click>>, mut next: ResMut<NextState<PlayerState>>) {
|
|
|
|
next.set(PlayerState::Alive);
|
|
|
|
next.set(PlayerState::Alive);
|
|
|
|
@ -707,7 +768,6 @@ fn manage_score(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn debug_collision_events(
|
|
|
|
fn debug_collision_events(
|
|
|
|
mut end: EventReader<CollisionEnded>,
|
|
|
|
mut end: EventReader<CollisionEnded>,
|
|
|
|
mut start: EventReader<CollisionStarted>,
|
|
|
|
mut start: EventReader<CollisionStarted>,
|
|
|
|
@ -725,14 +785,24 @@ fn debug_collision_start_observations(
|
|
|
|
trigger: Trigger<OnCollisionStart>,
|
|
|
|
trigger: Trigger<OnCollisionStart>,
|
|
|
|
state: Res<State<PlayerState>>,
|
|
|
|
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(
|
|
|
|
fn debug_collision_end_observations(
|
|
|
|
trigger: Trigger<OnCollisionEnd>,
|
|
|
|
trigger: Trigger<OnCollisionEnd>,
|
|
|
|
state: Res<State<PlayerState>>,
|
|
|
|
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
|
|
|
|
/// When the player moves forward while alive
|
|
|
|
|