Catlook
This commit is contained in:
parent
46e125da03
commit
ebce25c379
|
@ -19,6 +19,9 @@ const PLAYER_SPEED: f32 = 500.;
|
||||||
#[derive(Component, Debug)]
|
#[derive(Component, Debug)]
|
||||||
pub struct Player;
|
pub struct Player;
|
||||||
|
|
||||||
|
#[derive(Component, Debug)]
|
||||||
|
pub struct PlayerSprite;
|
||||||
|
|
||||||
#[derive(Component, Debug)]
|
#[derive(Component, Debug)]
|
||||||
pub struct Crosshair;
|
pub struct Crosshair;
|
||||||
|
|
||||||
|
@ -58,6 +61,7 @@ pub fn startup(
|
||||||
))
|
))
|
||||||
.with_children(|player| {
|
.with_children(|player| {
|
||||||
player.spawn((
|
player.spawn((
|
||||||
|
PlayerSprite,
|
||||||
Name::new("PlayerSprite"),
|
Name::new("PlayerSprite"),
|
||||||
SpriteBundle {
|
SpriteBundle {
|
||||||
texture: assets.load("img/Player.png"),
|
texture: assets.load("img/Player.png"),
|
||||||
|
@ -107,10 +111,21 @@ pub fn control(
|
||||||
input: Res<Input>,
|
input: Res<Input>,
|
||||||
mut crosshair: Query<&mut Transform, With<Crosshair>>,
|
mut crosshair: Query<&mut Transform, With<Crosshair>>,
|
||||||
mut player: Query<&mut Heading, With<Player>>,
|
mut player: Query<&mut Heading, With<Player>>,
|
||||||
|
mut sprite: Query<(&mut Sprite, &mut TextureAtlas), With<PlayerSprite>>,
|
||||||
// time: Res<Time>,
|
// time: Res<Time>,
|
||||||
) {
|
) {
|
||||||
if let Ok(mut heading) = player.get_single_mut() {
|
if let Ok(mut heading) = player.get_single_mut() {
|
||||||
heading.0 = input.movement;
|
heading.0 = input.movement;
|
||||||
|
if let Ok((mut sprite, mut texture)) = sprite.get_single_mut() {
|
||||||
|
if heading.y < 0. {
|
||||||
|
texture.index = 0;
|
||||||
|
} else if heading.y > 0. {
|
||||||
|
texture.index = 1;
|
||||||
|
} else if heading.x != 0. {
|
||||||
|
texture.index = 2;
|
||||||
|
sprite.flip_x = heading.x > 0.;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Ok(mut transform) = crosshair.get_single_mut() {
|
if let Ok(mut transform) = crosshair.get_single_mut() {
|
||||||
transform.rotation = Quat::from_rotation_z(input.angle - (TAU / 4.));
|
transform.rotation = Quat::from_rotation_z(input.angle - (TAU / 4.));
|
||||||
|
|
Loading…
Reference in a new issue