Created
February 22, 2022 16:54
-
-
Save SET001/577880375132b6ebd76196af14f8e174 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use bevy_editor_pls::prelude::*; | |
use bevy::prelude::*; | |
use leafwing_input_manager::{InputManagerBundle, prelude::{ActionState, InputMap}, Actionlike, plugin::InputManagerPlugin}; | |
#[derive(Actionlike, PartialEq, Eq, Clone, Copy, Hash, Debug)] | |
pub enum PlayerAction { | |
Fire, | |
MoveLeft, | |
MoveRight, | |
MoveUp, | |
MoveDown | |
} | |
fn main() { | |
App::new() | |
.insert_resource(WindowDescriptor { | |
title: "Bevy game experiments".to_string(), | |
width: 1000.0, | |
..Default::default() | |
}) | |
.add_plugins(DefaultPlugins) | |
.add_plugin(InputManagerPlugin::<PlayerAction>::default()) | |
.add_plugin(EditorPlugin) | |
.add_startup_system(on_start) | |
.run(); | |
} | |
fn on_start( | |
mut commands: Commands, | |
){ | |
let input_map = InputMap::new([ | |
(PlayerAction::MoveLeft, KeyCode::Left), | |
]) | |
.build(); | |
commands.spawn_bundle(InputManagerBundle::<PlayerAction> { | |
action_state: ActionState::default(), | |
input_map: input_map | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment