Skip to main content

OverworldActor

Struct OverworldActor 

Source
pub struct OverworldActor { /* private fields */ }
Expand description

A walking overworld actor (player or NPC): tile target + interpolated pixel position + facing + walk animation. Tile size is configurable (tile).

Implementations§

Source§

impl OverworldActor

Source

pub fn new(tile_x: i32, tile_y: i32, tile: i32) -> Self

Spawn at tile (tile_x, tile_y) facing down, with tile-px tiles.

Source

pub fn facing(&self) -> Direction

Source

pub fn set_facing(&mut self, dir: Direction)

Source

pub fn is_moving(&self) -> bool

Source

pub fn set_running(&mut self, running: bool)

Set whether the actor is running this frame — the consumer calls this each frame (e.g. from a held run button) before update. Running uses a faster step speed and animation; the renderer reads locomotion + step_phase to pick frames.

Source

pub fn is_running(&self) -> bool

Source

pub fn tile(&self) -> (i32, i32)

Target tile coordinates.

Source

pub fn px(&self) -> f32

Interpolated foot-tile top-left, in world pixels (for camera + drawing).

Source

pub fn py(&self) -> f32

Source

pub fn elevation(&self) -> u8

Elevation level the actor walks on (0 = ground).

Source

pub fn set_elevation(&mut self, level: u8)

Set the elevation level (stair transitions, spawns, save restore). The caller clamps to the map’s level count.

Source

pub fn place(&mut self, x: i32, y: i32, dir: Direction)

Snap to tile (x, y), facing dir, stationary (warps, spawns, debug teleport).

Source

pub fn update( &mut self, held: Option<Direction>, map: &impl OverworldCollision, ) -> Option<(i32, i32)>

Advance one frame. When idle and held is set, the actor turns to face it and — if the next tile isn’t OverworldCollision::is_blocked_at at the actor’s elevation — begins a step. The in-progress step’s pixel interpolation is advanced. Returns Some((x, y)) on the frame a step completes (the tile just arrived on) so the caller can check warps; None otherwise.

Source

pub fn facing_row(&self) -> u32

Sprite-sheet row for the current facing (the convention WalkSprite and the character-sprite-gen skill author: down=0, up=1, left=2, right=3).

Source

pub fn walk_frame(&self) -> u32

Generic 3-frame walk index: 0 = neutral/idle, 1/2 = the two step frames (alternating while walking). The consumer maps this to its sheet’s columns (a clean sheet uses it directly; a sheet whose neutral pose is elsewhere remaps).

Source

pub fn locomotion(&self) -> Locomotion

Locomotion state for picking sprite columns: Idle when stationary, else Run if the run flag is set (set_running) else Walk.

Source

pub fn step_phase(&self) -> u32

Which of the two step frames to show (0 or 1), alternating faster while running. Pair with frame_col to resolve the actual sheet column.

Trait Implementations§

Source§

impl Clone for OverworldActor

Source§

fn clone(&self) -> OverworldActor

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 OverworldActor

Source§

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

Formats the value using the given formatter. 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> 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> 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> 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> 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.