|
|
|
@ -9,7 +9,8 @@ fn main() {
|
|
|
|
App::new()
|
|
|
|
App::new()
|
|
|
|
.add_plugins((
|
|
|
|
.add_plugins((
|
|
|
|
BaseGamePlugin {
|
|
|
|
BaseGamePlugin {
|
|
|
|
name: "flappy bird (with rewind)".into(),
|
|
|
|
title: "flappy bird (with rewind)".into(),
|
|
|
|
|
|
|
|
name: "flappy".into(),
|
|
|
|
game_type: GameType::Two,
|
|
|
|
game_type: GameType::Two,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Physics2dPlugin,
|
|
|
|
Physics2dPlugin,
|
|
|
|
@ -561,14 +562,17 @@ fn flap_kb(
|
|
|
|
birds: Query<Entity, With<Bird>>,
|
|
|
|
birds: Query<Entity, With<Bird>>,
|
|
|
|
mut commands: Commands,
|
|
|
|
mut commands: Commands,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
debug_assert!(
|
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
matches!(state.get(), PlayerState::Alive),
|
|
|
|
{
|
|
|
|
"Only flap when playing"
|
|
|
|
debug_assert!(
|
|
|
|
);
|
|
|
|
matches!(state.get(), PlayerState::Alive),
|
|
|
|
debug_assert!(
|
|
|
|
"Only flap when playing"
|
|
|
|
keycode.just_pressed(KeyCode::Space),
|
|
|
|
);
|
|
|
|
"Only flap when space is just pressed"
|
|
|
|
debug_assert!(
|
|
|
|
);
|
|
|
|
keycode.just_pressed(KeyCode::Space),
|
|
|
|
|
|
|
|
"Only flap when space is just pressed"
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
birds.iter().for_each(|e| {
|
|
|
|
birds.iter().for_each(|e| {
|
|
|
|
debug!("Flapping {:?}", e);
|
|
|
|
debug!("Flapping {:?}", e);
|
|
|
|
@ -609,6 +613,7 @@ fn record(
|
|
|
|
With<Bird>,
|
|
|
|
With<Bird>,
|
|
|
|
>,
|
|
|
|
>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
|
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
debug_assert!(
|
|
|
|
debug_assert!(
|
|
|
|
matches!(state.get(), PlayerState::Alive),
|
|
|
|
matches!(state.get(), PlayerState::Alive),
|
|
|
|
"Only record in the alive state"
|
|
|
|
"Only record in the alive state"
|
|
|
|
@ -648,6 +653,7 @@ fn rewind(
|
|
|
|
>,
|
|
|
|
>,
|
|
|
|
mut frames: ResMut<RewindFrames>,
|
|
|
|
mut frames: ResMut<RewindFrames>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
|
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
debug_assert!(
|
|
|
|
debug_assert!(
|
|
|
|
matches!(state.get(), PlayerState::Rewind),
|
|
|
|
matches!(state.get(), PlayerState::Rewind),
|
|
|
|
"Only rewind in the rewinding state"
|
|
|
|
"Only rewind in the rewinding state"
|
|
|
|
@ -684,6 +690,7 @@ fn detect_dead(
|
|
|
|
obstacles: Query<&ColliderAabb, Or<(With<Ground>, With<Pipe>)>>,
|
|
|
|
obstacles: Query<&ColliderAabb, Or<(With<Ground>, With<Pipe>)>>,
|
|
|
|
mut next: ResMut<NextState<PlayerState>>,
|
|
|
|
mut next: ResMut<NextState<PlayerState>>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
|
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
debug_assert!(
|
|
|
|
debug_assert!(
|
|
|
|
matches!(state.get(), PlayerState::Alive),
|
|
|
|
matches!(state.get(), PlayerState::Alive),
|
|
|
|
"Only check if dead while alive"
|
|
|
|
"Only check if dead while alive"
|
|
|
|
@ -698,7 +705,9 @@ fn alive_bird(
|
|
|
|
#[cfg(debug_assertions)] state: Res<State<PlayerState>>,
|
|
|
|
#[cfg(debug_assertions)] state: Res<State<PlayerState>>,
|
|
|
|
mut bird: Single<&mut RigidBody, With<Bird>>,
|
|
|
|
mut bird: Single<&mut RigidBody, With<Bird>>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
|
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
debug_assert!(matches!(state.get(), PlayerState::Alive));
|
|
|
|
debug_assert!(matches!(state.get(), PlayerState::Alive));
|
|
|
|
|
|
|
|
|
|
|
|
debug!("Setting bird to Dynamic");
|
|
|
|
debug!("Setting bird to Dynamic");
|
|
|
|
**bird = RigidBody::Dynamic;
|
|
|
|
**bird = RigidBody::Dynamic;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|