Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, "."),
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ 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)]
pub enum Tile {
Robot,
Food,
Empty,
Wall,
}

/// Dictates where the robot is in the world
Expand Down Expand Up @@ -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 }
}
}
Expand Down Expand Up @@ -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;
Expand Down