summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2021-03-21 19:54:39 +0100
committerTom Barrett <tom@tombarrett.xyz>2021-03-21 19:54:39 +0100
commit23ba31868d99f17f2736d57d9a0f7a0eec0a5415 (patch)
tree24df6b83d134cfec5334d7640a423dde25369a93
parent9a57ab99eb0162cbc55064639db69a1d9ff26d76 (diff)
simplified check system
-rw-r--r--src/cell.rs39
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();
}
}
}