Extract systems
This commit is contained in:
parent
cef21f4a00
commit
214e0ceedc
9 changed files with 199 additions and 191 deletions
40
src/game/runtime.rs
Normal file
40
src/game/runtime.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use avian2d::prelude::*;
|
||||
use bevy::prelude::*;
|
||||
|
||||
use super::objects::Player;
|
||||
|
||||
pub fn move_player(
|
||||
time: Res<Time>,
|
||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||
mut velocity: Single<&mut LinearVelocity, With<Player>>,
|
||||
) -> Result {
|
||||
let acceleration = 500.0;
|
||||
|
||||
let delta_time = time.delta_secs();
|
||||
|
||||
if keyboard_input.any_pressed([KeyCode::KeyW, KeyCode::ArrowUp]) {
|
||||
velocity.y += acceleration * delta_time;
|
||||
}
|
||||
if keyboard_input.any_pressed([KeyCode::KeyS, KeyCode::ArrowDown]) {
|
||||
velocity.y -= acceleration * delta_time;
|
||||
}
|
||||
if keyboard_input.any_pressed([KeyCode::KeyA, KeyCode::ArrowLeft]) {
|
||||
velocity.x -= acceleration * delta_time;
|
||||
}
|
||||
if keyboard_input.any_pressed([KeyCode::KeyD, KeyCode::ArrowRight]) {
|
||||
velocity.x += acceleration * delta_time;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn quit(mut exit: EventWriter<AppExit>) {
|
||||
exit.write(AppExit::Success);
|
||||
}
|
||||
|
||||
pub fn move_camera(
|
||||
mut camera: Single<&mut Transform, (Without<Player>, With<IsDefaultUiCamera>)>,
|
||||
player: Single<&Transform, (With<Player>, Without<IsDefaultUiCamera>)>,
|
||||
) {
|
||||
camera.translation = camera.translation.lerp(player.translation, 0.05);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue