feat: inventory panel

This commit is contained in:
Ahmet Kaan Gümüş 2025-02-19 04:31:26 +03:00
parent 9f52e24582
commit 650217a746
7 changed files with 125 additions and 52 deletions

View file

@ -1,12 +1,9 @@
use bevy::prelude::*;
use crate::CHARACTER_SPEED;
use crate::{PlayerGUIStatus, CHARACTER_SPEED};
#[derive(Debug, Component)]
pub struct Player {
pub fish_count: usize,
pub money: usize,
}
pub struct Player;
impl Player {
pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
@ -14,10 +11,7 @@ impl Player {
commands.spawn((
Sprite::from_image(image),
Transform::from_xyz(0.0, 0.0, 0.0),
Player {
fish_count: 0,
money: 0,
},
Player,
));
}
@ -25,21 +19,24 @@ impl Player {
time: Res<Time>,
mut player_query: Query<&mut Transform, With<Player>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
player_gui_status: Res<PlayerGUIStatus>,
) {
let mut player = player_query.get_single_mut().unwrap();
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;
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;
}
}
}
}