commit aa0be729b7b521ae37d3af83f3007fb6d3a6a99c
parent 8427900b8cd375c3fe35881fe62a8595d74a733c
Author: = <=>
Date: Mon, 30 Dec 2019 13:14:31 +1300
Feat: Add 1 line of sight in all directions for every piece.
Diffstat:
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/src/main.rs b/src/main.rs
@@ -158,7 +158,7 @@ impl EventHandler for Game {
);
// draw enemy pieces that are within 2 squares of an
// allied piece.
- for (x, y) in self.moves((x as i32, y as i32)) {
+ for (x, y) in self.line_of_sight((x as i32, y as i32)) {
if let Some(Piece { player, unit, .. }) =
self.board.get((x as i32, y as i32))
{
@@ -387,6 +387,26 @@ impl Game {
.filter(|(x, y)| !self.contains_ally((*x, *y)))
.collect()
}
+ // Calculate line of sight for any piece at the given coordinate.
+ pub fn line_of_sight(&self, pos: (i32, i32)) -> Vec<(i32, i32)> {
+ let (x, y) = pos;
+ self.moves(pos)
+ .into_iter()
+ .chain(
+ vec![
+ (x + 1, y + 1),
+ (x - 1, y - 1),
+ (x + 1, y - 1),
+ (x - 1, y + 1),
+ (x + 1, y),
+ (x - 1, y),
+ (x, y + 1),
+ (x, y - 1),
+ ]
+ .into_iter(),
+ )
+ .collect()
+ }
/// Move a piece and conclude the turn.
pub fn move_turn(&mut self, from: (i32, i32), to: (i32, i32)) {
if self.contains_ally(from) {