Skip to content

Commit

Permalink
Improve example scene
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasEi committed Mar 3, 2023
1 parent 0f01516 commit a1b7974
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions examples/spacial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ fn main() {
.run()
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>, audio: Res<Audio>) {
fn setup(
mut commands: Commands,
asset_server: Res<AssetServer>,
audio: Res<Audio>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// Emitter Nr. 1
let cooking = audio
.play(asset_server.load("sounds/cooking.ogg"))
.with_volume(0.2)
.looped()
.handle();
commands
Expand All @@ -28,6 +34,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, audio: Res<Audi
.insert(AudioEmitter {
instances: vec![cooking],
});
// Emitter Nr. 2
let elevator_music = audio
.play(asset_server.load("sounds/loop.ogg"))
.looped()
Expand All @@ -41,7 +48,16 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, audio: Res<Audi
.insert(AudioEmitter {
instances: vec![elevator_music],
});
// Our camera will be the receiver
commands
.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.0, 0.5, 10.0),
..default()
})
.insert(AudioReceiver)
.insert(FlyCam);

// Other scene setup...
commands.spawn(PointLightBundle {
point_light: PointLight {
intensity: 1500.0,
Expand All @@ -51,11 +67,27 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, audio: Res<Audi
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
commands
.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.0, 0.0, 10.0),
..default()
})
.insert(AudioReceiver)
.insert(FlyCam);
commands.spawn( TextBundle {
text: Text {
sections: vec![TextSection {
value: "WASD to move horizontally\nSPACE to ascend\nLSHIFT to descend\nESC to grab/release cursor.".to_string(),
style: TextStyle {
font: asset_server.load("fonts/monogram.ttf"),
font_size: 40.0,
color: Color::rgb(0.9, 0.9, 0.9),
},
}],
alignment: Default::default(),
},
style: Style {
margin: UiRect::all(Val::Px(15.)),
..default()
},
..default()
});
commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane { size: 50. }.into()),
material: materials.add(Color::DARK_GREEN.into()),
..default()
});
}

0 comments on commit a1b7974

Please sign in to comment.