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