summaryrefslogtreecommitdiffstats
path: root/src/state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/state.rs')
-rw-r--r--src/state.rs32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/state.rs b/src/state.rs
index bf62f51..663e762 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -1,9 +1,5 @@
-extern crate sdl2;
-extern crate std;
-extern crate rand;
-
-use super::player;
use super::constants;
+use super::player;
pub trait StraightBullet: Positioned + Drawable {
fn real_x(&self) -> f64;
@@ -64,7 +60,12 @@ impl<T: StraightBullet> Bullet for T {
impl PBullet {
pub fn new(x: i32, d_x: f64, y: i32, d_y: f64) -> PBullet {
- PBullet { real_x: x as f64, real_y: y as f64, d_x: d_x, d_y: d_y }
+ PBullet {
+ real_x: x as f64,
+ real_y: y as f64,
+ d_x: d_x,
+ d_y: d_y,
+ }
}
pub fn damage() -> f64 {
0.01
@@ -89,14 +90,20 @@ pub struct State<T, U> {
impl<T: Enemy<U>, U> State<T, U> {
pub fn new() -> State<T, U> {
- State { player: player::Player::new(), enemies: vec![T::new()], bullets: Vec::new(), count: 0, player_bullets: Vec::new() }
+ State {
+ player: player::Player::new(),
+ enemies: vec![T::new()],
+ bullets: Vec::new(),
+ count: 0,
+ player_bullets: Vec::new(),
+ }
}
}
fn dist(x1: i32, y1: i32, x2: i32, y2: i32) -> f64 {
let xdist = x1 - x2;
let ydist = y1 - y2;
- f64::sqrt((xdist*xdist + ydist*ydist) as f64)
+ f64::sqrt((xdist * xdist + ydist * ydist) as f64)
}
pub trait Positioned {
@@ -122,7 +129,10 @@ pub trait Positioned {
fn outside(&self) -> bool {
let x = self.x();
let y = self.y();
- x < -100 || x > constants::X_DIM as i32 + 100 || y < -100 || y > constants::Y_DIM as i32 + 100
+ x < -100
+ || x > constants::X_DIM as i32 + 100
+ || y < -100
+ || y > constants::Y_DIM as i32 + 100
}
}
@@ -146,7 +156,9 @@ pub trait Drawable: Positioned {
let (cx, cy) = Self::center();
let x0 = self.x() - cx as i32;
let y0 = self.y() - cy as i32;
- canvas.copy(&texture, None, Some(sdl2::rect::Rect::new(x0, y0, tw, th))).unwrap();
+ canvas
+ .copy(&texture, None, Some(sdl2::rect::Rect::new(x0, y0, tw, th)))
+ .unwrap();
}
}