From cee4589ff116394b94643b37e251c2be67fe369c Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sun, 3 Jun 2018 21:01:42 +0200 Subject: Added a custom cursor --- src/main.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/main.rs') 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 for BugBasherGame { @@ -86,6 +87,9 @@ impl App 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 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 -- cgit v1.2.3