Changed hitboxed from an 'is a hitbox' to a 'has a hitbox'
[bug-basher.git] / src / main.rs
index 6ed2dbf..16e2836 100644 (file)
@@ -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;
                     }