Trait tile_net::Collable
[−]
[src]
pub trait Collable<T> { fn points(&self) -> Points; fn queued(&self) -> Vector; fn resolve<I>(&mut self, set: TileSet<T, I>) -> bool where I: Iterator<Item=(i32, i32)>; fn presolve(&mut self) { ... } fn postsolve(&mut self, _collided_once: bool, _resolved: bool) { ... } fn solve(&mut self, net: &TileNet<T>) { ... } fn tiles(&self) -> MultiIter<(i32, i32)> { ... } }
Trait for dynamic objects so they can easily check collisions with the TileMap
Required Methods
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.
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.
fn resolve<I>(&mut self, set: TileSet<T, I>) -> bool where 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
fn presolve(&mut self)
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.
fn postsolve(&mut self, _collided_once: bool, _resolved: bool)
Called at the end of solve
.
Used to process the result from the resolve loop.
fn solve(&mut self, net: &TileNet<T>)
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.
fn tiles(&self) -> MultiIter<(i32, i32)>
Gives us a list of points, sorted by proximity on the line.
The sortedness of the returned iterator means you can base your decision on the first element(s), as they represent the first collision.