Upgrade complete?

This commit is contained in:
Daniel Flanagan 2024-05-17 09:57:24 -05:00
parent cf8dbde7c7
commit 6775527467
5 changed files with 38 additions and 33 deletions

View file

@ -37,25 +37,15 @@ fn load_assets(
asset_server: Res<AssetServer>, asset_server: Res<AssetServer>,
mut texture_atlases: ResMut<Assets<TextureAtlasLayout>>, mut texture_atlases: ResMut<Assets<TextureAtlasLayout>>,
) { ) {
let player_img = asset_server.load("img/Player.png"); let player_atlas = TextureAtlasLayout::from_grid(
let props_img = asset_server.load("img/Props.png");
let player_atlas = TextureAtlas::from_grid(
player_img,
Vec2::new(32.0, 64.0), Vec2::new(32.0, 64.0),
3, 3,
1, 1,
Some(Vec2 { x: 0., y: 0. }), Some(Vec2 { x: 0., y: 0. }),
Some(Vec2 { x: 0., y: 0. }), Some(Vec2 { x: 0., y: 0. }),
); );
let statue_atlas = TextureAtlas::from_grid( let statue_atlas =
props_img, TextureAtlasLayout::from_grid(Vec2::new(40., 74.), 1, 1, None, Some(Vec2::new(443., 20.)));
Vec2::new(40., 74.),
1,
1,
None,
Some(Vec2::new(443., 20.)),
);
let player_atlas_handle = texture_atlases.add(player_atlas); let player_atlas_handle = texture_atlases.add(player_atlas);
let statue_atlas_handle = texture_atlases.add(statue_atlas); let statue_atlas_handle = texture_atlases.add(statue_atlas);

View file

@ -29,5 +29,6 @@ fn focus(
} }
fn y_sort(mut q: Query<&mut Transform>) { 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)
} }

View file

@ -22,7 +22,7 @@ fn main() {
..Default::default() ..Default::default()
}) })
.set(AudioPlugin { .set(AudioPlugin {
spatial_scale: SpatialScale::new_2d(1.), default_spatial_scale: SpatialScale::new_2d(1.),
global_volume: GlobalVolume::new(1.), global_volume: GlobalVolume::new(1.),
..default() ..default()
}) })

View file

@ -18,15 +18,17 @@ impl Plugin for Player {
} }
} }
fn spawn_player(mut commands: Commands, assets: Res<AssetLoader>) { fn spawn_player(mut commands: Commands, assets: Res<AssetLoader>, asset_server: Res<AssetServer>) {
let texture = asset_server.load("img/Player.png");
let listener = SpatialListener::new(1.); let listener = SpatialListener::new(1.);
commands commands
.spawn(( .spawn((
Player, Player,
SpriteSheetBundle { SpriteSheetBundle {
texture,
atlas: assets.images.player.clone().into(), atlas: assets.images.player.clone().into(),
sprite: TextureAtlas::new(0), sprite: Sprite::default(),
..Default::default() ..Default::default()
}, },
Mover { Mover {
@ -42,14 +44,15 @@ fn spawn_player(mut commands: Commands, assets: Res<AssetLoader>) {
fn controls( fn controls(
mut commands: Commands, mut commands: Commands,
mut query: Query<(&mut TextureAtlas, &mut Heading, Entity), With<Player>>, mut query: Query<(&mut Sprite, &mut TextureAtlas, &mut Heading, Entity), With<Player>>,
asset_server: Res<AssetServer>,
input: Res<ButtonInput<KeyCode>>, input: Res<ButtonInput<KeyCode>>,
mouse_input: Res<ButtonInput<MouseButton>>, mouse_input: Res<ButtonInput<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>>, q_camera: Query<(&Camera, &GlobalTransform), With<Camera>>,
) { ) {
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(); let (camera, camera_transform) = q_camera.single();
**heading = Vec2::ZERO; **heading = Vec2::ZERO;
for button in mouse_input.get_just_pressed() { for button in mouse_input.get_just_pressed() {
@ -62,11 +65,15 @@ fn controls(
.map(|ray| ray.origin.truncate()) .map(|ray| ray.origin.truncate())
{ {
let spos = world_position.extend(0.); let spos = world_position.extend(0.);
let statue_texture = asset_server.load("img/Props.png").clone();
commands.spawn(( commands.spawn((
Statue, Statue,
SpriteSheetBundle { SpriteSheetBundle {
atlas: assets.images.statue.clone(), texture: statue_texture,
sprite: TextureAtlas::new(0), atlas: TextureAtlas {
layout: assets.images.statue.clone(),
index: 0,
},
transform: Transform::from_translation(spos), transform: Transform::from_translation(spos),
..Default::default() ..Default::default()
}, },
@ -92,27 +99,27 @@ fn controls(
} }
for key in input.get_pressed() { for key in input.get_pressed() {
match key { match key {
KeyCode::A | KeyCode::Left => { KeyCode::KeyA | KeyCode::ArrowLeft => {
**heading -= Vec2::X; **heading -= Vec2::X;
} }
KeyCode::D | KeyCode::Right => { KeyCode::KeyD | KeyCode::ArrowRight => {
**heading += Vec2::X; **heading += Vec2::X;
} }
KeyCode::W | KeyCode::Up => { KeyCode::KeyW | KeyCode::ArrowUp => {
**heading += Vec2::Y; **heading += Vec2::Y;
} }
KeyCode::S | KeyCode::Down => { KeyCode::KeyS | KeyCode::ArrowDown => {
**heading -= Vec2::Y; **heading -= Vec2::Y;
} }
_ => {} _ => {}
} }
} }
if heading.y < 0. { if heading.y < 0. {
sprite.index = 0; texture.index = 0;
} else if heading.y > 0. { } else if heading.y > 0. {
sprite.index = 1; texture.index = 1;
} else if heading.x != 0. { } else if heading.x != 0. {
sprite.index = 2; texture.index = 2;
sprite.flip_x = heading.x > 0.; sprite.flip_x = heading.x > 0.;
} }
} }

View file

@ -11,12 +11,16 @@ impl Plugin for Statue {
} }
} }
fn spawn_statue(mut commands: Commands, assets: Res<AssetLoader>) { fn spawn_statue(mut commands: Commands, assets: Res<AssetLoader>, asset_server: Res<AssetServer>) {
let texture = asset_server.load("img/Props.png");
commands.spawn(( commands.spawn((
Statue, Statue,
SpriteSheetBundle { SpriteSheetBundle {
texture_atlas: assets.images.statue.clone(), texture: texture.clone(),
sprite: TextureAtlas::new(0), atlas: TextureAtlas {
layout: assets.images.statue.clone(),
index: 0,
},
transform: Transform::from_translation(Vec3::new(50., 50., 0.)), transform: Transform::from_translation(Vec3::new(50., 50., 0.)),
..Default::default() ..Default::default()
}, },
@ -24,8 +28,11 @@ fn spawn_statue(mut commands: Commands, assets: Res<AssetLoader>) {
commands.spawn(( commands.spawn((
Statue, Statue,
SpriteSheetBundle { SpriteSheetBundle {
texture_atlas: assets.images.statue.clone(), texture: texture.clone(),
sprite: TextureAtlas::new(0), atlas: TextureAtlas {
layout: assets.images.statue.clone(),
index: 0,
},
transform: Transform::from_translation(Vec3::new(50., 100., 0.)), transform: Transform::from_translation(Vec3::new(50., 100., 0.)),
..Default::default() ..Default::default()
}, },