Get flappy bird (with rewind) working in web

main
Elijah Voigt 3 months ago
parent 15cb9ae49b
commit 5f4a170a05

@ -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,
}

@ -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<Entity, With<Bird>>,
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<Bird>,
>,
) {
#[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<RewindFrames>,
) {
#[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<Ground>, With<Pipe>)>>,
mut next: ResMut<NextState<PlayerState>>,
) {
#[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<State<PlayerState>>,
mut bird: Single<&mut RigidBody, With<Bird>>,
) {
#[cfg(debug_assertions)]
debug_assert!(matches!(state.get(), PlayerState::Alive));
debug!("Setting bird to Dynamic");
**bird = RigidBody::Dynamic;
}

@ -0,0 +1,15 @@
<!doctype html>
<html lang="en">
<body>
<canvas id="flappy-canvas"></canvas>
<script type="module">
import init from './bin.js'
init().catch((error) => {
if (!error.message.startsWith("Using exceptions for control flow, don't mind me. This isn't actually an error!")) {
throw error;
}
});
</script>
</body>
</html>
Loading…
Cancel
Save