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: i32Left edge of the hitbox, units (the movement’s space; see docs/scale.md).
y: i32Top edge of the hitbox, units.
vx: f32Horizontal speed, units/s (pixels/s only at a scale of 1; see docs/scale.md).
vy: f32Vertical speed, units/s, positive down.
facing: i321 facing right, -1 facing left.
mode: ModeWhat the body is busy with.
air_jumps: u8Air jumps left.
dashes: u8Dashes left.
stamina: f32Climbing stamina left.
Implementations§
Source§impl Player
impl Player
Sourcepub fn at((x, y): (i32, i32), t: &Tuning) -> Self
pub fn at((x, y): (i32, i32), t: &Tuning) -> Self
Standing with its hitbox’s top-left at x, y (units), with everything refilled.
Sourcepub fn launch(&mut self, vx: f32, vy: f32)
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).
Sourcepub fn teleport(&mut self, x: i32, y: i32)
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.
Sourcepub fn refill(&mut self, t: &Tuning)
pub fn refill(&mut self, t: &Tuning)
Refill dashes, air jumps and climbing stamina, as touching the ground does.
Sourcepub fn exact_pos(&self) -> (f32, f32)
pub fn exact_pos(&self) -> (f32, f32)
Position with the sub-pixel remainder, for drawing between steps.
Sourcepub fn step(
&mut self,
level: &dyn Terrain,
i: &Intent,
moves: &Moves,
t: &Tuning,
dt: f32,
ev: &mut Vec<Event>,
)
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.
Sourcepub fn wall(&self, level: &dyn Terrain, side: i32) -> bool
pub fn wall(&self, level: &dyn Terrain, side: i32) -> bool
Whether a solid wall touches the hitbox on side (-1 left, 1 right).
Sourcepub fn climbable(&self, level: &dyn Terrain, side: i32) -> bool
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.
Sourcepub fn beside(&self, side: i32) -> Rect
pub fn beside(&self, side: i32) -> Rect
The column just beside the hitbox on side (-1 left, 1 right).
Sourcepub fn riding(&self) -> Option<Rect>
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.
Sourcepub fn ride(
&mut self,
level: &dyn Terrain,
carry: Option<(f32, f32)>,
t: &Tuning,
dt: f32,
)
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).
impl Player
The movement’s own state, to read (drivers, debug overlays).
Sourcepub fn w(&self) -> i32
pub fn w(&self) -> i32
Hitbox width in units, from Tuning::size.
Sourcepub fn h(&self) -> i32
pub fn h(&self) -> i32
Hitbox height in units, from Tuning::size.
Sourcepub fn dash_buffer(&self) -> f32
pub fn dash_buffer(&self) -> f32
Dash buffer time left: a press waiting to become a dash.
Sourcepub fn dash_cooldown(&self) -> f32
pub fn dash_cooldown(&self) -> f32
Seconds until the next dash may start.
Sourcepub fn force_move(&self) -> f32
pub fn force_move(&self) -> f32
Seconds the stick is overridden after a wall jump.
Sourcepub fn drop_through(&self) -> f32
pub fn drop_through(&self) -> f32
Seconds platforms still let the hero through after dropping.
Sourcepub fn wall_slide(&self) -> i32
pub fn wall_slide(&self) -> i32
Side of the wall being slid down (-1, 1), or 0.
Sourcepub fn wall_stick(&self) -> f32
pub fn wall_stick(&self) -> f32
Wall-stick time left: pressing away from the wall slid down doesn’t let go yet.
Sourcepub fn slipping(&self) -> bool
pub fn slipping(&self) -> bool
Holding on to a wall but sliding down it (a slipping or tired grip).
Sourcepub fn regrab(&self) -> f32
pub fn regrab(&self) -> f32
Seconds before a wall can be grabbed again after hopping over its top.
Sourcepub fn peak_y(&self) -> i32
pub fn peak_y(&self) -> i32
Highest (smallest) y of this airtime (units), for the drop height on landing.
Sourcepub fn lift(&self) -> (f32, f32)
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.
Trait Implementations§
impl StructuralPartialEq for Player
Auto Trait Implementations§
impl Freeze for Player
impl RefUnwindSafe for Player
impl Send for Player
impl Sync for Player
impl Unpin for Player
impl UnsafeUnpin for Player
impl UnwindSafe for Player
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.