Compare commits
2 Commits
04fe103b25
...
9e16c22eb5
Author | SHA1 | Date | |
---|---|---|---|
9e16c22eb5 | |||
66854be921 |
@ -8,3 +8,9 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = { version = "0.5", features = ["dynamic"] }
|
bevy = { version = "0.5", features = ["dynamic"] }
|
||||||
|
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
opt-level = 3
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
opt-level = 1
|
||||||
|
@ -19,5 +19,6 @@ fn main() {
|
|||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_startup_system(setup.system())
|
.add_startup_system(setup.system())
|
||||||
.add_startup_system(add_player.system())
|
.add_startup_system(add_player.system())
|
||||||
|
.add_system(player_movement.system())
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,35 @@ pub fn add_player(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn player_movement(
|
||||||
|
keyboard_input: Res<Input<KeyCode>>,
|
||||||
|
mut query: Query<(&Player, &mut Transform)>,
|
||||||
|
time: Res<Time>,
|
||||||
|
) {
|
||||||
|
if let Ok((_, mut transform)) = query.single_mut() {
|
||||||
|
let mut direction = Vec2::ZERO;
|
||||||
|
|
||||||
|
if keyboard_input.pressed(KeyCode::A) {
|
||||||
|
direction.x -= 1.0;
|
||||||
|
}
|
||||||
|
if keyboard_input.pressed(KeyCode::D) {
|
||||||
|
direction.x += 1.0;
|
||||||
|
}
|
||||||
|
if keyboard_input.pressed(KeyCode::S) {
|
||||||
|
direction.y -= 1.0;
|
||||||
|
}
|
||||||
|
if keyboard_input.pressed(KeyCode::W) {
|
||||||
|
direction.y += 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
let translation = &mut transform.translation;
|
||||||
|
let delta_seconds = time.delta_seconds();
|
||||||
|
|
||||||
|
translation.x += delta_seconds * direction.x * 100.0;
|
||||||
|
translation.y += delta_seconds * direction.y * 100.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn greet_player(
|
pub fn greet_player(
|
||||||
query: Query<&Name, With<Player>>,
|
query: Query<&Name, With<Player>>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user