Compare commits

..

No commits in common. '8c440317e70233971f47af420ddef882ff0361db' and 'a2367fb4f74b65b7d133f4f0e897d06a82c5e406' have entirely different histories.

1
.gitattributes vendored

@ -0,0 +1 @@
*.ogg filter=lfs diff=lfs merge=lfs -text

@ -1,3 +1,2 @@
*.ogg filter=lfs diff=lfs merge=lfs -text
*.xcf filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.xcf filter=lfs diff=lfs merge=lfs -text

@ -2,10 +2,8 @@ Programming: Elijah Voigt
Art Assets: Kenney.nl
1-Bit Platformer Pack
Impact Sounds
Engine: Bevy
Physics: Avian2D
Inspired by:
Flappy Bird (2013) by Dong Nguyen
Inspired by Flappy Bird (2013) by Dong Nguyen

BIN
assets/flappy/background-city.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/flappy/background-city.xcf (Stored with Git LFS)

Binary file not shown.

BIN
assets/flappy/background-clouds.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/flappy/background-clouds.xcf (Stored with Git LFS)

Binary file not shown.

@ -1,55 +0,0 @@
use games::*;
fn main() {
App::new()
.add_plugins((BaseGamePlugin {
name: "parallax example".into(),
title: "Parallax".into(),
game_type: GameType::Two,
},))
.add_systems(Startup, spawn_background)
.add_systems(Update, move_camera)
.add_systems(Update, parallax_gizmos)
.run();
}
fn spawn_background(
mut commands: Commands,
) {
commands.spawn((Parallax(1.0), children![(Text2d("1.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))]));
commands.spawn((Parallax(2.0), children![(Text2d("2.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))]));
commands.spawn((Parallax(4.0), children![(Text2d("4.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))]));
commands.spawn((Parallax(8.0), children![(Text2d("8.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))]));
}
fn move_camera(
mut t: Single<&mut Transform, With<Camera2d>>,
keys: Res<ButtonInput<KeyCode>>,
) {
if keys.pressed(KeyCode::ArrowLeft) {
t.translation.x -= 5.0;
} else if keys.pressed(KeyCode::ArrowRight) {
t.translation.x += 5.0;
}
if keys.pressed(KeyCode::ArrowDown) {
t.translation.y -= 5.0;
} else if keys.pressed(KeyCode::ArrowUp) {
t.translation.y += 5.0;
}
}
fn parallax_gizmos(
mut gizmos: Gizmos,
q: Query<&Transform, With<Parallax>>,
) {
// Closest to camera
// Parallax(1)
q.iter().for_each(|t| {
gizmos.grid_2d(
t.translation.truncate(),
UVec2::new(5, 5),
Vec2::splat(10.),
RED,
).outer_edges();
});
}

@ -42,7 +42,6 @@ impl Plugin for BaseGamePlugin {
.add_plugins(MeshPickingPlugin)
.add_plugins(LoadingPlugin)
.add_plugins(BaseUiPlugin)
.add_plugins(ParallaxPlugin)
.init_resource::<Rand>();
match self.game_type {

@ -39,11 +39,9 @@ fn main() {
),
)
.add_systems(OnEnter(PlayerState::Alive), alive_bird)
.add_systems(OnEnter(PlayerState::Alive), reset_button::<FlapButton>)
.add_systems(OnEnter(PlayerState::Rewind), (start_rewinding, alive_bird))
.add_systems(OnEnter(PlayerState::Pause), pause_bird)
.add_systems(OnEnter(PlayerState::Stasis), pause_bird)
.add_systems(OnExit(PlayerState::Stasis), reset_button::<RewindButton>)
.add_systems(
Update,
(
@ -87,13 +85,14 @@ fn main() {
sync_resource_to_ui::<Deaths>.run_if(resource_changed::<Deaths>),
sync_resource_to_ui::<RewindFrames>.run_if(resource_changed::<RewindFrames>),
),
(update_tooltip, debug_trail).run_if(in_state(DebuggingState::On)),
(
update_tooltip,
debug_trail,
).run_if(in_state(DebuggingState::On)),
// TODO: Add run_if to this system
update_batch_position.run_if(any_component_changed::<Batch>),
move_batches.run_if(on_event::<CollisionStarted>),
manage_score.run_if(on_event::<CollisionStarted>.or(on_event::<CollisionEnded>)),
shimmer_button::<RewindButton>.run_if(in_state(PlayerState::Stasis)),
shimmer_button::<FlapButton>.run_if(in_state(PlayerState::Pause)),
),
)
.add_observer(flap)
@ -140,7 +139,10 @@ struct Tape {
rotations: Vec<Rotation>,
}
fn init_bird(mut commands: Commands, bird_assets: Res<BirdAssets>) {
fn init_bird(
mut commands: Commands,
bird_assets: Res<BirdAssets>,
) {
let name = Name::new("bird");
let t = Transform::from_xyz(0.0, 0.0, 0.0).with_scale(Vec3::splat(50.0));
@ -405,18 +407,12 @@ fn init_assets(
#[derive(Component)]
struct FlapSfx;
#[derive(Component)]
struct FlapButton;
#[derive(Component)]
struct BonkSfx;
#[derive(Component)]
struct RewindSfx;
#[derive(Component)]
struct RewindButton;
fn init_ui(mut commands: Commands) {
commands
.spawn((
@ -528,63 +524,39 @@ fn init_ui(mut commands: Commands) {
next.set(PlayerState::Alive);
}
commands.spawn((
commands
.spawn((
Node {
align_self: AlignSelf::Center,
justify_self: JustifySelf::Center,
flex_direction: FlexDirection::Column,
..default()
},
Button,
PlayerState::Pause,
Text::new("PAUSED"),
));
children![Text::new("Go!"),],
))
.observe(start_game);
commands
.spawn(Node {
align_self: AlignSelf::End,
justify_self: JustifySelf::Center,
flex_direction: FlexDirection::Row,
justify_content: JustifyContent::SpaceEvenly,
width: Val::Percent(100.0),
min_height: Val::Percent(10.0),
..default()
})
.with_children(|parent| {
parent
.spawn((
Node {
width: Val::Percent(50.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
Node { ..default() },
Button,
BackgroundColor::default(),
RewindButton,
children![
Text::new("Rewind! (R)"),
TextLayout::new_with_justify(JustifyText::Center)
],
children![Text::new("Rewind!"),],
))
.observe(start_rewind)
.observe(end_rewind);
parent
.spawn((
Node {
width: Val::Percent(50.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
Button,
FlapButton,
children![
Text::new("Flap! (Spacebar)"),
TextFont::from_font_size(30.0),
TextLayout::new_with_justify(JustifyText::Center)
],
))
.spawn((Node { ..default() }, Button, children![Text::new("Flap!"),]))
.observe(flap_button);
});
@ -595,11 +567,9 @@ fn init_ui(mut commands: Commands) {
..default()
},
BackgroundColor(WHITE.into()),
children![(
SyncResource::<Score>::default(),
Text::default(),
TextLayout::new_with_justify(JustifyText::Center),
)]
));
}
@ -615,12 +585,7 @@ fn flap_button(
_trigger: Trigger<Pointer<Pressed>>,
mut commands: Commands,
bird: Single<Entity, With<Bird>>,
curr: Res<State<PlayerState>>,
mut next: ResMut<NextState<PlayerState>>,
) {
if !matches!(curr.get(), PlayerState::Alive) {
next.set(PlayerState::Alive);
}
let e = *bird;
debug!("Flapping {:?}", e);
commands.trigger_targets(Flap, e);
@ -657,10 +622,7 @@ fn flap(
// Play flap sfx
commands.spawn((
AudioPlayer::new(server.load("flappy/bonk.ogg")),
PlaybackSettings {
mode: PlaybackMode::Despawn,
..default()
},
PlaybackSettings { mode: PlaybackMode::Despawn, ..default() },
BonkSfx,
));
}
@ -818,10 +780,7 @@ fn detect_dead(
// Play bonk sfx
commands.spawn((
AudioPlayer::new(server.load("flappy/flap.ogg")),
PlaybackSettings {
mode: PlaybackMode::Despawn,
..default()
},
PlaybackSettings { mode: PlaybackMode::Despawn, ..default() },
FlapSfx,
));
}
@ -953,7 +912,7 @@ fn move_batches(
} else if hitboxes.contains(*a) {
*a
} else {
return;
return
}
};
@ -1003,7 +962,7 @@ fn update_tooltip(
}
fn debug_trail(
mut physics_objects: Query<(Entity, &Transform), With<Mass>>,
mut physics_objects: Query<(Entity ,&Transform), With<Mass>>,
mut gizmos: Gizmos,
mut positions: Local<HashMap<Entity, VecDeque<Vec3>>>,
) {
@ -1025,26 +984,13 @@ fn debug_trail(
})
}
fn start_rewinding(server: ResMut<AssetServer>, mut commands: Commands) {
fn start_rewinding(
server: ResMut<AssetServer>,
mut commands: Commands,
) {
commands.spawn((
AudioPlayer::new(server.load("flappy/rewind-start.ogg")),
PlaybackSettings {
mode: PlaybackMode::Despawn,
..default()
},
PlaybackSettings { mode: PlaybackMode::Despawn, ..default() },
RewindSfx,
));
}
fn shimmer_button<T: Component>(mut bg: Single<&mut BackgroundColor, With<T>>, time: Res<Time>) {
let t = time.elapsed_secs();
let period = 3.0;
let r = (((t / period) % 1.0) * std::f32::consts::PI).cos();
let g = ((((t / period) + 0.3) % 1.0) * std::f32::consts::PI).cos();
let b = ((((t / period) + 0.6) % 1.0) * std::f32::consts::PI).cos();
bg.0 = Srgba::rgb(r, g, b).into();
}
fn reset_button<T: Component>(mut bg: Single<&mut BackgroundColor, With<T>>) {
bg.0 = WHITE.into();
}

@ -9,12 +9,11 @@ pub mod physics3d;
mod scheduling;
mod ui;
mod version;
mod parallax;
// Rust stdlib
pub use std::collections::VecDeque;
pub use std::f32::consts::PI;
pub use std::fmt::Display;
pub use std::collections::VecDeque;
// Community libraries
pub use bevy::{
@ -45,4 +44,3 @@ pub use loading::*;
pub use scheduling::*;
pub use ui::*;
pub use version::*;
pub use parallax::*;

@ -1,27 +0,0 @@
use super::*;
pub struct ParallaxPlugin;
impl Plugin for ParallaxPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Update, move_parallax_items.run_if(any_component_changed::<Transform>));
}
}
#[derive(Component)]
#[require(Transform)]
pub struct Parallax(pub f32);
fn move_parallax_items(
mut q: Query<(&mut Transform, &Parallax), Without<Camera2d>>,
cam_t: Single<&Transform, With<Camera2d>>,
) {
let base = cam_t.translation.truncate();
q.iter_mut().for_each(|(mut t, p)| {
let val = base * (1.0 - (1.0 / p.0));
t.translation.x = val.x;
t.translation.y = val.y;
});
}
Loading…
Cancel
Save