From b9a6da7ccabb972074f09d686dc78f9643accfac Mon Sep 17 00:00:00 2001 From: Raymond Hogenson Date: Wed, 22 Aug 2018 16:54:43 -0400 Subject: Make taking injuries more flexible I've just moved it into the Enemy trait, because I was planning on having Bill move around when he got hit, but it didn't look good. --- src/gates.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/gates.rs') diff --git a/src/gates.rs b/src/gates.rs index 2c8da82..def618a 100644 --- a/src/gates.rs +++ b/src/gates.rs @@ -95,6 +95,14 @@ fn shorten(x: f64, y: f64, maxlen: f64) -> (f64, f64) { } } +impl Gates { + fn choose_position(&mut self) { + let (x, y) = random_position(); + self.target_x = x; + self.target_y = y; + } +} + impl state::Enemy for Gates { fn new() -> Gates { Gates { x: 200., y: 40., v_x: 0., v_y: 0., a_x: 0., a_y: 0., target_x: 200., target_y: 40., health: 1. } @@ -107,9 +115,7 @@ impl state::Enemy for Gates { /* If we've arrived (close and stopped) */ if (dx*dx + dy*dy).sqrt() < max_velocity / max_accel && (self.v_x*self.v_x + self.v_y*self.v_y).sqrt() < 0.01 { /* Then pick a new target */ - let (x, y) = random_position(); - self.target_x = x; - self.target_y = y; + self.choose_position(); } let dx = self.target_x - self.x; @@ -170,6 +176,9 @@ impl state::Enemy for Gates { fn set_health(&mut self, health: f64) { self.health = health; } + fn injure(&mut self, damage: f64) { + self.health -= damage; + } } impl state::Drawable for GatesBullet { -- cgit v1.3.1