Add commands for diagonal movement
Cribbed directly from Nethack This was really, really easy.
This commit is contained in:
parent
bf03ebc549
commit
405dbffe37
5 changed files with 17 additions and 4 deletions
|
@ -6,3 +6,4 @@
|
||||||
# everyone who runs the test benefits from these saved cases.
|
# everyone who runs the test benefits from these saved cases.
|
||||||
cc 16afe2473971397314ffa77acf7bad62f0c40bc3f591aff7aa9193c29e5a0921 # shrinks to items = [(Position { x: 92, y: 60 }, ""), (Position { x: 92, y: 60 }, "")]
|
cc 16afe2473971397314ffa77acf7bad62f0c40bc3f591aff7aa9193c29e5a0921 # shrinks to items = [(Position { x: 92, y: 60 }, ""), (Position { x: 92, y: 60 }, "")]
|
||||||
cc 3a68a382c3bb8fdf60ea150a369abbdd45859e0c54cd6a4f7c75937a6c783b98 # shrinks to mut em = EntityMap { by_position: {Position { x: 25, y: 33 }: [1]}, by_id: {1: TestEntity { position: Position { x: 25, y: 33 }, name: "" }}, last_id: 1 }, ent = TestEntity { position: Position { x: 25, y: 33 }, name: "" }, new_position = Position { x: 0, y: 0 }
|
cc 3a68a382c3bb8fdf60ea150a369abbdd45859e0c54cd6a4f7c75937a6c783b98 # shrinks to mut em = EntityMap { by_position: {Position { x: 25, y: 33 }: [1]}, by_id: {1: TestEntity { position: Position { x: 25, y: 33 }, name: "" }}, last_id: 1 }, ent = TestEntity { position: Position { x: 25, y: 33 }, name: "" }, new_position = Position { x: 0, y: 0 }
|
||||||
|
cc ffd7181e1c0343ab4c2ac92990f068d24c8663158c1c0a9526cd9edc470f950a # shrinks to mut em = EntityMap { by_position: {Position { x: 64, y: 58 }: [1]}, by_id: {1: TestEntity { position: Position { x: 64, y: 58 }, name: "" }}, last_id: 1 }, ent = TestEntity { position: Position { x: 0, y: 0 }, name: "" }, new_position = Position { x: 64, y: 58 }
|
||||||
|
|
|
@ -23,6 +23,11 @@ impl Command {
|
||||||
Char('k') | Char('w') | Key::Up => Some(Move(Up)),
|
Char('k') | Char('w') | Key::Up => Some(Move(Up)),
|
||||||
Char('j') | Char('s') | Key::Down => Some(Move(Down)),
|
Char('j') | Char('s') | Key::Down => Some(Move(Down)),
|
||||||
Char('l') | Char('d') | Key::Right => Some(Move(Right)),
|
Char('l') | Char('d') | Key::Right => Some(Move(Right)),
|
||||||
|
Char('y') => Some(Move(UpLeft)),
|
||||||
|
Char('u') => Some(Move(UpRight)),
|
||||||
|
Char('b') => Some(Move(DownLeft)),
|
||||||
|
Char('n') => Some(Move(DownRight)),
|
||||||
|
|
||||||
Ctrl('p') => Some(PreviousMessage),
|
Ctrl('p') => Some(PreviousMessage),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,4 +6,8 @@ pub enum Direction {
|
||||||
Up,
|
Up,
|
||||||
Down,
|
Down,
|
||||||
Right,
|
Right,
|
||||||
|
UpLeft,
|
||||||
|
UpRight,
|
||||||
|
DownRight,
|
||||||
|
DownLeft,
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,10 +234,9 @@ mod tests {
|
||||||
em.get(entity_id).map(|e| e.position()),
|
em.get(entity_id).map(|e| e.position()),
|
||||||
Some(new_position)
|
Some(new_position)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert!(
|
||||||
em.at(new_position).iter().map(
|
em.at(new_position).iter().map(
|
||||||
|e| e.name.clone()).collect::<Vec<_>>(),
|
|e| e.name.clone()).any(|en| en == ent.name),
|
||||||
vec![ent.name]
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ pub mod direction;
|
||||||
pub mod entity_map;
|
pub mod entity_map;
|
||||||
pub use collision::Collision;
|
pub use collision::Collision;
|
||||||
pub use direction::Direction;
|
pub use direction::Direction;
|
||||||
pub use direction::Direction::{Down, Left, Right, Up};
|
pub use direction::Direction::*;
|
||||||
use proptest_derive::Arbitrary;
|
use proptest_derive::Arbitrary;
|
||||||
use termion::cursor;
|
use termion::cursor;
|
||||||
|
|
||||||
|
@ -217,6 +217,10 @@ impl ops::Add<Direction> for Position {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
UpLeft => self + Up + Left,
|
||||||
|
UpRight => self + Up + Right,
|
||||||
|
DownLeft => self + Down + Left,
|
||||||
|
DownRight => self + Down + Right,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue