diff options
Diffstat (limited to 'src/ship.rs')
-rw-r--r-- | src/ship.rs | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/ship.rs b/src/ship.rs index 08b4d93..2482db1 100644 --- a/src/ship.rs +++ b/src/ship.rs @@ -1,7 +1,7 @@ use mass::{Mass, Type}; extern crate serde_json; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct Ship { name : String, position : (f64, f64, f64), @@ -22,14 +22,6 @@ impl Ship { target : None, } } - - pub fn give_target(&mut self, target : Option<usize>) { - self.target = target; - } - - pub fn range(&self) -> f64 { - self.r - } } impl Mass for Ship { @@ -45,6 +37,14 @@ impl Mass for Ship { serde_json::to_string(self).unwrap() } + fn range(&self) -> f64 { + self.r + } + + fn give_target(&mut self, target : Option<usize>) { + self.target = target; + } + fn slow(&mut self) { if self.velocity.0 > 0.01 { self.velocity.0 += -1.0 * self.velocity.0 * 0.1; @@ -68,6 +68,10 @@ impl Mass for Ship { } } + fn box_clone(&self) -> Box<Mass> { + Box::new((*self).clone()) + } + fn process(&mut self) { self.position.0 += self.velocity.0; self.position.1 += self.velocity.1; |