Struct InputJump

Source
pub struct InputJump {
    pub stickiness: Option<Duration>,
    /* private fields */
}
Expand description

Used to handle jump input. This is to encapsulate all the nitty-picky logic about considering a button is still pressed a fraction of seconds after it has been pressed, etc. It does not actually poll and/or listens to the real hardware, it just keeps track of what’s happening with push/pop operations.

Fields§

§stickiness: Option<Duration>

How long a button should be considered pressed after it has actually been pressed. This is used to work around the fact that you might require a jump just before you actually land.

Implementations§

Source§

impl InputJump

Source

pub fn new() -> InputJump

Create a new input jump manager.

§Examples
use babalcore::*;

let _input_jump = InputJump::new();
Source

pub fn set_stickiness_secs_f64(&mut self, stickiness_secs_f64: Option<f64>)

Set the stickiness value, in seconds.

§Examples
use babalcore::*;

let mut input_jump = InputJump::new();
input_jump.set_stickiness_secs_f64(Some(0.1));
Source

pub fn push_jump(&mut self, now: Option<Instant>)

Push a jump request. It is possible to omit the current now timestamp, or you may provide your own. If omitted, the default is the current instant (AKA now). Pushing several jump requests will not queue them, only the last one is registered.

§Examples
use babalcore::*;

let mut input_jump = InputJump::new();
// Player pressed the jump key, clicked on mouse
input_jump.push_jump(None);
Source

pub fn pop_jump(&mut self, now: Option<Instant>) -> bool

Pop a jump request. It is possible to omit the current now timestamp, or you may provide your own. If omitted, the default is the current instant (AKA now). Once a jump request is popped, it is cleared from the object. However, if stickiness is set, it will continue to return true for some time, defined by stickiness. This is to avoid the following “bug”: a player would press jump just before it can actually jump (eg: the ball did not land yet). But a fraction of a second later it would be OK to jump… You’d want it to jump now. To work around this, pop will return true for some time, typically 1/10th of a second.

§Examples
use babalcore::*;

let mut input_jump = InputJump::new();
assert!(!input_jump.pop_jump(None));
input_jump.push_jump(None);
assert!(input_jump.pop_jump(None));

Trait Implementations§

Source§

impl Debug for InputJump

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for InputJump

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V