work on player not moving due to bad query
This commit is contained in:
parent
f2c604e489
commit
d42483f166
1 changed files with 104 additions and 108 deletions
|
@ -24,28 +24,26 @@ pub fn startup(
|
|||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
) {
|
||||
let listener = SpatialListener::new(1.);
|
||||
|
||||
commands
|
||||
.spawn((Player, YSortable, Watched))
|
||||
.with_children(|player| {
|
||||
player.spawn((
|
||||
SpriteBundle {
|
||||
texture: assets.images.player.clone().into(),
|
||||
..default()
|
||||
},
|
||||
TextureAtlas {
|
||||
layout: assets.layouts.player.clone().into(),
|
||||
..default()
|
||||
},
|
||||
Mover {
|
||||
velocity: Velocity(Vec2::ZERO),
|
||||
heading: Heading(Vec2::ZERO),
|
||||
speed: Speed(PLAYER_SPEED),
|
||||
},
|
||||
));
|
||||
player.spawn((SpatialBundle::default(), listener.clone()));
|
||||
player.spawn(Text2dBundle {
|
||||
.spawn((
|
||||
// Player,
|
||||
// YSortable,
|
||||
// Watched,
|
||||
// SpriteBundle {
|
||||
// texture: assets.images.player.clone().into(),
|
||||
// ..default()
|
||||
// },
|
||||
// TextureAtlas {
|
||||
// layout: assets.layouts.player.clone().into(),
|
||||
// ..default()
|
||||
// },
|
||||
// Mover {
|
||||
// velocity: Velocity(Vec2::ZERO),
|
||||
// heading: Heading(Vec2::ZERO),
|
||||
// speed: Speed(PLAYER_SPEED),
|
||||
// },
|
||||
// (SpatialBundle::default(), SpatialListener::new(1.)),
|
||||
Text2dBundle {
|
||||
text: Text::from_section(
|
||||
"You",
|
||||
TextStyle {
|
||||
|
@ -57,34 +55,35 @@ pub fn startup(
|
|||
),
|
||||
transform: Transform::from_translation(Vec3::new(30.0, -30.0, 0.)),
|
||||
..default()
|
||||
});
|
||||
},
|
||||
))
|
||||
.with_children(|player| {
|
||||
// let mesh = Mesh2dHandle(meshes.add(Capsule2d::new(3.0, 25.0)));
|
||||
// let material = materials.add(Color::hsl(360. * 1 as f32 / 3 as f32, 0.95, 0.7));
|
||||
// // let global_transform = GlobalTransform::from_xyz(
|
||||
// // 0.0, 20.0,
|
||||
// // // TODO: need some way to ensure this draws above everything else?
|
||||
// // // a UI layer or something?
|
||||
// // 1000.,
|
||||
// // );
|
||||
|
||||
let mesh = Mesh2dHandle(meshes.add(Capsule2d::new(3.0, 25.0)));
|
||||
let material = materials.add(Color::hsl(360. * 1 as f32 / 3 as f32, 0.95, 0.7));
|
||||
// let global_transform = GlobalTransform::from_xyz(
|
||||
// 0.0, 20.0,
|
||||
// let transform = Transform::from_xyz(
|
||||
// 0.0, 0.0,
|
||||
// // TODO: need some way to ensure this draws above everything else?
|
||||
// // a UI layer or something?
|
||||
// 1000.,
|
||||
// );
|
||||
|
||||
let transform = Transform::from_xyz(
|
||||
0.0, 0.0,
|
||||
// TODO: need some way to ensure this draws above everything else?
|
||||
// a UI layer or something?
|
||||
1000.,
|
||||
);
|
||||
|
||||
player.spawn((
|
||||
Crosshair,
|
||||
MaterialMesh2dBundle {
|
||||
// global_transform,
|
||||
mesh,
|
||||
material,
|
||||
transform,
|
||||
..default()
|
||||
},
|
||||
));
|
||||
// player.spawn((
|
||||
// Crosshair,
|
||||
// MaterialMesh2dBundle {
|
||||
// // global_transform,
|
||||
// mesh,
|
||||
// material,
|
||||
// transform,
|
||||
// ..default()
|
||||
// },
|
||||
// ));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -99,15 +98,13 @@ pub fn controls(
|
|||
mut next_state: ResMut<NextState<crate::View>>,
|
||||
mut crosshair_q: Query<&mut Transform, With<Crosshair>>,
|
||||
) {
|
||||
if let Ok((mut sprite, mut texture, mut heading, player_entity)) = player_q.get_single_mut() {
|
||||
let (mut sprite, mut texture, mut heading, player_entity) = player_q.single_mut();
|
||||
let (camera, camera_transform) = cam_q.single();
|
||||
|
||||
let mouse_world_position = win_q
|
||||
.single()
|
||||
.cursor_position()
|
||||
.and_then(|cursor| {
|
||||
camera.viewport_to_world(&GlobalTransform::from_xyz(0., 0., 0.), cursor)
|
||||
})
|
||||
.and_then(|cursor| camera.viewport_to_world(&GlobalTransform::from_xyz(0., 0., 0.), cursor))
|
||||
.map(|ray| ray.origin.truncate());
|
||||
|
||||
if let Some(pos) = mouse_world_position {
|
||||
|
@ -176,7 +173,6 @@ pub fn controls(
|
|||
sprite.flip_x = heading.x > 0.;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sprite_select(
|
||||
mut q: Query<(&Handle<TextureAtlasLayout>, &mut TextureAtlas), With<Player>>,
|
||||
|
|
Loading…
Reference in a new issue