diff --git a/src/debug.rs b/src/debug.rs index 2875452..f0b2f11 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -13,8 +13,9 @@ impl GameState for State { for (y, rows) in self.world.read().unwrap().data.iter().enumerate() { for (x, tile) in rows.iter().enumerate() { match tile { - crate::Tile::Robot => ctx.print(x, y, "R"), - crate::Tile::Food => ctx.print(x, y, "F"), + crate::Tile::Robot => ctx.print_color(x, y, RGB::from_f32(0.0, 1.0, 0.0), RGB::from_f32(0.0, 0.0, 0.0), "R"), + crate::Tile::Food => ctx.print_color(x, y, RGB::from_f32(1.0, 0.0, 0.0), RGB::from_f32(0.0, 0.0, 0.0), "F"), + crate::Tile::Wall => ctx.print(x, y, "#"), crate::Tile::Empty => ctx.print_color(x, y, GRAY30, BLACK, "."), } } diff --git a/src/lib.rs b/src/lib.rs index c76e962..8ca3f5c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,7 @@ pub mod debug; // Constansts that dicate the world size const WORLD_HEIGHT: usize = 100; const WORLD_WIDTH: usize = 100; +const N_WALLS: usize = 100; /// Tile in the world, can either be a robot empty or food #[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)] @@ -13,6 +14,7 @@ pub enum Tile { Robot, Food, Empty, + Wall, } /// Dictates where the robot is in the world @@ -56,6 +58,12 @@ impl Default for World { let robot_y = rand::thread_rng().gen_range(1..WORLD_HEIGHT); data[robot_y][robot_x] = Tile::Robot; + for _ in 0..N_WALLS { + let wall_x = rand::thread_rng().gen_range(0..WORLD_WIDTH); + let wall_y = rand::thread_rng().gen_range(1..WORLD_HEIGHT); + data[wall_y][wall_x] = Tile::Wall; + } + Self { data } } } @@ -103,6 +111,10 @@ impl World { return Err(anyhow::anyhow!("out of bounds")); } + if self.data[new_x][new_y] == Tile::Wall { + return Err(anyhow::anyhow!("Boop, hitting a wall")); + } + // Update self.data[new_y][new_x] = Tile::Robot; self.data[old_y][old_x] = Tile::Empty;