Scene

Struct Scene 

Source
pub struct Scene {
    pub name: String,
    pub map: Map,
    pub pawn: Option<Pawn>,
}
Expand description

§Scene

The Scene struct represents an active gameplay scene containing a Map and a controllable Pawn. It acts as the orchestrator for movement logic, pathfinding, and interaction between the pawn and the terrain.

§Fields

  • name: String
    A unique identifier for the scene.

  • map: Map
    The associated map, which includes multiple layers and defines the terrain, obstacles, and interaction tiles.

  • pawn: Option<Pawn>
    The currently active pawn in the scene, if any. Pawns represent entities that can move and interact with the map.

§Usage

A Scene is responsible for high-level movement commands like walking to a target, stepping in a direction, and computing path steps.


§Methods

§new(name: String, map: Map, pawn: Option<Pawn>) -> Self

Creates a new scene with the given name, map, and an optional pawn.


§load_pawn(texture_id: u32)

Instantiates a new Pawn with the given texture_id and places it at the default spawn position defined by the map.


§load_pawn_at(pawn: Pawn)

Loads a given pawn into the scene at its defined coordinates.


§walk_to(&mut self, target_position: Coordinates) -> Result<Coordinates, RPGXError>

Asynchronously walks the pawn step-by-step to the target coordinates using the shortest computed path.
Returns the final tile position or an error if movement fails.

Errors:

  • PawnNotFound: if no pawn is loaded.
  • PathNotFround: if no path to the target exists.
  • WalkFailed: if movement to one of the tiles in the path fails.

§step_to(&mut self, direction: Direction) -> Result<Coordinates, RPGXError>

Attempts to move the pawn one step in the specified direction.
Returns the new position or an error if movement is blocked or invalid.

Errors:

  • PawnNotFound: if no pawn is loaded.
  • StepFailed: if the step results in an invalid coordinate.
  • TileNotWalkable: if the destination tile is blocked.

§move_to(&mut self, target_position: Coordinates) -> Result<Coordinates, RPGXError>

Moves the pawn directly to the target tile if movement is allowed.
Returns the new coordinates or an error if the tile is not walkable.

Errors:

  • PawnNotFound: if no pawn is loaded.
  • TileNotWalkable: if the tile is blocked by the map.

§steps_to(&self, target_position: Coordinates) -> Result<Vec<Coordinates>, RPGXError>

Computes the full path of steps from the current pawn position to the target.
Returns a vector of Coordinates or an error if the pawn is missing or the path can’t be found.

Errors:

  • PawnNotFound: if no pawn is loaded.
  • PathNotFround: if no valid path exists to the target.

§Notes

  • Scene provides convenience methods that delegate to the underlying Map for pathfinding.
  • It abstracts away path computation and movement, enabling game logic to interact with higher-level APIs.
  • Each movement is validated against map constraints like blocked tiles. RPG scene providing Pawn movement computation across the Map.

Fields§

§name: String

Scene name identifier.

§map: Map

The game map with multiple layers defining terrain and obstacles.

§pawn: Option<Pawn>

Optional pawn currently active in the scene.

Implementations§

Source§

impl Scene

Source

pub fn new(name: String, map: Map, pawn: Option<Pawn>) -> Self

Creates a new Scene with the specified name, map, and optional pawn.

§Arguments
  • name - A string identifier for the scene.
  • map - The Map instance used in the scene.
  • pawn - Optional initial Pawn to place in the scene.
Source

pub fn load_pawn(&mut self, texture_id: u32)

Load a Pawn into the scene at the map’s default spawn position.

§Arguments
  • texture_id - Identifier for the pawn’s texture/sprite.
Source

pub fn load_pawn_at(&mut self, pawn: Pawn)

Load a Pawn into the scene at a specific location.

§Arguments
  • pawn - The pawn instance with desired coordinates.
Source

pub async fn walk_to( &mut self, target_position: Coordinates, ) -> Result<Coordinates, RPGXError>

Walk asynchronously to the target coordinates along the best computed path.

Moves the pawn step-by-step, returning the final position or an error.

§Errors

Returns RPGXError if the pawn is missing, no path is found, or a step fails.

Source

pub fn step_to( &mut self, direction: Direction, ) -> Result<Coordinates, RPGXError>

Take a single movement step in the specified direction.

§Arguments
  • direction - The direction to move.
§Errors

Returns RPGXError if the pawn is missing, the target tile is invalid or blocked.

Source

pub fn move_to( &mut self, target_position: Coordinates, ) -> Result<Coordinates, RPGXError>

Move the pawn directly to the target coordinates if movement is allowed.

Checks map blocking and updates the pawn’s position if possible.

§Errors

Returns RPGXError if the pawn is missing or the target is blocked.

Source

pub fn steps_to( &self, target_position: Coordinates, ) -> Result<Vec<Coordinates>, RPGXError>

Compute all the steps from the current pawn position to the target.

Returns a vector of coordinates representing the path, or an error if no path.

§Errors

Returns RPGXError if the pawn is missing or no path is found.

Trait Implementations§

Source§

impl Clone for Scene

Source§

fn clone(&self) -> Scene

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Scene

§

impl RefUnwindSafe for Scene

§

impl Send for Scene

§

impl Sync for Scene

§

impl Unpin for Scene

§

impl UnwindSafe for Scene

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.