Add chunk constructor

This commit is contained in:
Jarrod Doyle 2024-01-29 15:15:46 +00:00
parent 508f7d7ad8
commit a57b457f49
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 20 additions and 16 deletions

View File

@ -46,14 +46,7 @@ fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
let image_handle = images.add(image); let image_handle = images.add(image);
commands commands.spawn(Chunk::new(256, 256)).insert(SpriteBundle {
.spawn(Chunk {
width: 256,
height: 256,
cells: vec![Elements::Air; 256 * 256],
dirty_rect: DirtyRect::default(),
})
.insert(SpriteBundle {
sprite: Sprite { sprite: Sprite {
flip_y: true, flip_y: true,
..default() ..default()
@ -73,6 +66,17 @@ pub struct Chunk {
dirty_rect: DirtyRect, dirty_rect: DirtyRect,
} }
impl Chunk {
pub fn new(width: usize, height: usize) -> Self {
Self {
width,
height,
cells: vec![Elements::Air; width * height],
dirty_rect: DirtyRect::default(),
}
}
}
pub fn place_sand_system(mut chunk: Query<&mut Chunk>) { pub fn place_sand_system(mut chunk: Query<&mut Chunk>) {
// We know for now there's only one chunk // We know for now there's only one chunk
let chunk = chunk.get_single_mut(); let chunk = chunk.get_single_mut();