summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2021-03-20 17:22:49 +0100
committerTom Barrett <tom@tombarrett.xyz>2021-03-20 17:22:49 +0100
commitc24bf56c3d69b826078307ddebb129a7be99ad97 (patch)
treeb806be0a14f3355705c2fd6d93baf267f554e958 /src/main.rs
parentc657649cdc1a4159f2c76852b32fc563d1279509 (diff)
explosion animation system
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index c81203f..4df4fa7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -73,6 +73,36 @@ fn cell_insert_system(mut cell_query: Query<(&mut Cell, &mut TextureAtlasSprite)
}
}
+fn explosion_animation_system(
+ time: Res<Time>,
+ commands: &mut Commands,
+ mut cell_query: Query<(
+ Entity,
+ &mut Cell,
+ &mut TextureAtlasSprite,
+ Option<&mut Timer>,
+ )>,
+) {
+ for (entity, mut cell, mut sprite, timer) in cell_query.iter_mut() {
+ if cell.occupant == Occupant::Explosion {
+ if let Some(mut timer) = timer {
+ timer.tick(time.delta_seconds());
+ if timer.finished() {
+ if sprite.index < 7 && sprite.index >= 4 {
+ sprite.index += 1;
+ } else {
+ cell.occupant = Occupant::None;
+ sprite.index = cell.occupant.to_index();
+ commands.remove_one::<Timer>(entity);
+ }
+ }
+ } else {
+ commands.insert(entity, (Timer::from_seconds(0.1, true),));
+ }
+ }
+ }
+}
+
fn cell_check_system(mut cell_query: Query<(&mut Cell, &mut TextureAtlasSprite)>) {
let mut cells = [[Cell::default(); constants::COLUMNS]; constants::ROWS];
for (cell, _) in cell_query.iter_mut() {
@@ -99,10 +129,10 @@ fn cell_check_system(mut cell_query: Query<(&mut Cell, &mut TextureAtlasSprite)>
}
for c in connected.iter() {
- if c.len() > 3 {
+ if c.len() > 4 {
for (i, j) in c.iter() {
for (mut cell, mut sprite) in cell_query.iter_mut() {
- if &cell.x == i && &cell.y == j {
+ if &cell.x == i && &cell.y == j && cell.occupant != Occupant::Explosion {
cell.occupant = Occupant::Explosion;
sprite.index = cell.occupant.to_index();
}
@@ -130,10 +160,10 @@ fn cell_check_system(mut cell_query: Query<(&mut Cell, &mut TextureAtlasSprite)>
}
for c in connected.iter() {
- if c.len() > 3 {
+ if c.len() > 4 {
for (i, j) in c.iter() {
for (mut cell, mut sprite) in cell_query.iter_mut() {
- if &cell.x == i && &cell.y == j {
+ if &cell.x == i && &cell.y == j && cell.occupant != Occupant::Explosion {
cell.occupant = Occupant::Explosion;
sprite.index = cell.occupant.to_index();
}
@@ -258,6 +288,7 @@ impl Plugin for GemsPlugin {
app.add_system(cell_insert_system.system());
app.add_system(cell_falling_system.system());
app.add_system(cell_check_system.system());
+ app.add_system(explosion_animation_system.system());
}
}