-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let npcs attack player on same tile
- Loading branch information
Showing
4 changed files
with
34 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::cmp; | ||
|
||
use eo::{data::EOChar, protocol::Coords}; | ||
|
||
use super::Map; | ||
|
||
impl Map { | ||
pub fn get_adjacent_tiles(&self, coords: &Coords) -> Vec<Coords> { | ||
let mut adjacent_tiles = Vec::with_capacity(5); | ||
adjacent_tiles.push(*coords); | ||
adjacent_tiles.push(Coords { | ||
x: coords.x, | ||
y: cmp::max(coords.y as i32 - 1, 0) as EOChar, | ||
}); | ||
adjacent_tiles.push(Coords { | ||
x: coords.x, | ||
y: cmp::min(coords.y as i32 + 1, self.file.height as i32) as EOChar, | ||
}); | ||
adjacent_tiles.push(Coords { | ||
x: cmp::max(coords.x as i32 - 1, 0) as EOChar, | ||
y: coords.y, | ||
}); | ||
adjacent_tiles.push(Coords { | ||
x: cmp::min(coords.x as i32 + 1, self.file.width as i32) as EOChar, | ||
y: coords.y, | ||
}); | ||
|
||
adjacent_tiles.dedup(); | ||
adjacent_tiles | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters