From 4d7a7e368a3f0a6b1261e1b9180a2647eb158047 Mon Sep 17 00:00:00 2001 From: tom barrett Date: Fri, 13 Apr 2018 03:39:24 -0500 Subject: moved over to mass struct with enum for types --- src/astroid.rs | 75 ---------------------------------------------------------- 1 file changed, 75 deletions(-) delete mode 100644 src/astroid.rs (limited to 'src/astroid.rs') diff --git a/src/astroid.rs b/src/astroid.rs deleted file mode 100644 index f95e362..0000000 --- a/src/astroid.rs +++ /dev/null @@ -1,75 +0,0 @@ -extern crate rand; -extern crate serde_json; - -use self::rand::distributions::Range; -use self::rand::distributions::Sample; - -use item::Item; -use storage::Storage; -use mass::{Mass, MassType}; - -#[derive(Serialize, Deserialize, Debug, Clone)] -pub struct Astroid { - mass_type : MassType, - position : (f64, f64, f64), - velocity : (f64, f64, f64), - resouces : Storage, -} - -impl Astroid { - pub fn new() -> Astroid { - let mut rng = rand::thread_rng(); - - let mut pr = Range::new(-50.0, 50.0); - let position = (pr.sample(&mut rng), pr.sample(&mut rng), pr.sample(&mut rng)); - - let mut vr = Range::new(-0.5, 0.5); - let velocity = (vr.sample(&mut rng), vr.sample(&mut rng), vr.sample(&mut rng)); - - let mut rr = Range::new(0, 20); - let mut resouces = Vec::new(); - for _ in 0..rr.sample(&mut rng) { - resouces.push(Item::new("Iron", 1)) - } - Astroid { - mass_type : MassType::Astroid, - position : position, - velocity : velocity, - resouces : Storage::new(resouces), - } - } -} - -impl Mass for Astroid { - fn recv_mass_type(&self) -> MassType { - self.mass_type.clone() - } - - fn position(&self) -> (f64, f64, f64) { - self.position - } - - fn serialize(&self) -> String { - serde_json::to_string(self).unwrap() - } - - fn box_clone(&self) -> Box { - Box::new((*self).clone()) - } - - fn process(&mut self) { - self.position.0 += self.velocity.0; - self.position.1 += self.velocity.1; - self.position.2 += self.velocity.2; - } - - fn recv_velocity(&self) -> (f64, f64, f64) { - self.velocity - } - - fn give_acceleration(&mut self, acceleration : (f64, f64, f64)) { - self.velocity.0 += acceleration.0; - self.velocity.1 += acceleration.1; - self.velocity.2 += acceleration.2; - } -} -- cgit v1.2.3