feat: ✨ ui
This commit is contained in:
parent
cca4b205f5
commit
2b0edc9c50
5 changed files with 157 additions and 42 deletions
|
@ -3,37 +3,39 @@ use bevy::prelude::*;
|
|||
use crate::CHARACTER_SPEED;
|
||||
|
||||
#[derive(Debug, Component)]
|
||||
pub struct Player;
|
||||
pub struct Player {
|
||||
pub fish_count: usize,
|
||||
}
|
||||
|
||||
impl Player {
|
||||
pub fn setup_player(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
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,
|
||||
Player { fish_count: 0 },
|
||||
));
|
||||
}
|
||||
|
||||
pub fn move_player(
|
||||
pub fn r#move(
|
||||
time: Res<Time>,
|
||||
mut character_transform: Query<&mut Transform, With<Player>>,
|
||||
mut player_query: Query<&mut Transform, With<Player>>,
|
||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||
) {
|
||||
let mut character_transform = character_transform.get_single_mut().unwrap();
|
||||
let mut player = player_query.get_single_mut().unwrap();
|
||||
|
||||
let translation = CHARACTER_SPEED * time.delta_secs();
|
||||
if keyboard_input.pressed(KeyCode::KeyW) {
|
||||
character_transform.translation.y += translation;
|
||||
player.translation.y += translation;
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::KeyS) {
|
||||
character_transform.translation.y -= translation;
|
||||
player.translation.y -= translation;
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::KeyA) {
|
||||
character_transform.translation.x -= translation;
|
||||
player.translation.x -= translation;
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::KeyD) {
|
||||
character_transform.translation.x += translation;
|
||||
player.translation.x += translation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue