This commit is contained in:
parent
57db0aff22
commit
6aeda8be14
7 changed files with 171 additions and 19 deletions
16
src/kirby.rs
16
src/kirby.rs
|
|
@ -10,14 +10,9 @@ pub struct Kirby {
|
|||
|
||||
pub fn kirby_spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
let sprite = Sprite::from_image(asset_server.load("sprites/kirby.png"));
|
||||
let body = PhysicsBody {
|
||||
mass: 10.0,
|
||||
force: Vec2::ZERO,
|
||||
velocity: Vec2::ZERO,
|
||||
drag: 0.05,
|
||||
};
|
||||
let body = PhysicsBody { mass: 10.0, force: Vec2::ZERO, velocity: Vec2::ZERO, drag: 0.05 };
|
||||
let transform = Transform::from_xyz(0.0, 0.0, 0.0).with_scale(Vec3::ONE * 0.25);
|
||||
commands.spawn((Kirby { speed_force: 50.0 }, transform, sprite, body));
|
||||
commands.spawn((Kirby { speed_force: 10000.0 }, transform, sprite, body));
|
||||
}
|
||||
|
||||
pub fn get_dir(keys: Res<ButtonInput<KeyCode>>) -> Vec2 {
|
||||
|
|
@ -43,16 +38,13 @@ pub fn get_dir(keys: Res<ButtonInput<KeyCode>>) -> Vec2 {
|
|||
dir.normalize_or_zero()
|
||||
}
|
||||
|
||||
pub fn kirby_player_move(
|
||||
keys: Res<ButtonInput<KeyCode>>,
|
||||
mut query: Query<(&mut PhysicsBody, &Kirby), With<Kirby>>,
|
||||
) {
|
||||
pub fn kirby_player_move(keys: Res<ButtonInput<KeyCode>>, mut query: Query<(&mut PhysicsBody, &Kirby), With<Kirby>>) {
|
||||
if keys.pressed(KeyCode::Space) {
|
||||
println!("SUCKING");
|
||||
}
|
||||
let dir = get_dir(keys);
|
||||
for (mut body, kirby) in &mut query {
|
||||
body.velocity += dir * kirby.speed_force;
|
||||
body.force += dir * kirby.speed_force;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue