mazeir/map/orthogonal/
mod.rs1mod depth_first;
2mod stdout;
3mod image;
4
5use super::Direction2D;
6
7pub const LEFT_WALL: u8 = 0b0000_0010;
8pub const UP_WALL: u8 = 0b0000_0001;
9
10pub struct Orthogonal {
19 width: usize,
20 height: usize,
21 map: Vec<u8>,
22}
23
24impl Orthogonal {
25 pub fn new(width: usize, height: usize) -> Self {
26 Orthogonal {
27 width,
28 height,
29 map: vec![0; width * height],
30 }
31 }
32 pub fn center_point(&self) -> (usize, usize) {
33 (self.width / 2, self.height / 2)
34 }
35
36 pub fn get(&self, x: usize, y: usize) -> &u8 {
37 &self.map[y * self.width + x]
38 }
39 pub fn get_mut(&mut self, x: usize, y: usize) -> &mut u8 {
40 &mut self.map[y * self.width + x]
41 }
42
43 pub fn set(&mut self, x: usize, y: usize, value: u8) {
44 self.map[y * self.width + x] = value;
45 }
46
47 pub fn break_wall(&mut self, x: usize, y: usize, wall: &Direction2D) {
49 match wall {
50 Direction2D::Left => self.map[y * self.width + x] |= LEFT_WALL,
51 Direction2D::Right => self.map[y * self.width + x + 1] |= LEFT_WALL,
52 Direction2D::Up => self.map[y * self.width + x] |= UP_WALL,
53 Direction2D::Down => self.map[(y + 1) * self.width + x] |= UP_WALL,
54 }
55 }
56}
57
58impl Default for Orthogonal {
59 fn default() -> Self {
60 Orthogonal {
61 width: 32,
62 height: 32,
63 map: vec![0; 32 * 32],
64 }
65 }
66}