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