Skip to main content

Player

Struct Player 

Source
pub struct Player {
    pub x: i32,
    pub y: i32,
    pub vx: f32,
    pub vy: f32,
    pub facing: i32,
    pub mode: Mode,
    pub air_jumps: u8,
    pub dashes: u8,
    pub stamina: f32,
    /* private fields */
}
Expand description

The hero’s body. What a game or an Ability may change is public: position (a nudge; Player::teleport for a jump elsewhere), speed, facing, mode and refills. The movement’s own state (timers, latches, what it stands on) is read through methods: written by hand it could leave the body in a state the movement never produces.

Fields§

§x: i32

Left edge of the hitbox, units (the movement’s space; see docs/scale.md).

§y: i32

Top edge of the hitbox, units.

§vx: f32

Horizontal speed, units/s (pixels/s only at a scale of 1; see docs/scale.md).

§vy: f32

Vertical speed, units/s, positive down.

§facing: i32

1 facing right, -1 facing left.

§mode: Mode

What the body is busy with.

§air_jumps: u8

Air jumps left.

§dashes: u8

Dashes left.

§stamina: f32

Climbing stamina left.

Implementations§

Source§

impl Player

Source

pub fn at((x, y): (i32, i32), t: &Tuning) -> Self

Standing with its hitbox’s top-left at x, y (units), with everything refilled.

Source

pub fn launch(&mut self, vx: f32, vy: f32)

Set the speed from outside: a spring, a bounce pad, knockback. Whatever the body was busy with ends (a dash, a dive, a climb), a jump in progress can no longer be sustained or cut, and going up leaves the ground for good (no coyote jump).

Source

pub fn teleport(&mut self, x: i32, y: i32)

Put the hitbox’s top-left at x, y (units) without moving through what’s between: a door, a portal. The sub-pixel remainder is dropped and the airtime starts over; speed and state stay (follow with Player::launch to stop it). Teleported into the air while standing, it walks off as if from a ledge.

Source

pub fn refill(&mut self, t: &Tuning)

Refill dashes, air jumps and climbing stamina, as touching the ground does.

Source

pub fn rect(&self) -> Rect

The hitbox.

Source

pub fn exact_pos(&self) -> (f32, f32)

Position with the sub-pixel remainder, for drawing between steps.

Source

pub fn step( &mut self, level: &dyn Terrain, i: &Intent, moves: &Moves, t: &Tuning, dt: f32, ev: &mut Vec<Event>, )

One step of dt seconds (see the module docs for the order), with the built-in moves moves allows.

Source

pub fn mode_time(&self) -> f32

Seconds in the current timed mode (0 for untimed ones).

Source

pub fn wall(&self, level: &dyn Terrain, side: i32) -> bool

Whether a solid wall touches the hitbox on side (-1 left, 1 right).

Source

pub fn climbable(&self, level: &dyn Terrain, side: i32) -> bool

Whether a wall the character may hold on to touches the hitbox on side: solid, and its super::Surface climbable.

Source

pub fn feet(&self) -> Rect

The row just under the hitbox.

Source

pub fn beside(&self, side: i32) -> Rect

The column just beside the hitbox on side (-1 left, 1 right).

Source

pub fn riding(&self) -> Option<Rect>

What the body rides on: the row under its feet while standing, the column beside it while holding on to a wall, or nothing.

Source

pub fn ride( &mut self, level: &dyn Terrain, carry: Option<(f32, f32)>, t: &Tuning, dt: f32, )

Carried dx, dy units in a step of dt by the moving ground (or moving wall) it rides, or None when it rides nothing. Moved through the same unit-by-unit collision, testing only the edge it moves toward, so the ground it rides (now overlapping the feet when rising) doesn’t hold it back. Its speed becomes Player::lift, which a jump keeps for Tuning::coyote_time after leaving.

Source§

impl Player

The movement’s own state, to read (drivers, debug overlays).

Source

pub fn w(&self) -> i32

Hitbox width in units, from Tuning::size.

Source

pub fn h(&self) -> i32

Hitbox height in units, from Tuning::size.

Source

pub fn grounded(&self) -> bool

Standing on something.

Source

pub fn coyote(&self) -> f32

Coyote time left.

Source

pub fn buffer(&self) -> f32

Jump buffer time left: a press waiting to become a jump.

Source

pub fn dash_buffer(&self) -> f32

Dash buffer time left: a press waiting to become a dash.

Source

pub fn var_jump(&self) -> f32

Variable-jump time left: holding jump keeps the upward speed.

Source

pub fn dash_cooldown(&self) -> f32

Seconds until the next dash may start.

Source

pub fn force_move(&self) -> f32

Seconds the stick is overridden after a wall jump.

Source

pub fn drop_through(&self) -> f32

Seconds platforms still let the hero through after dropping.

Source

pub fn wall_slide(&self) -> i32

Side of the wall being slid down (-1, 1), or 0.

Source

pub fn wall_stick(&self) -> f32

Wall-stick time left: pressing away from the wall slid down doesn’t let go yet.

Source

pub fn slipping(&self) -> bool

Holding on to a wall but sliding down it (a slipping or tired grip).

Source

pub fn regrab(&self) -> f32

Seconds before a wall can be grabbed again after hopping over its top.

Source

pub fn look(&self) -> i32

Looking up (-1) or down (1) while standing still, or 0.

Source

pub fn look_time(&self) -> f32

Seconds the current look has been held.

Source

pub fn gliding(&self) -> bool

Gliding.

Source

pub fn peak_y(&self) -> i32

Highest (smallest) y of this airtime (units), for the drop height on landing.

Source

pub fn lift(&self) -> (f32, f32)

The speed of the moving ground (or wall) ridden, units/s, smoothed over about LIFT_SMOOTHING seconds: a jump keeps it.

Source

pub fn contacts(&self) -> Contacts

What its movement ran into in the last step.

Trait Implementations§

Source§

impl Clone for Player

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Player

Source§

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

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

impl PartialEq for Player

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Player

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more