Add gamepad
This commit is contained in:
parent
954e3d3b8b
commit
70ce8c3887
23
src/main.rs
23
src/main.rs
@ -1,6 +1,7 @@
|
||||
use bevy::{prelude::*, window::{PrimaryMonitor, PrimaryWindow}};
|
||||
use bevy::{prelude::*, window::PrimaryWindow};
|
||||
use rand::{rngs::ThreadRng, thread_rng, Rng};
|
||||
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(
|
||||
@ -104,7 +105,7 @@ fn update_obstacles(
|
||||
}
|
||||
|
||||
fn spawn_obstacles(
|
||||
mut commands: &mut Commands,
|
||||
commands: &mut Commands,
|
||||
rand: &mut ThreadRng,
|
||||
window_width: f32,
|
||||
pipe_image: &Handle<Image>
|
||||
@ -155,9 +156,23 @@ fn update_bird(
|
||||
time: Res<Time>,
|
||||
keys: Res<ButtonInput<KeyCode>>,
|
||||
game_manager: Res<GameManager>,
|
||||
gamepads: Query<(Entity, &Gamepad)>
|
||||
){
|
||||
let mut hit_jump = false;
|
||||
|
||||
for (_entity, gamepad) in &gamepads {
|
||||
if gamepad.just_pressed(GamepadButton::South) {
|
||||
hit_jump = true;
|
||||
}
|
||||
}
|
||||
|
||||
if keys.just_pressed(KeyCode::Space) {
|
||||
hit_jump = true;
|
||||
}
|
||||
|
||||
if let Ok((mut bird, mut transform)) = bird_query.get_single_mut(){
|
||||
if keys.just_pressed(KeyCode::Space) {
|
||||
|
||||
if hit_jump {
|
||||
bird.velocity = FLAP_FORCE;
|
||||
}
|
||||
|
||||
@ -194,4 +209,6 @@ fn update_bird(
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user