input fixes!

This commit is contained in:
2021-10-14 19:22:23 +02:00
parent 35f3d0e4a8
commit 5365097f3b
3 changed files with 24 additions and 9 deletions

View File

@@ -54,9 +54,11 @@ impl Game for TestGame {
let objs = &mut self.game_objects;
let components = &mut self.components;
components.iter_mut().for_each(|component| {
component.update(frame_time, &input, renderer, objs);
});
if !self.paused {
components.iter_mut().for_each(|component| {
component.update(frame_time, &input, renderer, objs);
});
}
// User interaction
if self.input.button_just_released("quit") {
@@ -123,7 +125,7 @@ impl TestGame {
pub fn new(toml_path: &str, log_config: LogConfig) -> TestGame {
TestGame {
input: InputState::new(toml_path, log_config),
player: Player::new(),
player: Player::new(3., 30.),
game_objects: vec![],
text_objects: vec![],
log_config,

View File

@@ -112,12 +112,12 @@ pub struct Player {
}
impl Player {
pub fn new() -> Player {
pub fn new(movement_speed: f32, look_sensitivity: f32) -> Player {
Player {
camera: Camera::new(),
movement_mode: Flying,
movement_speed: 3.0,
look_sensitivity: 30.0,
movement_speed,
look_sensitivity,
height: 1.0,
x_look: 0.0,
y_look: 0.0

View File

@@ -655,7 +655,7 @@ pub enum AxisInput {
Touch(TouchAxis)
}
#[derive(Debug, Eq, PartialEq, Hash, Clone)]
#[derive(Debug, Eq, PartialEq, Clone, Hash)]
pub enum DigitalInput {
Keyboard(KeyboardInput),
Wheel(WheelInput),
@@ -663,13 +663,26 @@ pub enum DigitalInput {
Controller(ControllerInput),
}
#[derive(Debug, Eq, PartialEq, Hash, Clone)]
#[derive(Debug, Eq, Clone)]
pub struct KeyboardInput {
scan_code: ScanCode,
key_code: Option<VirtualKeyCode>,
modifiers: KeyboardModifierState,
}
impl PartialEq for KeyboardInput {
fn eq(&self, other: &Self) -> bool {
(self.scan_code == other.scan_code || (self.key_code != None && self.key_code == other.key_code)) && self.modifiers == other.modifiers
}
}
impl Hash for KeyboardInput {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.scan_code.hash(state);
self.modifiers.hash(state);
}
}
#[derive(Debug, Eq, PartialEq, Hash, Clone)]
pub struct MouseInput {
button: MouseButton,