Skip to main content

Builder

Struct Builder 

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

Sets up a Platformer: preset, tuning, controls, animation graph, spawn point.

Implementations§

Source§

impl Builder

Source

pub fn preset(self, preset: Preset) -> Self

Feel (and, with game-toolkit, controls) of preset.

Source

pub fn tuning(self, tuning: Tuning) -> Self

A tuning of your own (replaces the preset’s numbers).

Source

pub fn tune(self, f: impl FnOnce(&mut Tuning)) -> Self

Adjust the tuning so far, e.g. .tune(|t| t.air_jumps = 2).

Source

pub fn graph(self, graph: GraphSpec) -> Self

An animation graph of your own instead of the built-in one. It has to declare the parameters the built-in driver writes (see hero::spec), though it may ignore any of them; Builder::build says which one is missing (a typo, say). For a graph that declares only what it uses, see Builder::partial_graph.

Source

pub fn partial_graph(self, graph: GraphSpec) -> Self

An animation graph of your own that declares only the built-in driver’s parameters it uses: the rest are written but never read. A misspelled one goes unnoticed, which Builder::graph would catch.

Source

pub fn driver(self, driver: impl Driver<World> + 'static) -> Self

A driver of your own, run after the built-in one every step (several run in the order added): for parameters of your game (hurt, attacking, carrying), or to override what the built-in one wrote. A closure |world: &World, params: &mut Params| ... is a driver. Parameters only your game sets (not the built-in driver) can also be set between updates through Platformer::animator.

Source

pub fn ability(self, ability: impl Ability + Clone + 'static) -> Self

A move of your own (an attack lunge, a ledge grab), run in every step; several run in the order added. See Ability; for one with animation of its own, see Builder::animated.

Source

pub fn animated<T: Ability + Animate + Clone + 'static>( self, ability: T, ) -> Self

A move of your own that also drives its animation parameters (Animate): one registration for both halves. Runs as an Builder::ability; its Animate::drive runs after each step, after the built-in driver and before Builder::drivers. Builder::build fails if the graph lacks one of its Animate::PARAMS.

Source

pub fn without_hero_driver(self) -> Self

Run without the built-in driver: your drivers (Builder::driver) set every parameter, and the graph needn’t declare the built-in ones.

Source

pub fn scale(self, k: i32) -> Self

Your terrain speaks pixels, k of them per unit of the movement (default 1): with 16-pixel tiles, say, scale(2), so the feel made for 8-unit tiles fits. The character then converts at its edges: the terrain is asked in your pixels, and everything the facade hands in or out is in them too: positions (Platformer::position, Platformer::hitbox, every Spot), speeds (Platformer::velocity, Platformer::launch) and the events of Platformer::drain_events. What runs inside the movement stays in units: Platformer::world, the Tuning, drivers, abilities (their Step) and the data of Event::Custom. docs/scale.md has the table.

A Level already speaks units: keep the scale at 1 with one and draw it scaled.

Source

pub fn spawn(self, spot: Spot) -> Self

Start at spot (units, or pixels with a Builder::scale): Spot::Feet(x, floor_y) to stand on ground of your own, level.start() on a Level’s spawn tile, Spot::TopLeft(x, y) for the hitbox’s corner.

Source

pub fn respawn(self, on: bool) -> Self

Whether to put the character back at its start when it falls out of the world (default: yes). Event::FellOut is reported either way, so you can do your own.

Source

pub fn controls(self, scheme: Scheme) -> Self

A control scheme of your own instead of the preset’s.

Source

pub fn build(self) -> Result<Platformer, SpecError>

The character, or why the animation graph doesn’t fit.

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> 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<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, 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> 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