From 15fe765d380abc70ed371a2af2806dbb2fa95199 Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Sat, 13 Jan 2024 20:19:11 +0100 Subject: didnt build --- src/cell.rs | 34 ++++++++++++++-------------------- src/main.rs | 29 ++++++++++++++++------------- 2 files changed, 30 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/cell.rs b/src/cell.rs index 0d9b381..53e9860 100644 --- a/src/cell.rs +++ b/src/cell.rs @@ -107,22 +107,16 @@ impl Cell { } } - pub fn set_occupant( - &mut self, - occupant: Occupant, - sprite: &mut TextureAtlasSprite, - visibility: &mut Visibility, - ) { + pub fn set_occupant(&mut self, occupant: Occupant, sprite: &mut TextureAtlasSprite) { self.occupant = occupant; sprite.index = self.occupant.to_index(); - *visibility = Visibility::Inherited; } } -pub fn insert(mut q: Query<(&mut Cell, &mut TextureAtlasSprite, &mut Visibility)>) { - for (mut cell, mut sprite, mut visibility) in q.iter_mut() { +pub fn insert(mut q: Query<(&mut Cell, &mut TextureAtlasSprite)>) { + for (mut cell, mut sprite) in q.iter_mut() { if cell.occupant == Occupant::None && cell.y == constants::GRID_SIZE - 1 { - cell.set_occupant(rand::random(), &mut sprite, &mut visibility); + cell.set_occupant(rand::random(), &mut sprite); } } } @@ -140,9 +134,9 @@ pub fn start_explosion( } } -pub fn check(mut q: Query<(&mut Cell, &mut TextureAtlasSprite, &mut Visibility)>) { +pub fn check(mut q: Query<(&mut Cell, &mut TextureAtlasSprite)>) { let mut cells = [[Cell::default(); constants::GRID_SIZE]; constants::GRID_SIZE]; - for (cell, _, _) in q.iter_mut() { + for (cell, _) in q.iter_mut() { cells[cell.x][cell.y] = *cell; } @@ -187,39 +181,39 @@ pub fn check(mut q: Query<(&mut Cell, &mut TextureAtlasSprite, &mut Visibility)> for c in connected.iter() { for (i, j) in c.iter() { - for (mut cell, mut sprite, mut visibility) in q.iter_mut() { + for (mut cell, mut sprite) in q.iter_mut() { if &cell.x == i && &cell.y == j && cell.occupant != Occupant::Explosion { - cell.set_occupant(Occupant::Explosion, &mut sprite, &mut visibility); + cell.set_occupant(Occupant::Explosion, &mut sprite); } } } } } -pub fn falling(mut q: Query<(&mut Cell, &mut TextureAtlasSprite, &mut Visibility)>) { +pub fn falling(mut q: Query<(&mut Cell, &mut TextureAtlasSprite)>) { let mut have_gems = Vec::new(); - for (cell, _sprite, _visibility) in q.iter_mut() { + for (cell, _sprite) in q.iter_mut() { if cell.occupant != Occupant::None { have_gems.push(*cell); } } let mut moved_gems = Vec::new(); - for (mut cell, mut sprite, mut visibility) in q.iter_mut() { + for (mut cell, mut sprite) in q.iter_mut() { if cell.occupant == Occupant::None { if let Some(c) = have_gems .iter() .find(|&c| (c.x, c.y) == (cell.x, cell.y + 1)) { - cell.set_occupant(c.occupant, &mut sprite, &mut visibility); + cell.set_occupant(c.occupant, &mut sprite); moved_gems.push(c); } } } - for (mut cell, mut sprite, mut visibility) in q.iter_mut() { + for (mut cell, mut sprite) in q.iter_mut() { if moved_gems.iter().any(|c| (c.x, c.y) == (cell.x, cell.y)) { - cell.set_occupant(Occupant::None, &mut sprite, &mut visibility); + cell.set_occupant(Occupant::None, &mut sprite); } } } diff --git a/src/main.rs b/src/main.rs index 627fec0..b06e30c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,7 +110,6 @@ pub fn setup( commands .spawn(SpriteSheetBundle { texture_atlas: atlas_handle.clone(), - visibility: Visibility::Inherited, transform: Transform { translation: Vec3::new( ((i as f32) * constants::TILE_SIZE * constants::TILE_SCALE) - 330.0, @@ -135,10 +134,9 @@ fn animation( Option<&mut Cell>, &mut AnimationTimer, &mut TextureAtlasSprite, - &mut Visibility, )>, ) { - for (entity, cell, mut timer, mut sprite, mut visibility) in q.iter_mut() { + for (entity, cell, mut timer, mut sprite) in q.iter_mut() { timer.tick(time.delta()); if timer.finished() { let index = match sprite.index { @@ -160,7 +158,7 @@ fn animation( if let Some(index) = index { sprite.index = index; } else if let Some(mut cell) = cell { - cell.set_occupant(Occupant::None, &mut sprite, &mut visibility); + cell.set_occupant(Occupant::None, &mut sprite); commands.entity(entity).remove::(); } else { commands.entity(entity).despawn(); @@ -282,7 +280,10 @@ pub fn main() { .set(WindowPlugin { primary_window: Some(Window { title: "gems".to_string(), - resolution: WindowResolution::new(constants::WINDOW_WIDTH,constants::WINDOW_HEIGHT), + resolution: WindowResolution::new( + constants::WINDOW_WIDTH, + constants::WINDOW_HEIGHT, + ), resizable: false, ..default() }), @@ -290,13 +291,15 @@ pub fn main() { }), ) .add_startup_system(setup) - .add_system(cell::insert) - .add_system(cell::falling) - .add_system(cell::check) - .add_system(cell::start_explosion) - .add_system(mouse) - .add_system(cosmonaut_detect) - .add_system(animation) - .add_system(star_spawning) + .add_systems(( + cell::insert, + cell::falling, + cell::check, + cell::start_explosion, + mouse, + cosmonaut_detect, + animation, + star_spawning, + )) .run(); } -- cgit v1.2.3