summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs22
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() {