From 092eb4685e9073b046c98371ab15f85156426d15 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sat, 11 Aug 2018 16:30:03 +0200 Subject: New cursors!!! --- src/main.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index e6932af..55c8594 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,7 +35,8 @@ struct BugBasherGame { game_over: bool, time_to_next_bug: f64, total_time: f64, - camera: Affine + camera: Affine, + cursor: SpriteId } impl App for BugBasherGame { @@ -90,12 +91,16 @@ impl App for BugBasherGame { let (x, y) = self.camera.invert_translate().apply_f64(ctx.cursor()); match key { KeyCode::MouseLeft => { + let mut hit = false; for bug in self.bugs.iter_mut().filter(|bug| bug.touches_point(Vec2d { x, y })) { if !self.game_over && bug.alive == true { self.points += 1; } - bug.alive = false; + hit = true; + } + if hit { + self.rotate_cursor(); } }, KeyCode::Return => { @@ -155,7 +160,7 @@ impl App for BugBasherGame { let mut renderer = renderer.sprite_mode(); renderer.draw( &Affine::translate(cursor_x, cursor_y), - SpriteId::Cursor + self.cursor ); } } @@ -178,7 +183,8 @@ impl BugBasherGame { game_over: true, time_to_next_bug: 0., total_time: 0., - camera: Affine::id() + camera: Affine::id(), + cursor: SpriteId::Cursor1 }; game.reset(); game @@ -221,6 +227,14 @@ impl BugBasherGame { renderer.draw(&affine, tile); }; } + + fn rotate_cursor(&mut self) { + self.cursor = match self.cursor { + SpriteId::Cursor1 => SpriteId::Cursor2, + SpriteId::Cursor2 => SpriteId::Cursor3, + _ => SpriteId::Cursor1 + } + } } fn main() { -- cgit v1.2.3