summaryrefslogtreecommitdiff
path: root/src/modules/engines.rs
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2018-04-23 06:25:55 -0500
committertom barrett <spalf0@gmail.com>2018-04-23 06:25:55 -0500
commit923e49d29ce2f51df608011db192cbb73e8f7345 (patch)
tree1813395ed810b3f5a810cb13abd5bf39f94349ef /src/modules/engines.rs
parent7211ed31e5412eb84f8fbf0e3a465305068f1d7c (diff)
-split up module.rs
Diffstat (limited to 'src/modules/engines.rs')
-rw-r--r--src/modules/engines.rs70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/modules/engines.rs b/src/modules/engines.rs
new file mode 100644
index 0000000..10e4c85
--- /dev/null
+++ b/src/modules/engines.rs
@@ -0,0 +1,70 @@
+use mass::Mass;
+
+#[derive(Serialize, Deserialize, Debug, Clone)]
+pub struct Engines {
+ acceleration : (f64, f64, f64),
+}
+
+impl Engines {
+ pub fn new() -> Engines {
+ Engines {
+ acceleration : (0.0, 0.0, 0.0)
+ }
+ }
+
+ pub fn recv_acceleration(&mut self) -> (f64, f64, f64) {
+ let acceleration = self.acceleration;
+ self.acceleration = (0.0, 0.0, 0.0);
+ acceleration
+ }
+
+ pub fn give_client_data(&mut self, ship : &Mass, target : Option<&Mass>, data : String) {
+ let mut acceleration = (0.0, 0.0, 0.0);
+ match data.as_bytes() {
+ 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" => {
+ let m_v = ship.velocity;
+ acceleration = (m_v.0 * 0.05,
+ m_v.1 * 0.05,
+ m_v.2 * 0.05);
+ },
+ b"-\n" => {
+ let m_v = ship.velocity;
+ acceleration = (-1.0 * m_v.0 * 0.05,
+ -1.0 * m_v.1 * 0.05,
+ -1.0 * m_v.2 * 0.05);
+ },
+ b"c\n" => {
+ match target {
+ Some(target) => {
+ let d_v = target.velocity;
+ let m_v = ship.velocity;
+ acceleration = (d_v.0 - m_v.0,
+ d_v.1 - m_v.1,
+ d_v.2 - m_v.2);
+ },
+ None => (),
+ }
+ },
+ b"t\n" => {
+ match target {
+ Some(target) => {
+ let d_p = target.position;
+ let m_p = ship.position;
+ acceleration = ((d_p.0 - m_p.0) * 0.01,
+ (d_p.1 - m_p.1) * 0.01,
+ (d_p.2 - m_p.2) * 0.01);
+ },
+ None => (),
+ }
+ },
+ _ => (),
+ }
+ self.acceleration = acceleration;
+ }
+}