diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 39 |
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()); } } |