pub struct Builder { /* private fields */ }Expand description
Sets up a Platformer: preset, tuning, controls, animation graph, spawn point.
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn tuning(self, tuning: Tuning) -> Self
pub fn tuning(self, tuning: Tuning) -> Self
A tuning of your own (replaces the preset’s numbers).
Sourcepub fn tune(self, f: impl FnOnce(&mut Tuning)) -> Self
pub fn tune(self, f: impl FnOnce(&mut Tuning)) -> Self
Adjust the tuning so far, e.g. .tune(|t| t.air_jumps = 2).
Sourcepub fn graph(self, graph: GraphSpec) -> Self
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.
Sourcepub fn partial_graph(self, graph: GraphSpec) -> Self
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.
Sourcepub fn driver(self, driver: impl Driver<World> + 'static) -> Self
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.
Sourcepub fn ability(self, ability: impl Ability + Clone + 'static) -> Self
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.
Sourcepub fn animated<T: Ability + Animate + Clone + 'static>(
self,
ability: T,
) -> Self
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.
Sourcepub fn without_hero_driver(self) -> Self
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.
Sourcepub fn scale(self, k: i32) -> Self
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.
Sourcepub fn spawn(self, spot: Spot) -> Self
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.
Sourcepub fn respawn(self, on: bool) -> Self
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.
Sourcepub fn controls(self, scheme: Scheme) -> Self
pub fn controls(self, scheme: Scheme) -> Self
A control scheme of your own instead of the preset’s.
Sourcepub fn build(self) -> Result<Platformer, SpecError>
pub fn build(self) -> Result<Platformer, SpecError>
The character, or why the animation graph doesn’t fit.
Auto Trait Implementations§
impl !RefUnwindSafe for Builder
impl !Send for Builder
impl !Sync for Builder
impl !UnwindSafe for Builder
impl Freeze for Builder
impl Unpin for Builder
impl UnsafeUnpin for Builder
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> 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.