better collision detection, i hope

This commit is contained in:
2015-01-06 23:12:35 +01:00
parent b5f94170f7
commit ff9ab15240
4 changed files with 115 additions and 74 deletions

View File

@@ -35,7 +35,7 @@ impl<T> Layer<T> where T: Clone {
self.tiles[offset] = tile;
}
pub fn get_intersecting(&self, rect: &Rect) -> Rect {
pub fn find_intersecting(&self, rect: &Rect) -> Rect {
let x1 = max(rect.x / self.tile_width, 0);
let y1 = max(rect.y / self.tile_height, 0);
let x2 = min((rect.x + rect.w - 1) / self.tile_width, self.width - 1);
@@ -45,7 +45,7 @@ impl<T> Layer<T> where T: Clone {
}
pub fn for_each_intersecting<F>(&self, rect: &Rect, mut f: F) where F: FnMut(&T, &Rect) {
let intersect = self.get_intersecting(rect);
let intersect = self.find_intersecting(rect);
if intersect.x < 0 || intersect.x + intersect.w > self.width {
return;