summaryrefslogtreecommitdiffstats
path: root/src/gates.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/gates.rs')
-rw-r--r--src/gates.rs15
1 files changed, 12 insertions, 3 deletions
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<GatesBullet> 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<GatesBullet> 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<GatesBullet> 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 {