diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index b6dd0bb..0000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -*.ogg filter=lfs diff=lfs merge=lfs -text diff --git a/assets/.gitattributes b/assets/.gitattributes index 86acde7..6070049 100644 --- a/assets/.gitattributes +++ b/assets/.gitattributes @@ -1,2 +1,3 @@ -*.png filter=lfs diff=lfs merge=lfs -text +*.ogg filter=lfs diff=lfs merge=lfs -text *.xcf filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text diff --git a/assets/flappy/CREDITS b/assets/flappy/CREDITS index b9e477f..90e9867 100644 --- a/assets/flappy/CREDITS +++ b/assets/flappy/CREDITS @@ -2,8 +2,10 @@ 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 diff --git a/assets/flappy/background-city.png b/assets/flappy/background-city.png new file mode 100644 index 0000000..e059925 --- /dev/null +++ b/assets/flappy/background-city.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a46a212302c813b07cf0c8d465024824f6543423159260242806a7ceaf84add2 +size 499 diff --git a/assets/flappy/background-city.xcf b/assets/flappy/background-city.xcf new file mode 100644 index 0000000..a6fd1b4 --- /dev/null +++ b/assets/flappy/background-city.xcf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:abdcbf64a5d93bc1b0fc7f631e25e4538e5ec83a662caf4d509b2ba95a009c9f +size 3553 diff --git a/assets/flappy/background-clouds.png b/assets/flappy/background-clouds.png new file mode 100644 index 0000000..b769645 --- /dev/null +++ b/assets/flappy/background-clouds.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:235ead07c9fa7e851779ef68ab9bf9fa08bac4933e0d350c6d4a8b9a1f19affa +size 582 diff --git a/assets/flappy/background-clouds.xcf b/assets/flappy/background-clouds.xcf new file mode 100644 index 0000000..46bc2ab --- /dev/null +++ b/assets/flappy/background-clouds.xcf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ca08cbdd23e8ba7e975c09caea38c17b5bc09631e34f7e7e7196ea11da4e6aa4 +size 2709 diff --git a/examples/parallax.rs b/examples/parallax.rs new file mode 100644 index 0000000..3b3595d --- /dev/null +++ b/examples/parallax.rs @@ -0,0 +1,55 @@ +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>, + keys: Res>, +) { + 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>, +) { + // 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(); + }); +} diff --git a/src/base_game.rs b/src/base_game.rs index bac4b2f..a7f90cd 100644 --- a/src/base_game.rs +++ b/src/base_game.rs @@ -42,6 +42,7 @@ impl Plugin for BaseGamePlugin { .add_plugins(MeshPickingPlugin) .add_plugins(LoadingPlugin) .add_plugins(BaseUiPlugin) + .add_plugins(ParallaxPlugin) .init_resource::(); match self.game_type { diff --git a/src/bin/flappy/main.rs b/src/bin/flappy/main.rs index a88acc3..b27f188 100644 --- a/src/bin/flappy/main.rs +++ b/src/bin/flappy/main.rs @@ -562,7 +562,7 @@ fn init_ui(mut commands: Commands) { BackgroundColor::default(), RewindButton, children![ - Text::new("Rewind!"), + Text::new("Rewind! (R)"), TextLayout::new_with_justify(JustifyText::Center) ], )) @@ -580,7 +580,7 @@ fn init_ui(mut commands: Commands) { Button, FlapButton, children![ - Text::new("Flap!"), + Text::new("Flap! (Spacebar)"), TextFont::from_font_size(30.0), TextLayout::new_with_justify(JustifyText::Center) ], diff --git a/src/lib.rs b/src/lib.rs index 6d36548..63ebc90 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,7 @@ pub mod physics3d; mod scheduling; mod ui; mod version; +mod parallax; // Rust stdlib pub use std::collections::VecDeque; @@ -44,3 +45,4 @@ pub use loading::*; pub use scheduling::*; pub use ui::*; pub use version::*; +pub use parallax::*; diff --git a/src/parallax.rs b/src/parallax.rs new file mode 100644 index 0000000..596b1f3 --- /dev/null +++ b/src/parallax.rs @@ -0,0 +1,27 @@ +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::)); + } +} + +#[derive(Component)] +#[require(Transform)] +pub struct Parallax(pub f32); + +fn move_parallax_items( + mut q: Query<(&mut Transform, &Parallax), Without>, + cam_t: Single<&Transform, With>, +) { + 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; + }); +} +