summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2021-03-21 14:16:03 +0100
committerTom Barrett <tom@tombarrett.xyz>2021-03-21 14:16:03 +0100
commit3449202489951dc0ca43428062439d34f5fc2e8a (patch)
treede461255f071e64bbe29cbecfcb9ad1ca102bbba
parentc24bf56c3d69b826078307ddebb129a7be99ad97 (diff)
mouse hover over gems
-rw-r--r--src/main.rs28
1 files changed, 28 insertions, 0 deletions
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<Windows>,
+ 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());
}
}