Add Chunk set_cell function
This commit is contained in:
parent
28e604a804
commit
8c75efa08a
|
@ -75,6 +75,15 @@ impl Chunk {
|
||||||
dirty_rect: DirtyRect::default(),
|
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>) {
|
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 frac = chunk.width / 2;
|
||||||
let x = (chunk.width - frac) / 2 + rand::thread_rng().gen_range(0..frac);
|
let x = (chunk.width - frac) / 2 + rand::thread_rng().gen_range(0..frac);
|
||||||
let y = chunk.height - 1;
|
let y = chunk.height - 1;
|
||||||
let index = x + y * chunk.width;
|
chunk.set_cell(x, y, Element::Sand);
|
||||||
chunk.cells[index] = Element::Sand;
|
|
||||||
chunk.dirty_rect.add_point(x, y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn simulate_chunk_system(mut chunk: Query<&mut Chunk>) {
|
pub fn simulate_chunk_system(mut chunk: Query<&mut Chunk>) {
|
||||||
|
|
Loading…
Reference in New Issue