pub trait Collable<T, S> {
// Required methods
fn points(&self) -> Points<'_> ⓘ;
fn queued(&self) -> Vector;
fn resolve<I>(&mut self, set: TileSet<'_, T, I>, state: &mut S) -> bool
where I: Iterator<Item = (i32, i32)>;
// Provided methods
fn presolve(&mut self, _state: &mut S) { ... }
fn postsolve(
&mut self,
_collided_once: bool,
_resolved: bool,
_state: &mut S
) { ... }
fn solve(&mut self, net: &TileNet<T>, state: &mut S) { ... }
fn tiles(&self) -> MultiIter<(i32, i32)> ⓘ { ... }
}
Expand description
Trait for dynamic objects so they can easily check collisions with the TileMap
Required Methods§
sourcefn points(&self) -> Points<'_> ⓘ
fn points(&self) -> Points<'_> ⓘ
Returns the set of points associated with this object. These points are used to draw lines to their respective next points. For a rectangle, the four courners may be points. For a circle, a whole bunch of points may be defined.
sourcefn queued(&self) -> Vector
fn queued(&self) -> Vector
Get the previously queued move. Should reasonably return what was given in enqueue
,
but you can do whatever makes sense in your application.
sourcefn resolve<I>(&mut self, set: TileSet<'_, T, I>, state: &mut S) -> boolwhere
I: Iterator<Item = (i32, i32)>,
fn resolve<I>(&mut self, set: TileSet<'_, T, I>, state: &mut S) -> boolwhere I: Iterator<Item = (i32, i32)>,
Resolve the movement: you get a set of tiles and you decide what to do with them.
If you aren’t satisfied, you can change the move vector and return false, this means
that we’ll try again. Another set of tiles may then be given.
If you’re satisfied, return true and adjust your Collable
’s position accordingly.
IMPORTANT: You should add the move from queued_move to your point set. The ray tracer also adds to find the next points. This will prevent you from getting stuck in a wall.
Provided Methods§
sourcefn presolve(&mut self, _state: &mut S)
fn presolve(&mut self, _state: &mut S)
Called at the beginning of solve
This method is useful when resetting internal variables of state. An example of this is when you have to set a has-jumped variable.
sourcefn postsolve(&mut self, _collided_once: bool, _resolved: bool, _state: &mut S)
fn postsolve(&mut self, _collided_once: bool, _resolved: bool, _state: &mut S)
Called at the end of solve
.
Used to process the result from the resolve loop.
sourcefn solve(&mut self, net: &TileNet<T>, state: &mut S)
fn solve(&mut self, net: &TileNet<T>, state: &mut S)
Convenience function for the resolve loop
Calls presolve at the beginning and postsolve at the end. Runs the resolve function in a loop of at max 30 iterations. This is to avoid potential deadlock if the resolve function is poorly coded and returns false all the time.