Struct simple_tilemap::Tilemap

source ·
pub struct Tilemap<C, U = ()> { /* private fields */ }
Expand description

A map that holds a tileset and a collection of tiles.

Implementations§

source§

impl<C, U> Tilemap<C, U>
where U: Default + Clone,

source

pub fn new(width: u32, height: u32, tileset: Tileset<C>) -> Self

Construct a new tilemap. width and height are map’s size in tiles.

source§

impl<C, U> Tilemap<C, U>

source

pub fn width(&self) -> u32

Map’s width in tiles.

source

pub fn height(&self) -> u32

Map’s height in tiles.

source

pub fn tileset(&self) -> &Tileset<C>

Tileset used by this map.

source

pub fn tiles(&self) -> &[Tile<U>]

Map’s tiles.

source

pub fn tiles_mut(&mut self) -> &mut [Tile<U>]

Map’s tiles (mutable).

source

pub fn get_tile(&self, x: u32, y: u32) -> Option<&Tile<U>>

Get a tile at (x, y).

source

pub fn get_mut_tile(&mut self, x: u32, y: u32) -> Option<&mut Tile<U>>

Get a mutable ref to a tile at (x, y).

source

pub fn set_tile(&mut self, x: u32, y: u32, tile: Tile<U>)

Set a tile at (x, y).

source§

impl<C> Tilemap<C>
where C: AsRef<[u8]>,

source

pub fn render( &self, surface: &mut (impl BufferMut<Color> + ?Sized), offset_x: i32, offset_y: i32 )

Render the map onto a buffer at pixel offset (offset_x, offset_y).

Trait Implementations§

source§

impl<C> Buffer<Tile> for Tilemap<C>

source§

fn width(&self) -> u32

Buffer width
source§

fn height(&self) -> u32

Buffer height
source§

fn get(&self, x: u32, y: u32) -> &Tile

Get a value at (x, y). This function must not panic when x < self.width() && y < self.height() (unless you want blit functions to panic). It will not be called with values outside of that range.
source§

impl<C> BufferMut<Tile> for Tilemap<C>

source§

fn get_mut(&mut self, x: u32, y: u32) -> &mut Tile

Get a mutable value at (x, y). This function must not panic when x < self.width() && y < self.height() (unless you want blit functions to panic). It will not be called with values outside of that range.
source§

impl<C: Clone, U: Clone> Clone for Tilemap<C, U>

source§

fn clone(&self) -> Tilemap<C, U>

Returns a copy 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<C: Debug, U: Debug> Debug for Tilemap<C, U>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C, U> RefUnwindSafe for Tilemap<C, U>

§

impl<C, U> Send for Tilemap<C, U>
where C: Send, U: Send,

§

impl<C, U> Sync for Tilemap<C, U>
where C: Sync, U: Sync,

§

impl<C, U> Unpin for Tilemap<C, U>
where C: Unpin, U: Unpin,

§

impl<C, U> UnwindSafe for Tilemap<C, U>
where C: UnwindSafe, U: UnwindSafe,

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> 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,

§

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>,

§

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>,

§

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.