a simple tile system

This commit is contained in:
2015-01-02 15:23:45 +01:00
parent e313bbf80a
commit 4cca0eac2c
6 changed files with 126 additions and 63 deletions

25
src/tile.rs Normal file
View File

@@ -0,0 +1,25 @@
pub struct Layer<T> {
tiles: Vec<T>,
width: i32
}
impl<T> Layer<T> where T: Clone {
pub fn new(width: i32, height: i32, tile: T) -> Layer<T> {
Layer {
tiles: Vec::from_elem((width * height) as uint, tile),
width: width
}
}
pub fn get_tile(&self, x: i32, y: i32) -> &T {
let offset = (x + y * self.width) as uint;
self.tiles.index(&offset)
}
pub fn set_tile(&mut self, x: i32, y: i32, tile: T) {
let offset = (x + y * self.width) as uint;
*self.tiles.index_mut(&offset) = tile;
}
}