[][src]Trait babalcore::InputQuery

pub trait InputQuery {
    pub fn pop_jump(&mut self) -> bool;
pub fn pop_steer(&mut self) -> f64; }

A trait to abstract the input query interface, it is mostly used for testing the game logic without having real inputs.

Required methods

pub fn pop_jump(&mut self) -> bool[src]

Returns true if a jump is requested. It can return true several times in a row, even if the button/key has been pressed once, but this only for a limited time. OTOH if you call pop_jump very late after the button/key press, it will still buffer it and return true.

pub fn pop_steer(&mut self) -> f64[src]

Returns steering information, that is, how much on the left or on the right the player should move. The values accumulate over time so popping values after 50 msec is likely to return twice the value popped after 25 msec.

Loading content...

Implementors

impl InputQuery for FakeInput[src]

pub fn pop_jump(&mut self) -> bool[src]

Test whether a push request has been pushed.

Examples

use babalcore::*;

let mut fake_input = FakeInput::new();
assert!(!fake_input.pop_jump());
fake_input.push_jump();
assert!(fake_input.pop_jump());
assert!(!fake_input.pop_jump());

pub fn pop_steer(&mut self) -> f64[src]

Pop steer commands.

Examples

use babalcore::*;

let mut fake_input = FakeInput::new();
assert_eq!(0.0, fake_input.pop_steer());
fake_input.push_steer(1.0);
fake_input.push_steer(-3.0);
assert_eq!(1.0, fake_input.pop_steer());
assert_eq!(-3.0, fake_input.pop_steer());
assert_eq!(0.0, fake_input.pop_steer());
Loading content...