implemented Distribution for Direction
This commit is contained in:
parent
ecaeceb1e7
commit
36bcdd1518
|
@ -1,4 +1,6 @@
|
|||
use crate::{Image, Tileset, Vec2};
|
||||
use rand::prelude::Distribution;
|
||||
use rand::Rng;
|
||||
use std::rc::Rc;
|
||||
|
||||
//odd-q vertical layout https://www.redblobgames.com/grids/hexagons
|
||||
|
@ -125,3 +127,16 @@ impl HexMap {
|
|||
(coord.x + coord.y * self.size.x) as usize
|
||||
}
|
||||
}
|
||||
|
||||
impl Distribution<Direction> for Direction {
|
||||
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Direction {
|
||||
match rng.gen_range(0..6) {
|
||||
0 => Direction::North,
|
||||
1 => Direction::NorthEast,
|
||||
2 => Direction::SouthEast,
|
||||
3 => Direction::South,
|
||||
4 => Direction::SouthWest,
|
||||
_ => Direction::NorthWest,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue