From a9a4d2215322a74a746415007c00929631b65a4b Mon Sep 17 00:00:00 2001 From: Jan Hohenheim Date: Mon, 8 Jul 2024 03:04:04 +0200 Subject: [PATCH 01/27] Move player spawning to game --- src/game/mod.rs | 5 ++++- src/game/spawn_level.rs | 25 +++++++++++++++++++++++++ src/screen/playing.rs | 11 +++-------- 3 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 src/game/spawn_level.rs diff --git a/src/game/mod.rs b/src/game/mod.rs index 993202a3..4445fe9b 100644 --- a/src/game/mod.rs +++ b/src/game/mod.rs @@ -1,7 +1,10 @@ //! Game mechanics and content. use bevy::prelude::*; +pub(crate) use spawn_level::SpawnLevel; + +mod spawn_level; pub(super) fn plugin(app: &mut App) { - let _ = app; + app.add_plugins(spawn_level::plugin); } diff --git a/src/game/spawn_level.rs b/src/game/spawn_level.rs new file mode 100644 index 00000000..0f0cd990 --- /dev/null +++ b/src/game/spawn_level.rs @@ -0,0 +1,25 @@ +use bevy::prelude::*; + +use crate::screen::Screen; + +#[derive(Debug, Event)] +pub(crate) struct SpawnLevel; + +pub(super) fn plugin(app: &mut App) { + app.observe(spawn_level); +} + +fn spawn_level( + _trigger: Trigger, + mut commands: Commands, + asset_server: Res, +) { + commands.spawn(( + Name::new("Player"), + SpriteBundle { + texture: asset_server.load("ducky.png"), + ..Default::default() + }, + StateScoped(Screen::Playing), + )); +} diff --git a/src/screen/playing.rs b/src/screen/playing.rs index 62add4aa..4458984e 100644 --- a/src/screen/playing.rs +++ b/src/screen/playing.rs @@ -3,6 +3,7 @@ use bevy::{input::common_conditions::input_just_pressed, prelude::*}; use super::Screen; +use crate::game::SpawnLevel; pub(super) fn plugin(app: &mut App) { app.add_systems(OnEnter(Screen::Playing), enter_playing) @@ -15,14 +16,8 @@ pub(super) fn plugin(app: &mut App) { ); } -fn enter_playing(mut commands: Commands, asset_server: Res) { - commands.spawn(( - SpriteBundle { - texture: asset_server.load("ducky.png"), - ..Default::default() - }, - StateScoped(Screen::Playing), - )); +fn enter_playing(mut commands: Commands) { + commands.trigger(SpawnLevel); } // TODO: Reset camera transform here. From eef00af77aa177943514da4cfd5d8c5eff7db6bc Mon Sep 17 00:00:00 2001 From: Jan Hohenheim Date: Mon, 8 Jul 2024 12:57:33 +0200 Subject: [PATCH 02/27] Add movement mod --- src/game/mod.rs | 10 +++++++++- src/game/movement.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/game/movement.rs diff --git a/src/game/mod.rs b/src/game/mod.rs index 4445fe9b..b62742fb 100644 --- a/src/game/mod.rs +++ b/src/game/mod.rs @@ -3,8 +3,16 @@ use bevy::prelude::*; pub(crate) use spawn_level::SpawnLevel; +mod movement; mod spawn_level; pub(super) fn plugin(app: &mut App) { - app.add_plugins(spawn_level::plugin); + app.configure_sets(Update, GameSystem::Movement); + + app.add_plugins((spawn_level::plugin, movement::plugin)); +} + +#[derive(Debug, SystemSet, Clone, Copy, Eq, PartialEq, Hash)] +enum GameSystem { + Movement, } diff --git a/src/game/movement.rs b/src/game/movement.rs new file mode 100644 index 00000000..4e7a9742 --- /dev/null +++ b/src/game/movement.rs @@ -0,0 +1,28 @@ +use bevy::prelude::*; + +pub(super) fn plugin(app: &mut App) {} + +fn move_player( + time: Res