From 3b2017b7f4e7d1c932b430fa515286a9ceaf1a92 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Mon, 2 Apr 2018 15:36:01 +0200 Subject: Added hitboxes and something for the bugs to run into --- src/entities/bug.rs | 15 ++++++++------- src/entities/home.rs | 27 +++++++++++++++++++++++++++ src/entities/mod.rs | 1 + 3 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 src/entities/home.rs (limited to 'src/entities') diff --git a/src/entities/bug.rs b/src/entities/bug.rs index 424e195..482e5c4 100644 --- a/src/entities/bug.rs +++ b/src/entities/bug.rs @@ -1,5 +1,7 @@ use geometry::*; +use hitbox::*; +#[derive(Debug, Clone)] pub struct Bug { pub pos: Vec2d, pub rotation: f64, @@ -29,14 +31,13 @@ impl Bug { }; self.pos = self.pos + delta_pos; } +} - pub fn click(&mut self, point: Vec2d) { - if self.touches(point) { - self.alive = false; - } +impl CircleHitbox for Bug { + fn pos(&self) -> Vec2d { + self.pos } - - fn touches(&self, point: Vec2d) -> bool { - self.pos.distance(point) <= 75. // Some better hit box modelling might be nice? + fn radius(&self) -> f64 { + 75. } } diff --git a/src/entities/home.rs b/src/entities/home.rs new file mode 100644 index 0000000..6f7f53d --- /dev/null +++ b/src/entities/home.rs @@ -0,0 +1,27 @@ +use geometry::*; +use hitbox::*; + +#[derive(Debug, Clone)] +pub struct Home { + pub pos: Vec2d +} + +impl Home { + pub fn new(x: f64, y: f64) -> Home { + Home { + pos: Vec2d { + x: x, + y: y + } + } + } +} + +impl CircleHitbox for Home { + fn pos(&self) -> Vec2d { + self.pos + } + fn radius(&self) -> f64 { + 100. + } +} diff --git a/src/entities/mod.rs b/src/entities/mod.rs index 0f4281c..90b4a11 100644 --- a/src/entities/mod.rs +++ b/src/entities/mod.rs @@ -1 +1,2 @@ pub mod bug; +pub mod home; -- cgit v1.2.3