From 67755274675ba99faf9960849abb3d9e0e8230ea Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Fri, 17 May 2024 09:57:24 -0500 Subject: [PATCH] Upgrade complete? --- src/assets.rs | 16 +++------------- src/camera.rs | 3 ++- src/main.rs | 2 +- src/player.rs | 33 ++++++++++++++++++++------------- src/statue.rs | 17 ++++++++++++----- 5 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/assets.rs b/src/assets.rs index 3814ce2..48ca4c0 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -37,25 +37,15 @@ fn load_assets( asset_server: Res, mut texture_atlases: ResMut>, ) { - let player_img = asset_server.load("img/Player.png"); - let props_img = asset_server.load("img/Props.png"); - - let player_atlas = TextureAtlas::from_grid( - player_img, + let player_atlas = TextureAtlasLayout::from_grid( Vec2::new(32.0, 64.0), 3, 1, Some(Vec2 { x: 0., y: 0. }), Some(Vec2 { x: 0., y: 0. }), ); - let statue_atlas = TextureAtlas::from_grid( - props_img, - Vec2::new(40., 74.), - 1, - 1, - None, - Some(Vec2::new(443., 20.)), - ); + let statue_atlas = + TextureAtlasLayout::from_grid(Vec2::new(40., 74.), 1, 1, None, Some(Vec2::new(443., 20.))); let player_atlas_handle = texture_atlases.add(player_atlas); let statue_atlas_handle = texture_atlases.add(statue_atlas); diff --git a/src/camera.rs b/src/camera.rs index ae8ab4d..965a7bf 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -29,5 +29,6 @@ fn focus( } fn y_sort(mut q: Query<&mut Transform>) { - q.for_each_mut(|mut tf| tf.translation.z = -tf.translation.y) + q.iter_mut() + .for_each(|mut tf| tf.translation.z = -tf.translation.y) } diff --git a/src/main.rs b/src/main.rs index b701393..0559e75 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,7 @@ fn main() { ..Default::default() }) .set(AudioPlugin { - spatial_scale: SpatialScale::new_2d(1.), + default_spatial_scale: SpatialScale::new_2d(1.), global_volume: GlobalVolume::new(1.), ..default() }) diff --git a/src/player.rs b/src/player.rs index f8d2432..d340a0d 100644 --- a/src/player.rs +++ b/src/player.rs @@ -18,15 +18,17 @@ impl Plugin for Player { } } -fn spawn_player(mut commands: Commands, assets: Res) { +fn spawn_player(mut commands: Commands, assets: Res, asset_server: Res) { + let texture = asset_server.load("img/Player.png"); let listener = SpatialListener::new(1.); commands .spawn(( Player, SpriteSheetBundle { + texture, atlas: assets.images.player.clone().into(), - sprite: TextureAtlas::new(0), + sprite: Sprite::default(), ..Default::default() }, Mover { @@ -42,14 +44,15 @@ fn spawn_player(mut commands: Commands, assets: Res) { fn controls( mut commands: Commands, - mut query: Query<(&mut TextureAtlas, &mut Heading, Entity), With>, + mut query: Query<(&mut Sprite, &mut TextureAtlas, &mut Heading, Entity), With>, + asset_server: Res, input: Res>, mouse_input: Res>, assets: Res, q_windows: Query<&Window, With>, q_camera: Query<(&Camera, &GlobalTransform), With>, ) { - let (mut sprite, mut heading, player_entity) = query.single_mut(); + let (mut sprite, mut texture, mut heading, player_entity) = query.single_mut(); let (camera, camera_transform) = q_camera.single(); **heading = Vec2::ZERO; for button in mouse_input.get_just_pressed() { @@ -62,11 +65,15 @@ fn controls( .map(|ray| ray.origin.truncate()) { let spos = world_position.extend(0.); + let statue_texture = asset_server.load("img/Props.png").clone(); commands.spawn(( Statue, SpriteSheetBundle { - atlas: assets.images.statue.clone(), - sprite: TextureAtlas::new(0), + texture: statue_texture, + atlas: TextureAtlas { + layout: assets.images.statue.clone(), + index: 0, + }, transform: Transform::from_translation(spos), ..Default::default() }, @@ -92,27 +99,27 @@ fn controls( } for key in input.get_pressed() { match key { - KeyCode::A | KeyCode::Left => { + KeyCode::KeyA | KeyCode::ArrowLeft => { **heading -= Vec2::X; } - KeyCode::D | KeyCode::Right => { + KeyCode::KeyD | KeyCode::ArrowRight => { **heading += Vec2::X; } - KeyCode::W | KeyCode::Up => { + KeyCode::KeyW | KeyCode::ArrowUp => { **heading += Vec2::Y; } - KeyCode::S | KeyCode::Down => { + KeyCode::KeyS | KeyCode::ArrowDown => { **heading -= Vec2::Y; } _ => {} } } if heading.y < 0. { - sprite.index = 0; + texture.index = 0; } else if heading.y > 0. { - sprite.index = 1; + texture.index = 1; } else if heading.x != 0. { - sprite.index = 2; + texture.index = 2; sprite.flip_x = heading.x > 0.; } } diff --git a/src/statue.rs b/src/statue.rs index 17468e6..b6c0987 100644 --- a/src/statue.rs +++ b/src/statue.rs @@ -11,12 +11,16 @@ impl Plugin for Statue { } } -fn spawn_statue(mut commands: Commands, assets: Res) { +fn spawn_statue(mut commands: Commands, assets: Res, asset_server: Res) { + let texture = asset_server.load("img/Props.png"); commands.spawn(( Statue, SpriteSheetBundle { - texture_atlas: assets.images.statue.clone(), - sprite: TextureAtlas::new(0), + texture: texture.clone(), + atlas: TextureAtlas { + layout: assets.images.statue.clone(), + index: 0, + }, transform: Transform::from_translation(Vec3::new(50., 50., 0.)), ..Default::default() }, @@ -24,8 +28,11 @@ fn spawn_statue(mut commands: Commands, assets: Res) { commands.spawn(( Statue, SpriteSheetBundle { - texture_atlas: assets.images.statue.clone(), - sprite: TextureAtlas::new(0), + texture: texture.clone(), + atlas: TextureAtlas { + layout: assets.images.statue.clone(), + index: 0, + }, transform: Transform::from_translation(Vec3::new(50., 100., 0.)), ..Default::default() },