From 3449202489951dc0ca43428062439d34f5fc2e8a Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Sun, 21 Mar 2021 14:16:03 +0100 Subject: mouse hover over gems --- src/main.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 4df4fa7..bb65f81 100644 --- a/src/main.rs +++ b/src/main.rs @@ -281,6 +281,33 @@ pub fn setup( } } +fn mouse_system( + windows: Res, + mut cell_query: Query<(&Cell, &mut Transform, &mut 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 (_, _, mut sprite) in cell_query.iter_mut() { + sprite.color.set_a(1.0); + } + + for (_, transform, mut 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.color.set_a(0.5); + } + } + } +} + pub struct GemsPlugin; impl Plugin for GemsPlugin { fn build(&self, app: &mut AppBuilder) { @@ -289,6 +316,7 @@ impl Plugin for GemsPlugin { app.add_system(cell_falling_system.system()); app.add_system(cell_check_system.system()); app.add_system(explosion_animation_system.system()); + app.add_system(mouse_system.system()); } } -- cgit v1.2.3