Add Chunk set_cell function

This commit is contained in:
Jarrod Doyle 2024-01-29 15:21:17 +00:00
parent 28e604a804
commit 8c75efa08a
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 10 additions and 3 deletions

View File

@ -75,6 +75,15 @@ impl Chunk {
dirty_rect: DirtyRect::default(),
}
}
pub fn set_cell(&mut self, x: usize, y: usize, element: Element) {
if x >= self.width || y >= self.height {
return;
}
self.cells[x + y * self.width] = element;
self.dirty_rect.add_point(x, y);
}
}
pub fn place_sand_system(mut chunk: Query<&mut Chunk>) {
@ -88,9 +97,7 @@ pub fn place_sand_system(mut chunk: Query<&mut Chunk>) {
let frac = chunk.width / 2;
let x = (chunk.width - frac) / 2 + rand::thread_rng().gen_range(0..frac);
let y = chunk.height - 1;
let index = x + y * chunk.width;
chunk.cells[index] = Element::Sand;
chunk.dirty_rect.add_point(x, y);
chunk.set_cell(x, y, Element::Sand);
}
pub fn simulate_chunk_system(mut chunk: Query<&mut Chunk>) {