use bevy::{ input::keyboard::{KeyboardInput, VirtualKeyCode}, prelude::*, }; fn main() { App::build() .add_default_plugins() .init_resource::() .add_system(collect_input_system.system()) .add_system(move_system.system()) .add_startup_system(setup) .run(); } #[derive(Resource)] struct State { event_reader: EventReader, moving_right: bool, moving_left: bool, } /// adjusts move state based on keyboard input fn collect_input_system( mut state: ResourceMut, keyboard_input_events: Resource>, ) { for event in state.event_reader.iter(&keyboard_input_events) { match event { KeyboardInput { virtual_key_code: Some(VirtualKeyCode::Left), state: element_state, .. } => { state.moving_left = element_state.is_pressed(); } KeyboardInput { virtual_key_code: Some(VirtualKeyCode::Right), state: element_state, .. } => { state.moving_right = element_state.is_pressed(); } _ => {} } } } /// moves our cube left when the "left" key is pressed. moves it right when the "right" key is pressed fn move_system( state: Resource, time: Resource