Skip to main content

Collider

Struct Collider 

Source
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

Source

pub fn new(north: bool, south: bool, east: bool, west: bool) -> Self

Source

pub fn blocks(&self, movement: &Movement) -> bool

Check if a movement directed towards the collider should be blocked.

Source

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 chars

Trait Implementations§

Source§

impl Add for Collider

If two colliders are added together, their collisions are OR’d.

Source§

type Output = Collider

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for Collider

Source§

fn clone(&self) -> Collider

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Collider

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Collider

Source§

fn eq(&self, other: &Collider) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Collider

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.