From 9a473ee4d711a03241bf0e94dfac1017094e32cd Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Wed, 31 Jan 2024 16:07:06 +0000 Subject: [PATCH] Add initial water cells to chunk --- src/falling_sand/mod.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/falling_sand/mod.rs b/src/falling_sand/mod.rs index 83c3e9d..29f918c 100644 --- a/src/falling_sand/mod.rs +++ b/src/falling_sand/mod.rs @@ -74,13 +74,21 @@ pub struct Chunk { impl Chunk { pub fn new(width: usize, height: usize) -> Self { - Self { + let mut initial = Self { step: 0, width, height, cells: vec![Element::Air; width * height], dirty_rect: DirtyRect::default(), + }; + + let max_y = height / 10; + for y in 0..=max_y { + for x in 0..width { + initial.set_cell(x, y, Element::Water); + } } + initial } pub fn set_cell(&mut self, x: usize, y: usize, element: Element) {