diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2023-07-21 19:31:02 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2023-07-21 19:31:02 -0700 |
| commit | 8b51759dc9b26eb9d9e9f94807d7e85a41fbf555 (patch) | |
| tree | 0360fa6d99edf114b1e780acffcf978bc77c2445 /src/gates.rs | |
| parent | Update my email. (diff) | |
| download | stallman-shooter-8b51759dc9b26eb9d9e9f94807d7e85a41fbf555.tar.zst | |
Remove unnecessary "extern crate" declarations.
Diffstat (limited to 'src/gates.rs')
| -rw-r--r-- | src/gates.rs | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/src/gates.rs b/src/gates.rs index 83cc9bc..ebc2b69 100644 --- a/src/gates.rs +++ b/src/gates.rs @@ -1,8 +1,5 @@ -extern crate rand; -extern crate std; - -use super::state; use super::constants; +use super::state; pub struct Gates { x: f64, @@ -25,7 +22,12 @@ pub struct GatesBullet { impl GatesBullet { pub fn new(x: i32, d_x: f64, y: i32, d_y: f64) -> GatesBullet { - GatesBullet { real_x: x as f64, real_y: y as f64, d_x: d_x, d_y: d_y } + GatesBullet { + real_x: x as f64, + real_y: y as f64, + d_x: d_x, + d_y: d_y, + } } } @@ -54,7 +56,10 @@ impl state::Positioned for Gates { } fn random_position() -> (f64, f64) { - (rand::random::<f64>() * (constants::X_DIM - 200) as f64 + 100., rand::random::<f64>() * 100.) + ( + rand::random::<f64>() * (constants::X_DIM - 200) as f64 + 100., + rand::random::<f64>() * 100., + ) } impl state::StraightBullet for GatesBullet { @@ -79,15 +84,16 @@ impl state::StraightBullet for GatesBullet { } fn random_bullet<T: state::Enemy<GatesBullet>>(enemy: &T) -> GatesBullet { - let multiplier = 2. + 3.*(1. - enemy.health()); - let theta: f64 = rand::random::<f64>()*2.*std::f64::consts::PI/3. + std::f64::consts::PI/6.; + let multiplier = 2. + 3. * (1. - enemy.health()); + let theta: f64 = + rand::random::<f64>() * 2. * std::f64::consts::PI / 3. + std::f64::consts::PI / 6.; let dx = f64::cos(theta) * multiplier; let dy = f64::sin(theta) * multiplier; GatesBullet::new(enemy.x(), dx, enemy.y(), dy) } fn shorten(x: f64, y: f64, maxlen: f64) -> (f64, f64) { - let len = f64::sqrt(x*x + y*y); + let len = f64::sqrt(x * x + y * y); if len > maxlen { (x / len / 2., y / len / 2.) } else { @@ -105,7 +111,17 @@ impl Gates { 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. } + 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., + } } fn act(&mut self, count: u64) -> Vec<GatesBullet> { let max_accel = (1. - self.health) * 0.75 + 0.25; @@ -113,7 +129,9 @@ impl state::Enemy<GatesBullet> for Gates { let dx = self.target_x - self.x; let dy = self.target_y - self.y; /* 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 { + 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 */ self.choose_position(); } @@ -121,7 +139,7 @@ impl state::Enemy<GatesBullet> for Gates { let dx = self.target_x - self.x; let dy = self.target_y - self.y; /* If we're close */ - if (dx*dx + dy*dy).sqrt() < max_velocity / max_accel { + if (dx * dx + dy * dy).sqrt() < max_velocity / max_accel { /* Then slow down */ let (x, y) = shorten(-self.v_x, -self.v_y, max_accel); self.a_x = x; @@ -134,7 +152,7 @@ impl state::Enemy<GatesBullet> for Gates { } /* If we're going too fast */ - if (self.v_x*self.v_x + self.v_y*self.v_y).sqrt() > max_velocity { + if (self.v_x * self.v_x + self.v_y * self.v_y).sqrt() > max_velocity { /* Then don't go faster */ if self.v_x.signum() == self.a_x.signum() { self.a_x = 0.; |
