Can drop statues

This commit is contained in:
Daniel Flanagan 2024-02-02 11:35:18 -06:00
parent 458bd994d6
commit a70e59fdf8
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4

View file

@ -44,25 +44,24 @@ fn controls(
mut commands: Commands, mut commands: Commands,
mut query: Query<(&mut TextureAtlasSprite, &mut Heading, Entity), With<Player>>, mut query: Query<(&mut TextureAtlasSprite, &mut Heading, Entity), With<Player>>,
input: Res<Input<KeyCode>>, input: Res<Input<KeyCode>>,
mouse_input: Res<Input<MouseButton>>,
assets: Res<AssetLoader>, assets: Res<AssetLoader>,
q_windows: Query<&Window, With<PrimaryWindow>>, q_windows: Query<&Window, With<PrimaryWindow>>,
q_camera: Query<(&Camera, &GlobalTransform), With<Camera>>,
) { ) {
let (mut sprite, mut heading, player_entity) = query.single_mut(); let (mut sprite, mut heading, player_entity) = query.single_mut();
let (camera, camera_transform) = q_camera.single();
**heading = Vec2::ZERO; **heading = Vec2::ZERO;
for key in input.get_just_pressed() { for button in mouse_input.get_just_pressed() {
match key { match button {
KeyCode::Space => { MouseButton::Left => {
let child = commands if let Some(world_position) = q_windows
.spawn(AudioSourceBundle { .single()
source: assets.sounds.meow.clone(), .cursor_position()
settings: PlaybackSettings::DESPAWN.with_spatial(false), .and_then(|cursor| camera.viewport_to_world(camera_transform, cursor))
}) .map(|ray| ray.origin.truncate())
.id(); {
commands.entity(player_entity).push_children(&[child]); let spos = world_position.extend(0.);
}
KeyCode::Key1 => {
if let Some(position) = q_windows.single().cursor_position() {
let spos = position.extend(0.);
commands.spawn(( commands.spawn((
Statue, Statue,
SpriteSheetBundle { SpriteSheetBundle {
@ -77,6 +76,20 @@ fn controls(
_ => {} _ => {}
} }
} }
for key in input.get_just_pressed() {
match key {
KeyCode::Space => {
let child = commands
.spawn(AudioSourceBundle {
source: assets.sounds.meow.clone(),
settings: PlaybackSettings::DESPAWN.with_spatial(false),
})
.id();
commands.entity(player_entity).push_children(&[child]);
}
_ => {}
}
}
for key in input.get_pressed() { for key in input.get_pressed() {
match key { match key {
KeyCode::A | KeyCode::Left => { KeyCode::A | KeyCode::Left => {