Upgrade complete?
This commit is contained in:
parent
cf8dbde7c7
commit
6775527467
|
@ -37,25 +37,15 @@ fn load_assets(
|
|||
asset_server: Res<AssetServer>,
|
||||
mut texture_atlases: ResMut<Assets<TextureAtlasLayout>>,
|
||||
) {
|
||||
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);
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
})
|
||||
|
|
|
@ -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.);
|
||||
|
||||
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<AssetLoader>) {
|
|||
|
||||
fn controls(
|
||||
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>>,
|
||||
mouse_input: Res<ButtonInput<MouseButton>>,
|
||||
assets: Res<AssetLoader>,
|
||||
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 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.;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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((
|
||||
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<AssetLoader>) {
|
|||
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()
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue