From 5f4a170a05c810dbd039abc05e6b2a83b562c02e Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Fri, 8 Aug 2025 12:49:23 -0700 Subject: [PATCH] Get flappy bird (with rewind) working in web --- src/base_game.rs | 2 ++ src/bin/flappy/main.rs | 27 ++++++++++++++++++--------- web/flappy.html | 15 +++++++++++++++ 3 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 web/flappy.html diff --git a/src/base_game.rs b/src/base_game.rs index c302b24..bac4b2f 100644 --- a/src/base_game.rs +++ b/src/base_game.rs @@ -4,6 +4,7 @@ use super::*; /// A good starting place for creating a game building on top of the base Bevy app pub struct BaseGamePlugin { + pub title: String, pub name: String, pub game_type: GameType, } @@ -16,6 +17,7 @@ pub enum GameType { impl Default for BaseGamePlugin { fn default() -> Self { BaseGamePlugin { + title: "My Game".into(), name: "mygame".into(), game_type: GameType::Three, } diff --git a/src/bin/flappy/main.rs b/src/bin/flappy/main.rs index 6d30f60..9d51f52 100644 --- a/src/bin/flappy/main.rs +++ b/src/bin/flappy/main.rs @@ -9,7 +9,8 @@ fn main() { App::new() .add_plugins(( BaseGamePlugin { - name: "flappy bird (with rewind)".into(), + title: "flappy bird (with rewind)".into(), + name: "flappy".into(), game_type: GameType::Two, }, Physics2dPlugin, @@ -561,14 +562,17 @@ fn flap_kb( birds: Query>, mut commands: Commands, ) { - debug_assert!( - matches!(state.get(), PlayerState::Alive), - "Only flap when playing" - ); - debug_assert!( - keycode.just_pressed(KeyCode::Space), - "Only flap when space is just pressed" - ); + #[cfg(debug_assertions)] + { + debug_assert!( + matches!(state.get(), PlayerState::Alive), + "Only flap when playing" + ); + debug_assert!( + keycode.just_pressed(KeyCode::Space), + "Only flap when space is just pressed" + ); + } birds.iter().for_each(|e| { debug!("Flapping {:?}", e); @@ -609,6 +613,7 @@ fn record( With, >, ) { + #[cfg(debug_assertions)] debug_assert!( matches!(state.get(), PlayerState::Alive), "Only record in the alive state" @@ -648,6 +653,7 @@ fn rewind( >, mut frames: ResMut, ) { + #[cfg(debug_assertions)] debug_assert!( matches!(state.get(), PlayerState::Rewind), "Only rewind in the rewinding state" @@ -684,6 +690,7 @@ fn detect_dead( obstacles: Query<&ColliderAabb, Or<(With, With)>>, mut next: ResMut>, ) { + #[cfg(debug_assertions)] debug_assert!( matches!(state.get(), PlayerState::Alive), "Only check if dead while alive" @@ -698,7 +705,9 @@ fn alive_bird( #[cfg(debug_assertions)] state: Res>, mut bird: Single<&mut RigidBody, With>, ) { + #[cfg(debug_assertions)] debug_assert!(matches!(state.get(), PlayerState::Alive)); + debug!("Setting bird to Dynamic"); **bird = RigidBody::Dynamic; } diff --git a/web/flappy.html b/web/flappy.html new file mode 100644 index 0000000..79e8a89 --- /dev/null +++ b/web/flappy.html @@ -0,0 +1,15 @@ + + + + + + +