From 893805baa14972dc6c1c28170856097bb54bf280 Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Sat, 10 Apr 2021 13:06:25 +0200 Subject: redid how visibility works, moved setting occupants to a fucntion, setup animation function better --- src/main.rs | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) (limited to 'src/main.rs') 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::(); - } 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::(); + } else { + commands.entity(entity).despawn(); } } } -- cgit v1.2.3