pub struct Collider { /* private fields */ }Expand description
Represents a collision box. The cardinals denote which INWARD movements are blocked. E.g.: if collider.north = true, then it will not allow something getting into it from the north. However, it will allow moving north from inside of it.
Implementations§
Source§impl Collider
impl Collider
pub fn new(north: bool, south: bool, east: bool, west: bool) -> Self
Sourcepub fn blocks(&self, movement: &Movement) -> bool
pub fn blocks(&self, movement: &Movement) -> bool
Check if a movement directed towards the collider should be blocked.
Sourcepub fn build(template: &str) -> Self
pub fn build(template: &str) -> Self
Creates a collider from a template string. The string must have the format ‘nsew’ where each letter represents the collider blocking from a cardinal. If the collider should not block from that direction, use ‘-’ instead.
§Examples
use starlib::Collider;
let col1 = Collider::build("ns--");
let col2 = Collider::new(true, true, false, false);
assert_eq!(col1, col2);§Panics
Panics if the value does not match the specified format. E.g.: When it is not 4 chars long, when one of its chars is not ‘n’, ‘s’, ‘e’, ‘w’ or ‘-’ or when those characters aren’t in order.
ⓘ
use starlib::Collider;
Collider::build("nwe-"); // Out of orderⓘ
use starlib::Collider;
Collider::build("nse"); // Wrong lengthⓘ
use starlib::Collider;
Collider::build("Starlib!"); // Wrong charsTrait Implementations§
impl StructuralPartialEq for Collider
Auto Trait Implementations§
impl Freeze for Collider
impl RefUnwindSafe for Collider
impl Send for Collider
impl Sync for Collider
impl Unpin for Collider
impl UnsafeUnpin for Collider
impl UnwindSafe for Collider
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
Mutably borrows from an owned value. Read more