summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2021-03-21 16:18:52 +0100
committerTom Barrett <tom@tombarrett.xyz>2021-03-21 16:18:52 +0100
commit5198891f3683c656f8e50a99a3a271b4e0734293 (patch)
tree6ede819f411f4daecc4996be92a50c5df70a2417
parentd3ae44a367de28934f64155be7b4f04bd63db1dc (diff)
visor animation with hover
-rw-r--r--src/main.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index d9a468f..5577a11 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -285,6 +285,60 @@ pub fn setup(
}
}
+fn cosmonaut_animation_system(
+ commands: &mut Commands,
+ time: Res<Time>,
+ mut cell_query: Query<(Entity, &mut Timer, &mut TextureAtlasSprite), Without<Cell>>,
+) {
+ for (entity, mut timer, mut sprite) in cell_query.iter_mut() {
+ timer.tick(time.delta_seconds());
+ if timer.finished() {
+ let index = match sprite.index {
+ 9 => 10,
+ 10 => 13,
+ 13 => 14,
+ 11 => 12,
+ _ => 11,
+ };
+ sprite.index = index;
+ if index == 12 {
+ commands.remove_one::<Timer>(entity);
+ commands.remove_one::<TextureAtlasSprite>(entity);
+ }
+ }
+ }
+}
+
+fn cosmonaut_detect_system(
+ commands: &mut Commands,
+ windows: Res<Windows>,
+ mut cell_query: Query<(&Transform, &TextureAtlasSprite)>,
+) {
+ if let Some(mut cursor_position) = windows
+ .get_primary()
+ .and_then(|window| window.cursor_position())
+ {
+ cursor_position.x -= 400.0 - 16.0 * 3.5 * 0.5;
+ cursor_position.y -= 300.0 - 16.0 * 3.5 * 0.5;
+ for (transform, sprite) in cell_query.iter_mut() {
+ if transform.translation.x < cursor_position.x
+ && transform.translation.x + 16.0 * 3.5 > cursor_position.x
+ && transform.translation.y < cursor_position.y
+ && transform.translation.y + 16.0 * 3.5 > cursor_position.y
+ && sprite.index == 8
+ {
+ commands
+ .spawn(SpriteSheetBundle {
+ sprite: TextureAtlasSprite::new(9),
+ transform: *transform,
+ ..Default::default()
+ })
+ .with(Timer::from_seconds(0.1, true));
+ }
+ }
+ }
+}
+
fn mouse_system(
windows: Res<Windows>,
mut cell_query: Query<(&mut Cell, &mut Transform, &mut TextureAtlasSprite)>,
@@ -366,6 +420,8 @@ impl Plugin for GemsPlugin {
app.add_system(cell_check_system.system());
app.add_system(explosion_animation_system.system());
app.add_system(mouse_system.system());
+ app.add_system(cosmonaut_detect_system.system());
+ app.add_system(cosmonaut_animation_system.system());
}
}