diff options
| author | Raymond Hogenson <rhogenson@posteo.net> | 2018-08-22 16:54:43 -0400 |
|---|---|---|
| committer | Raymond Hogenson <rhogenson@posteo.net> | 2018-08-22 16:54:43 -0400 |
| commit | b9a6da7ccabb972074f09d686dc78f9643accfac (patch) | |
| tree | f12b13003142571c07909b354fa1f9e6e2155566 /src/gates.rs | |
| parent | 6879976d47a218c0f48a2fd33d11d154f1fbbb8f (diff) | |
| download | stallman-shooter-b9a6da7ccabb972074f09d686dc78f9643accfac.tar.zst | |
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.
Diffstat (limited to 'src/gates.rs')
| -rw-r--r-- | src/gates.rs | 15 |
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 { |
