diff options
author | Tom Barrett <tom@tombarrett.xyz> | 2021-03-21 18:45:36 +0100 |
---|---|---|
committer | Tom Barrett <tom@tombarrett.xyz> | 2021-03-21 18:45:36 +0100 |
commit | 420d0f36adeed7fa254497b49ef91a7574628082 (patch) | |
tree | 0e35934257c8548fe313cfcb59f4b13e07523e3a /src | |
parent | 4312f3b7eedbf6cdbe012be6eea1d45afd82de12 (diff) |
merged animation systems
Diffstat (limited to 'src')
-rw-r--r-- | src/cell.rs | 27 | ||||
-rw-r--r-- | src/main.rs | 21 |
2 files changed, 20 insertions, 28 deletions
diff --git a/src/cell.rs b/src/cell.rs index 1659289..d5d19e2 100644 --- a/src/cell.rs +++ b/src/cell.rs @@ -76,32 +76,13 @@ pub fn insert(mut cell_query: Query<(&mut Cell, &mut TextureAtlasSprite)>) { } } -pub fn explosion_animation( - time: Res<Time>, +pub fn start_explosion( commands: &mut Commands, - mut cell_query: Query<( - Entity, - &mut Cell, - &mut TextureAtlasSprite, - Option<&mut Timer>, - )>, + mut cell_query: Query<(Entity, &Cell), Without<Timer>>, ) { - for (entity, mut cell, mut sprite, timer) in cell_query.iter_mut() { + for (entity, cell) 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),)); - } + commands.insert(entity, (Timer::from_seconds(0.1, true),)); } } } diff --git a/src/main.rs b/src/main.rs index 97592eb..164ffe3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use bevy::math::Vec3; use bevy::prelude::*; -use gems::cell::{self, Cell}; +use gems::cell::{self, Cell, Occupant}; use gems::constants; use rand::{thread_rng, Rng}; @@ -113,9 +113,14 @@ pub fn setup( fn animation_system( commands: &mut Commands, time: Res<Time>, - mut cell_query: Query<(Entity, &mut Timer, &mut TextureAtlasSprite), Without<Cell>>, + mut cell_query: Query<( + Entity, + Option<&mut Cell>, + &mut Timer, + &mut TextureAtlasSprite, + )>, ) { - for (entity, mut timer, mut sprite) in cell_query.iter_mut() { + for (entity, cell, mut timer, mut sprite) in cell_query.iter_mut() { timer.tick(time.delta_seconds()); if timer.finished() { let index = match sprite.index { @@ -135,7 +140,13 @@ fn animation_system( }; sprite.index = index; if index == constants::TILESHEET_NONE2 { - commands.despawn(entity); + if let Some(mut cell) = cell { + cell.occupant = Occupant::None; + sprite.index = cell.occupant.to_index(); + commands.remove_one::<Timer>(entity); + } else { + commands.despawn(entity); + } } } } @@ -250,7 +261,7 @@ impl Plugin for GemsPlugin { app.add_system(cell::insert.system()); app.add_system(cell::falling.system()); app.add_system(cell::check.system()); - app.add_system(cell::explosion_animation.system()); + app.add_system(cell::start_explosion.system()); app.add_system(mouse_system.system()); app.add_system(cosmonaut_detect_system.system()); app.add_system(animation_system.system()); |