diff options
author | Tom Barrett <tom@tombarrett.xyz> | 2021-04-10 13:06:25 +0200 |
---|---|---|
committer | Tom Barrett <tom@tombarrett.xyz> | 2021-04-10 13:06:25 +0200 |
commit | 893805baa14972dc6c1c28170856097bb54bf280 (patch) | |
tree | c240dbd965bad732afb3729c5b32e801e4b2171a /src/main.rs | |
parent | 6f2cf244f8d92068963207205125f2167768ff53 (diff) |
redid how visibility works, moved setting occupants to a fucntion, setup animation function better
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/src/main.rs b/src/main.rs index 8a59000..c69d791 100644 --- a/src/main.rs +++ b/src/main.rs @@ -100,7 +100,10 @@ pub fn setup( commands .spawn_bundle(SpriteSheetBundle { texture_atlas: atlas_handle.clone(), - sprite: TextureAtlasSprite::new(constants::TILESHEET_NONE1), + visible: Visible { + is_visible: false, + is_transparent: true, + }, transform: Transform { translation: Vec3::new( ((i as f32) * constants::TILE_SIZE * constants::TILE_SCALE) - 330.0, @@ -125,35 +128,35 @@ fn animation( Option<&mut Cell>, &mut Timer, &mut TextureAtlasSprite, + &mut Visible, )>, ) { - for (entity, cell, mut timer, mut sprite) in q.iter_mut() { + for (entity, cell, mut timer, mut sprite, mut visible) in q.iter_mut() { timer.tick(time.delta()); if timer.finished() { let index = match sprite.index { - constants::TILESHEET_EXPLOSION1 => constants::TILESHEET_EXPLOSION2, - constants::TILESHEET_EXPLOSION2 => constants::TILESHEET_EXPLOSION3, - constants::TILESHEET_EXPLOSION3 => constants::TILESHEET_EXPLOSION4, + constants::TILESHEET_EXPLOSION1 => Some(constants::TILESHEET_EXPLOSION2), + constants::TILESHEET_EXPLOSION2 => Some(constants::TILESHEET_EXPLOSION3), + constants::TILESHEET_EXPLOSION3 => Some(constants::TILESHEET_EXPLOSION4), + constants::TILESHEET_EXPLOSION4 => Some(constants::TILESHEET_EXPLOSION5), - constants::TILESHEET_VISOR1 => constants::TILESHEET_VISOR2, - constants::TILESHEET_VISOR2 => constants::TILESHEET_VISOR3, - constants::TILESHEET_VISOR3 => constants::TILESHEET_VISOR4, + constants::TILESHEET_VISOR1 => Some(constants::TILESHEET_VISOR2), + constants::TILESHEET_VISOR2 => Some(constants::TILESHEET_VISOR3), + constants::TILESHEET_VISOR3 => Some(constants::TILESHEET_VISOR4), - constants::TILESHEET_STAR1 => constants::TILESHEET_STAR2, - constants::TILESHEET_STAR2 => constants::TILESHEET_STAR3, + constants::TILESHEET_STAR1 => Some(constants::TILESHEET_STAR2), + constants::TILESHEET_STAR2 => Some(constants::TILESHEET_STAR3), - constants::TILESHEET_NONE1 => constants::TILESHEET_NONE2, - _ => constants::TILESHEET_NONE1, + _ => None, }; - sprite.index = index; - if index == constants::TILESHEET_NONE2 { - if let Some(mut cell) = cell { - cell.occupant = Occupant::None; - sprite.index = cell.occupant.to_index(); - commands.entity(entity).remove::<Timer>(); - } else { - commands.entity(entity).despawn(); - } + + if let Some(index) = index { + sprite.index = index; + } else if let Some(mut cell) = cell { + cell.set_occupant(Occupant::None, &mut sprite, &mut visible); + commands.entity(entity).remove::<Timer>(); + } else { + commands.entity(entity).despawn(); } } } |