diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2018-08-11 16:30:03 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2018-08-11 16:30:03 +0200 |
commit | 092eb4685e9073b046c98371ab15f85156426d15 (patch) | |
tree | 7d366e6b7a3dda606a68608d760aa71ea4d53516 /src/main.rs | |
parent | 3b90ccfcc15b13ff06cfd98dc4817b5d692ef97e (diff) |
New cursors!!!
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 22 |
1 files changed, 18 insertions, 4 deletions
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<AssetId> for BugBasherGame { @@ -90,12 +91,16 @@ impl App<AssetId> 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<AssetId> 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() { |