From 23ba31868d99f17f2736d57d9a0f7a0eec0a5415 Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Sun, 21 Mar 2021 19:54:39 +0100 Subject: simplified check system --- src/cell.rs | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) (limited to 'src/cell.rs') diff --git a/src/cell.rs b/src/cell.rs index 48bc387..51b68e8 100644 --- a/src/cell.rs +++ b/src/cell.rs @@ -93,10 +93,11 @@ pub fn check(mut q: Query<(&mut Cell, &mut TextureAtlasSprite)>) { let mut last = Occupant::None; let mut connected = Vec::new(); - for (i, _) in cells.iter().enumerate() { + for (i, row) in cells.iter().enumerate() { let mut c = Vec::new(); - for j in 0..constants::GRID_SIZE { - if cells[i][j].occupant == last && last != Occupant::None { + for (j, _) in row.iter().enumerate() { + if cells[i][j].occupant == last && last != Occupant::None && last != Occupant::Explosion + { c.push((i, j)); c.push((i, j - 1)); } else { @@ -109,25 +110,11 @@ pub fn check(mut q: Query<(&mut Cell, &mut TextureAtlasSprite)>) { last = Occupant::None; } - for c in connected.iter() { - if c.len() > 4 { - for (i, j) in c.iter() { - for (mut cell, mut sprite) in q.iter_mut() { - if &cell.x == i && &cell.y == j && cell.occupant != Occupant::Explosion { - cell.occupant = Occupant::Explosion; - sprite.index = cell.occupant.to_index(); - } - } - } - } - } - - connected.clear(); - for (i, row) in cells.iter().enumerate() { let mut c = Vec::new(); for (j, _) in row.iter().enumerate() { - if cells[j][i].occupant == last && last != Occupant::None { + if cells[j][i].occupant == last && last != Occupant::None && last != Occupant::Explosion + { c.push((j, i)); c.push((j - 1, i)); } else { @@ -140,14 +127,14 @@ pub fn check(mut q: Query<(&mut Cell, &mut TextureAtlasSprite)>) { last = Occupant::None; } + connected = connected.into_iter().filter(|c| c.len() > 4).collect(); + for c in connected.iter() { - if c.len() > 4 { - for (i, j) in c.iter() { - for (mut cell, mut sprite) in q.iter_mut() { - if &cell.x == i && &cell.y == j && cell.occupant != Occupant::Explosion { - cell.occupant = Occupant::Explosion; - sprite.index = cell.occupant.to_index(); - } + for (i, j) in c.iter() { + for (mut cell, mut sprite) in q.iter_mut() { + if &cell.x == i && &cell.y == j && cell.occupant != Occupant::Explosion { + cell.occupant = Occupant::Explosion; + sprite.index = cell.occupant.to_index(); } } } -- cgit v1.2.3