diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/cell.rs | 39 | 
1 files changed, 13 insertions, 26 deletions
| 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();                  }              }          } | 
