summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/geometry.rs3
-rw-r--r--src/main.rs17
2 files changed, 18 insertions, 2 deletions
diff --git a/src/geometry.rs b/src/geometry.rs
index f84a973..6f7f658 100644
--- a/src/geometry.rs
+++ b/src/geometry.rs
@@ -7,6 +7,9 @@ pub struct Vec2d {
}
impl Vec2d {
+ pub fn new(x: f64, y: f64) -> Vec2d {
+ Vec2d {x, y}
+ }
pub fn distance(&self, other: Vec2d) -> f64 {
self.distance_squared(other).sqrt()
}
diff --git a/src/main.rs b/src/main.rs
index 857e744..c98c80e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -32,7 +32,8 @@ struct BugBasherGame {
lives: i64,
game_over: bool,
time_to_next_bug: f64,
- total_time: f64
+ total_time: f64,
+ cursor_pos: Vec2d
}
impl App<AssetId> for BugBasherGame {
@@ -86,6 +87,9 @@ impl App<AssetId> for BugBasherGame {
bug.alive = false;
}
},
+ InputEvent::MouseMotion(x, y) => {
+ self.cursor_pos = Vec2d::new(x,y);
+ },
InputEvent::KeyPressed(KeyCode::Return) => {
self.reset();
},
@@ -130,6 +134,14 @@ impl App<AssetId> for BugBasherGame {
BugBasherGame::print_string(renderer, &points_str, Alignment::Center, 0., -25.);
}
}
+
+ {
+ let mut renderer = renderer.sprite_mode();
+ renderer.draw(
+ &Affine::translate(self.cursor_pos.x, self.cursor_pos.y),
+ SpriteId::Cursor
+ );
+ }
}
}
@@ -149,7 +161,8 @@ impl BugBasherGame {
lives: 0,
game_over: true,
time_to_next_bug: 0.,
- total_time: 0.
+ total_time: 0.,
+ cursor_pos: Vec2d::new(0.,0.)
};
game.reset();
game