Struct babalcore::InputSteer[][src]

pub struct InputSteer {
    pub mouse_sensibility: f64,
    pub keyboard_sensibility: f64,
    // some fields omitted
}

An object to tract steering, that is, going left, or going right. This does not actually poll/reacts to the physical controllers, it just collects "go right" or "go left" informations then aggregates and consolidates them.

Fields

mouse_sensibility: f64keyboard_sensibility: f64

Implementations

impl InputSteer[src]

pub fn new() -> InputSteer[src]

Create a new input steer manager.

Examples

use babalcore::*;

let _input_steer = InputSteer::new();

pub fn mouse_move(&mut self, delta_px: f64)[src]

Register a move of N pixels of the mouse.

Examples

use babalcore::*;

let mut input_steer = InputSteer::new();
// Player moved the mouse of 42 pixels to the left.
input_steer.mouse_move(-42.0);

pub fn right_key(
    &mut self,
    id: i64,
    intensity: f64,
    state: bool,
    now: Option<Instant>
)
[src]

Register a change on a key handling the "move to the right".

One needs to provide an ID (typically, a scancode, but it can be anything) as the manager is stateful and keeps track of what is pressed or released.

The intensity can be used to make in account the fact that a key could be "half pressed". It could typically be used for an analog joystick, which does not act as a mouse, it is rather a virtual key which can be pressed from 0 to 100%.

A true state means pressed, to be called on key down events. A false state means released, to be called on key up events.

The timestamp is used to handle repeats and polling properly, by passing None, the current timestamp, AKA now(), is used.

Examples

use babalcore::*;

let mut input_steer = InputSteer::new();
// Player press arrow right key, pretending keycode is 42.
input_steer.right_key(42, 0.5, true, None);

pub fn left_key(
    &mut self,
    id: i64,
    intensity: f64,
    state: bool,
    now: Option<Instant>
)
[src]

Register a change on a key handling the "move to the left".

One needs to provide an ID (typically, a scancode, but it can be anything) as the manager is stateful and keeps track of what is pressed or released.

The intensity can be used to make in account the fact that a key could be "half pressed". It could typically be used for an analog joystick, which does not act as a mouse, it is rather a virtual key which can be pressed from 0 to 100%.

A true state means pressed, to be called on key down events. A false state means released, to be called on key up events.

The timestamp is used to handle repeats and polling properly, by passing None, the current timestamp, AKA now(), is used.

Examples

use babalcore::*;

let mut input_steer = InputSteer::new();
// Player moved joystick half-way to the left, pretending keycode is 17.
input_steer.left_key(17, 0.5, true, None);

pub fn pop_steer(&mut self, now: Option<Instant>) -> f64[src]

Get the information about steering.

The information returned accumulates all the informations from the mouse, the keys, and outputs a read-to-use, all-in-one number which can be used to figure out "should I go right or should I go left".

The timestamp is used to handle repeats and polling properly, by passing None, the current timestamp, AKA now(), is used.

Examples

use babalcore::*;

let mut input_steer = InputSteer::new();
// Player pressed left arrow, pretending keycode is 41.
input_steer.left_key(41, 1.0, true, None);
let steer = input_steer.pop_steer(None);
assert!(steer < 0.0);

Trait Implementations

impl Debug for InputSteer[src]

impl Default for InputSteer[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,