32 lines
822 B
Rust
32 lines
822 B
Rust
use bevy::prelude::*;
|
|
use leafwing_input_manager::prelude::*;
|
|
|
|
#[derive(Actionlike, PartialEq, Eq, Clone, Copy, Hash, Debug, Reflect)]
|
|
pub enum PlayerAction {
|
|
Move,
|
|
Jump,
|
|
}
|
|
|
|
impl PlayerAction {
|
|
pub fn default_input_map() -> InputMap<Self> {
|
|
let mut input_map = InputMap::default();
|
|
|
|
// Default gamepad input bindings
|
|
input_map.insert(Self::Move, DualAxis::left_stick());
|
|
input_map.insert(Self::Jump, GamepadButtonType::South);
|
|
|
|
// Default kbm input bindings
|
|
input_map.insert(Self::Move, VirtualDPad::wasd());
|
|
input_map.insert(Self::Jump, KeyCode::Space);
|
|
|
|
input_map
|
|
}
|
|
}
|
|
|
|
pub struct InputPlugin;
|
|
impl Plugin for InputPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.add_plugins(InputManagerPlugin::<PlayerAction>::default());
|
|
}
|
|
}
|