summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/astroid.rs4
-rw-r--r--src/connection.rs13
-rw-r--r--src/mass.rs1
-rw-r--r--src/ship.rs23
4 files changed, 35 insertions, 6 deletions
diff --git a/src/astroid.rs b/src/astroid.rs
index fb14751..28009ca 100644
--- a/src/astroid.rs
+++ b/src/astroid.rs
@@ -44,6 +44,10 @@ impl Mass for Astroid {
serde_json::to_string(self).unwrap()
}
+ fn slow(&mut self) {
+
+ }
+
fn process(&mut self) {
self.position.0 += self.velocity.0;
self.position.1 += self.velocity.1;
diff --git a/src/connection.rs b/src/connection.rs
index bcd4a30..8cf2a15 100644
--- a/src/connection.rs
+++ b/src/connection.rs
@@ -68,12 +68,13 @@ impl Connection {
let mut data = String::new();
match self.buff_r.read_line(&mut data) {
Ok(result) => match data.as_bytes() {
- b"5\n" => acceleration.0 += 1.0,
- b"0\n" => acceleration.0 -= 1.0,
- b"8\n" => acceleration.1 += 1.0,
- b"2\n" => acceleration.1 -= 1.0,
- b"4\n" => acceleration.2 += 1.0,
- b"6\n" => acceleration.2 -= 1.0,
+ b"5\n" => acceleration.0 += 0.1,
+ b"0\n" => acceleration.0 -= 0.1,
+ b"8\n" => acceleration.1 += 0.1,
+ b"2\n" => acceleration.1 -= 0.1,
+ b"4\n" => acceleration.2 += 0.1,
+ b"6\n" => acceleration.2 -= 0.1,
+ b"-\n" => masses[self.index].slow(),
_ => {
if result == 0 {
self.open = false;
diff --git a/src/mass.rs b/src/mass.rs
index d91b292..30442ec 100644
--- a/src/mass.rs
+++ b/src/mass.rs
@@ -5,6 +5,7 @@ pub trait Mass : Any {
fn position(&self) -> (f64, f64, f64);
fn serialize(&self) -> String;
fn process(&mut self);
+ fn slow(&mut self);
fn give_acceleration(&mut self, acceleration : (f64, f64, f64));
}
diff --git a/src/ship.rs b/src/ship.rs
index 30c68d9..0ea97e0 100644
--- a/src/ship.rs
+++ b/src/ship.rs
@@ -39,6 +39,29 @@ impl Mass for Ship {
serde_json::to_string(self).unwrap()
}
+ fn slow(&mut self) {
+ if self.velocity.0 > 0.01 {
+ self.velocity.0 += -1.0 * self.velocity.0 * 0.1;
+ }
+ else {
+ self.velocity.0 = 0.0;
+ }
+
+ if self.velocity.1 > 0.01 {
+ self.velocity.1 += -1.0 * self.velocity.1 * 0.1;
+ }
+ else {
+ self.velocity.1 = 0.0;
+ }
+
+ if self.velocity.2 > 0.01 {
+ self.velocity.2 += -1.0 * self.velocity.2 * 0.1;
+ }
+ else {
+ self.velocity.2 = 0.0;
+ }
+ }
+
fn process(&mut self) {
self.position.0 += self.velocity.0;
self.position.1 += self.velocity.1;