From 8566a46347abda9e8430c609bdbc9bf8a2162e3b Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Thu, 7 Aug 2025 16:13:51 -0700 Subject: [PATCH] credits --- assets/flappy/CREDITS | 9 +++ src/bin/flappy/main.rs | 136 +++++++++++++++++++++++++++++++---------- 2 files changed, 112 insertions(+), 33 deletions(-) create mode 100644 assets/flappy/CREDITS diff --git a/assets/flappy/CREDITS b/assets/flappy/CREDITS new file mode 100644 index 0000000..dd853fc --- /dev/null +++ b/assets/flappy/CREDITS @@ -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 diff --git a/src/bin/flappy/main.rs b/src/bin/flappy/main.rs index 6a721be..e58aaaa 100644 --- a/src/bin/flappy/main.rs +++ b/src/bin/flappy/main.rs @@ -113,6 +113,8 @@ enum PlayerState { Alive, Rewind, Stasis, + // Kind of a hack, but we need a state for this + Credits, #[default] Pause, } @@ -335,45 +337,104 @@ fn init_obstacle_assets( } fn init_ui(mut commands: Commands) { - commands.spawn(( - Node { - align_self: AlignSelf::Center, - justify_self: JustifySelf::Center, - flex_direction: FlexDirection::Column, - ..default() - }, - PlayerState::Stasis, - children![ - ( - Text::new("You Died"), - TextLayout::new_with_justify(JustifyText::Center) - ), - ( + commands + .spawn(( + Node { + align_self: AlignSelf::Center, + justify_self: JustifySelf::Center, + flex_direction: FlexDirection::Column, + ..default() + }, + PlayerState::Stasis, + )) + .with_children(|parent| { + parent.spawn(( + Text::new("Game Over...?"), + TextLayout::new_with_justify(JustifyText::Center), + )); + parent.spawn(( SyncResource::::default(), Text::default(), - TextLayout::new_with_justify(JustifyText::Center) - ), - ( + TextLayout::new_with_justify(JustifyText::Center), + )); + parent.spawn(( SyncResource::::default(), Text::default(), - TextLayout::new_with_justify(JustifyText::Center) - ), - ( + TextLayout::new_with_justify(JustifyText::Center), + )); + parent.spawn(( SyncResource::::default(), Text::default(), - TextLayout::new_with_justify(JustifyText::Center) - ), - ( + TextLayout::new_with_justify(JustifyText::Center), + )); + parent.spawn(( SyncResource::::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>, + mut exit: EventWriter, + ) { + warn!("Quitting game"); + exit.write(AppExit::Success); + } + + fn show_credits( + _trigger: Trigger>, + mut state: ResMut>, + ) { + 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>, mut state: ResMut>) { + 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>, mut next: ResMut>) { next.set(PlayerState::Alive); @@ -707,7 +768,6 @@ fn manage_score( } } - fn debug_collision_events( mut end: EventReader, mut start: EventReader, @@ -725,14 +785,24 @@ fn debug_collision_start_observations( trigger: Trigger, state: Res>, ) { - 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, state: Res>, ) { - 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