just check intersecting tiles

This commit is contained in:
2015-01-02 16:02:17 +01:00
parent 4cca0eac2c
commit 62101e8466
3 changed files with 65 additions and 38 deletions

View File

@@ -1,13 +1,20 @@
use sdl2::rect::Rect;
pub struct Layer<T> {
tiles: Vec<T>,
width: i32
width: i32,
tile_width: i32,
tile_height: i32
}
impl<T> Layer<T> where T: Clone {
pub fn new(width: i32, height: i32, tile: T) -> Layer<T> {
pub fn new(width: i32, height: i32, tile_width: i32, tile_height: i32, tile: T) -> Layer<T> {
Layer {
tiles: Vec::from_elem((width * height) as uint, tile),
width: width
width: width,
tile_width: tile_width,
tile_height: tile_height
}
}
@@ -22,4 +29,14 @@ impl<T> Layer<T> where T: Clone {
*self.tiles.index_mut(&offset) = tile;
}
pub fn get_intersecting(&self, rect: &Rect) -> Rect {
let x = rect.x / self.tile_width;
let w = rect.w / self.tile_width;
let y = rect.y / self.tile_height;
let h = rect.h / self.tile_height;
Rect::new(x, y, w, h)
}
}