I prefer this way
This commit is contained in:
parent
a66e596db0
commit
0bc6dcdf02
|
@ -303,23 +303,23 @@ impl Map {
|
|||
}
|
||||
|
||||
/// Creates the neighbours of a tile.
|
||||
pub fn neighbours(&self, i: isize, j: isize) -> [Option<CollisionTile>; 8] {
|
||||
pub fn neighbours(&self, i: usize, j: usize) -> [Option<CollisionTile>; 8] {
|
||||
[
|
||||
self.collision_tiles.get_isize(i - 1, j - 1).cloned(),
|
||||
self.collision_tiles.get_isize(i - 1, j ).cloned(),
|
||||
self.collision_tiles.get_isize(i - 1, j + 1).cloned(),
|
||||
self.collision_tiles.get_isize(i , j + 1).cloned(),
|
||||
self.collision_tiles.get_isize(i + 1, j + 1).cloned(),
|
||||
self.collision_tiles.get_isize(i + 1, j ).cloned(),
|
||||
self.collision_tiles.get_isize(i + 1, j - 1).cloned(),
|
||||
self.collision_tiles.get_isize(i , j - 1).cloned(),
|
||||
if i > 0 && j > 0 { self.collision_tiles.get(i - 1, j - 1).cloned() } else { None },
|
||||
if i > 0 { self.collision_tiles.get(i - 1, j ).cloned() } else { None },
|
||||
if i > 0 { self.collision_tiles.get(i - 1, j + 1).cloned() } else { None },
|
||||
self.collision_tiles.get(i , j + 1).cloned(),
|
||||
self.collision_tiles.get(i + 1, j + 1).cloned(),
|
||||
self.collision_tiles.get(i + 1, j ).cloned(),
|
||||
if j > 0 { self.collision_tiles.get(i + 1, j - 1).cloned() } else { None },
|
||||
if j > 0 { self.collision_tiles.get(i , j - 1).cloned() } else { None },
|
||||
]
|
||||
}
|
||||
|
||||
/// Returns the graphic tile corresponding to the collision tiles.
|
||||
pub fn graphic_tile(&self, i: usize, j: usize) -> GraphicTile {
|
||||
if self.collision_tiles[(i, j)].is_full() {
|
||||
GraphicTile::from_neighbour_options(&self.neighbours(i as isize, j as isize))
|
||||
GraphicTile::from_neighbour_options(&self.neighbours(i, j))
|
||||
} else {
|
||||
GraphicTile(None)
|
||||
}
|
||||
|
@ -327,7 +327,7 @@ impl Map {
|
|||
|
||||
/// Returns a tile of the map.
|
||||
pub fn collision_tile(&self, i: usize, j: usize) -> Option<CollisionTile> {
|
||||
self.collision_tiles.get((i, j)).cloned()
|
||||
self.collision_tiles.get(i, j).cloned()
|
||||
}
|
||||
|
||||
/// Changes a tile of the map.
|
||||
|
@ -339,7 +339,7 @@ impl Map {
|
|||
for i in (i - 1) ..= (i + 1) {
|
||||
for j in (j - 1) ..= (j + 1) {
|
||||
let new_tile = self.graphic_tile(i, j);
|
||||
if let Some(tile) = self.graphic_tiles.get_mut((i, j)) {
|
||||
if let Some(tile) = self.graphic_tiles.get_mut(i, j) {
|
||||
*tile = new_tile;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ impl<T> Matrix<T> {
|
|||
}
|
||||
|
||||
/// Returns the tile if any, none otherwise.
|
||||
pub fn get(&self, (row, col): (usize, usize)) -> Option<&T> {
|
||||
pub fn get(&self, row: usize, col: usize) -> Option<&T> {
|
||||
if row < self.rows && col < self.cols {
|
||||
Some(&self[(row, col)])
|
||||
} else {
|
||||
|
@ -78,18 +78,8 @@ impl<T> Matrix<T> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Returns the tile if any, none otherwise.
|
||||
pub fn get_isize(&self, row: isize, col: isize) -> Option<&T> {
|
||||
if row >= 0 && col >= 0 && (row as usize) < self.rows && (col as usize) < self.cols {
|
||||
Some(&self[(row as usize, col as usize)])
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the tile if any.
|
||||
pub fn get_mut(&mut self, (row, col): (usize, usize)) -> Option<&mut T> {
|
||||
pub fn get_mut(&mut self, row: usize, col: usize) -> Option<&mut T> {
|
||||
if row < self.rows && col < self.cols {
|
||||
Some(&mut self[(row, col)])
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue