rust_fisher_game/src/player.rs
Ahmet Kaan Gümüş 650217a746 feat: inventory panel
2025-02-19 04:31:26 +03:00

42 lines
1.3 KiB
Rust

use bevy::prelude::*;
use crate::{PlayerGUIStatus, CHARACTER_SPEED};
#[derive(Debug, Component)]
pub struct Player;
impl Player {
pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let image = asset_server.load::<Image>("character.png");
commands.spawn((
Sprite::from_image(image),
Transform::from_xyz(0.0, 0.0, 0.0),
Player,
));
}
pub fn r#move(
time: Res<Time>,
mut player_query: Query<&mut Transform, With<Player>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
player_gui_status: Res<PlayerGUIStatus>,
) {
if !player_gui_status.looking_inventory {
let mut player = player_query.get_single_mut().unwrap();
let translation = CHARACTER_SPEED * time.delta_secs();
if keyboard_input.pressed(KeyCode::KeyW) {
player.translation.y += translation;
}
if keyboard_input.pressed(KeyCode::KeyS) {
player.translation.y -= translation;
}
if keyboard_input.pressed(KeyCode::KeyA) {
player.translation.x -= translation;
}
if keyboard_input.pressed(KeyCode::KeyD) {
player.translation.x += translation;
}
}
}
}