From 38caea2a14bb3c205e4c42daa9f11f0f60550360 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Wed, 12 Sep 2018 21:39:34 +0200 Subject: Changed hitboxed from an 'is a hitbox' to a 'has a hitbox' --- src/main.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/main.rs') 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 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 for BugBasherGame { fn key_down(&mut self, key: KeyCode, ctx: &mut AppContext) { 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; } -- cgit v1.2.3