summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 6ed2dbf..16e2836 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -50,7 +50,8 @@ impl App<AssetId> for BugBasherGame {
self.bugs.retain(|b| b.alive);
for bug in &mut self.bugs {
bug.advance(seconds);
- if self.home.touches_circle(bug) {
+
+ if Hitbox::intersect(&self.home.hitbox(), &bug.hitbox()) {
bug.alive = false;
self.lives -= 1;
}
@@ -91,10 +92,14 @@ impl App<AssetId> for BugBasherGame {
fn key_down(&mut self, key: KeyCode, ctx: &mut AppContext<AssetId>) {
let (x, y) = self.camera.invert_translate().apply_f64(ctx.cursor());
+ let cursor_hitbox = Hitbox::Circle(CircleHitbox {
+ pos: Vec2d::new(x, y),
+ radius: 10.
+ });
match key {
KeyCode::MouseLeft => {
let mut hit = false;
- for bug in self.bugs.iter_mut().filter(|bug| bug.touches_point(Vec2d::new(x, y))) {
+ for bug in self.bugs.iter_mut().filter(|bug| Hitbox::intersect(&cursor_hitbox, &bug.hitbox())) {
if !self.game_over && bug.alive {
self.points += 1;
}