-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use custom commands instead of observers for spawning (#242)
Co-authored-by: Ben Frankel <[email protected]>
- Loading branch information
1 parent
00d39a8
commit 3ec03f0
Showing
4 changed files
with
44 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
//! Spawn the main level by triggering other observers. | ||
//! Spawn the main level. | ||
use bevy::prelude::*; | ||
use bevy::{ecs::world::Command, prelude::*}; | ||
|
||
use super::player::SpawnPlayer; | ||
|
||
pub(super) fn plugin(app: &mut App) { | ||
app.observe(spawn_level); | ||
pub(super) fn plugin(_app: &mut App) { | ||
// No setup required for this plugin. | ||
// It's still good to have a function here so that we can add some setup | ||
// later if needed. | ||
} | ||
|
||
#[derive(Event, Debug)] | ||
#[derive(Debug)] | ||
pub struct SpawnLevel; | ||
|
||
fn spawn_level(_trigger: Trigger<SpawnLevel>, mut commands: Commands) { | ||
// The only thing we have in our level is a player, | ||
// but add things like walls etc. here. | ||
commands.trigger(SpawnPlayer); | ||
impl Command for SpawnLevel { | ||
fn apply(self, world: &mut World) { | ||
// The only thing we have in our level is a player, | ||
// but add things like walls etc. here. | ||
world.commands().add(SpawnPlayer { max_speed: 400.0 }); | ||
|
||
// Flush the commands we just added so that they are | ||
// all executed now, as part of this command. | ||
world.flush_commands(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters