// Hyperspace is Asteroids in Javascript
//
// Current code is based off of the examples from
// http://coquette.maryrosecook.com/
var Hyperspace = function() {
  this.c = new Coquette(this, "canvas", 1000, 600, "#000");

  this.connect();

  this.c.entities.create(Person, { center: { x:250, y:40 }, color:"#099" });

  this.c.entities.create(Person, { center: { x:256, y:110 }, color:"#f07",
    update: function() {
      if (this.c.inputter.isDown(this.c.inputter.UP_ARROW)) {
        this.center.y -= 0.4;
      }
    },
    collision: function(other) {
      other.center.y = this.center.y; // follow the player
    }
  });
};

Hyperspace.prototype.connect = function() {
  this.socket = new WebSocket("ws://" + window.location.host + "/ws");

  var that = this;
  this.socket.onopen = function() {
    console.log("websocket connected");
    that.socket.send("test");
  };

  this.socket.onclose = function() {
    console.log("websocket disconnected");
  };

  this.socket.onmessage = function(msg) {
    console.log("websocket received message", msg);
  };
}

var Person = function(game, settings) {
  this.c = game.c;
  for (var i in settings) {
    this[i] = settings[i];
  }

  this.size = { x:9, y:9 };
  this.draw = function(ctx) {
    ctx.fillStyle = settings.color;
    ctx.fillRect(
        this.center.x - this.size.x / 2,
        this.center.y - this.size.y / 2,
        this.size.x,
        this.size.y);
  };
};

window.addEventListener('load', function() {
  new Hyperspace();
});

@@ -40,58 +40,91 @@
 t%0A//
-%0A// Current code is based off of
+ Authors: @kenpratt and @icco%0A//%0A// This code is dependent on
  the 
-examples from
+coquette library:
 %0A// 
@@ -156,16 +156,79 @@
 ook.com/
+%0A%0A// The main game initializer. This function sets up the game.
 %0Avar Hyp
@@ -336,83 +336,194 @@
 %0A%0A  
-this.c.entities.create(Person, %7B center: %7B x:250, y:40 %7D, color:%22#099%22 %7D);%0A
+// Create the ship that the current player drives. It differs from all other%0A  // ships in that it has an update loop (called every tick) that takes in%0A  // directions from the keyboard.
 %0A  t
@@ -544,22 +544,20 @@
 .create(
-Person
+Ship
 , %7B cent
@@ -613,24 +613,61 @@
 unction() %7B%0A
+      // TODO(icco): Support W and ,%0A
       if (th
@@ -758,112 +758,429 @@
   %7D%0A
+%0A
     
-%7D,%0A    collision: functio
+  // TODO(icco): Support S and O%0A      if (this.c.inputter.isDow
 n(
-o
 th
-er) %7B%0A      other.center.y = this.center.y; // follow the player
+is.c.inputter.DOWN_ARROW)) %7B%0A        this.center.y += 0.4;%0A      %7D%0A%0A      // TODO(icco): Support D and E%0A      if (this.c.inputter.isDown(this.c.inputter.RIGHT_ARROW)) %7B%0A        this.center.x += 0.4;%0A      %7D%0A%0A      // TODO(icco): Support A%0A      if (this.c.inputter.isDown(this.c.inputter.LEFT_ARROW)) %7B%0A        this.center.x -= 0.4;%0A      %7D
 %0A    %7D
+,
 %0A  %7D
@@ -1625,18 +1625,134 @@
 %0A%7D%0A%0A
-var Person
+// The actual ship entity. One of these will be created for every single player%0A// in the game. Please set the color.%0Avar Ship
  = f
@@ -2147,16 +2147,83 @@
 ion() %7B%0A
+  // Begin the game once the page is loaded! Party like it's 1979!%0A
   new Hy

set up charecter movement.