const $       = require('jquery');
var canvas    = document.getElementById('game');
var context   = canvas.getContext('2d');
var Game      = require('./game.js');

var game      = new Game(canvas, context);
listen();

function listen () {
    requestAnimationFrame(function gameLoop () {
        if (game.lives > 0) {
            context.clearRect(0, 0, canvas.width, canvas.height);
            game.spaceTime.drawAll();

            requestAnimationFrame(gameLoop);
        }
        else {
            gameOver();
        }
  });
};

window.addEventListener("keydown", checkKeyDown, false);
window.addEventListener("keyup", checkKeyUp, false);

function checkKeyDown (e) {
    if (e.keyCode == "32") { //spacebar
        game.spaceTime.fireLaser();
    }
    else if(e.keyCode == "68") { //d
        if(game.spaceTime.mines.length < 5) {
        game.spaceTime.layMine();
        }
    }
    else if (e.keyCode == "37") { // left
        game.spaceTime.ship.updateAngle(-15);
    }
    else if(e.keyCode == "39") { // right
        game.spaceTime.ship.updateAngle(15);
    }
    else if(e.keyCode == "38") { // up
        thrustShip(game.spaceTime);
    }
    else if(e.keyCode == "40") { //down
        game.spaceTime.activeShield();
    }
    game.spaceTime.ship.moveShip();

}

function checkKeyUp (e) {
    if (e.keyCode == "40") { //down
        game.spaceTime.shields = [];
    }

    game.spaceTime.ship.flame = false;
}

function thrustShip (spaceTime) {
    if(spaceTime.ship.velocity <= 0) {
        spaceTime.ship.thrustAngle = spaceTime.ship.angle;
        spaceTime.ship.velocity += .2;
    }
    else if(spaceTime.ship.thrustAngle !== spaceTime.ship.angle) {
        if(spaceTime.ship.velocity > 0) {
        spaceTime.ship.velocity -= .3;
        }
        else {
            spaceTime.ship.velocity = 0;
        }
    }
    else if(spaceTime.ship.thrustAngle === spaceTime.ship.angle) {
        if(spaceTime.ship.velocity < 3) {
            spaceTime.ship.velocity += .2;
        }
    }

    spaceTime.ship.moveShip();
    spaceTime.ship.flame = true;
}

function gameOver () {
    context.clearRect(0, 0, canvas.width, canvas.height);
    $('#game').toggle();
    $('#game-window').append('<div id="game-over"><p>GAME OVER<br>Score: ' + game.score + '</p></div>');
}
@@ -303,32 +303,62 @@
 me.lives %3E 0) %7B%0A
+            listenForInput();%0A
             cont
@@ -667,24 +667,432 @@
 p, false);%0A%0A
+var keys = %7B%0A    %2237%22: false, // left%0A    %2239%22: false, // right%0A    %2240%22: false  // down%0A%7D%0A%0Afunction listenForInput () %7B%0A    if (keys%5B%2237%22%5D) %7B // left%0A        game.spaceTime.ship.updateAngle(-4);%0A    %7D%0A    else if(keys%5B%2239%22%5D) %7B // right%0A        game.spaceTime.ship.updateAngle(4);%0A    %7D%0A    else if(keys%5B%2240%22%5D) %7B // down%0A        game.spaceTime.activeShield();%0A    %7D%0A%0A    game.spaceTime.ship.moveShip();%0A%7D;%0A%0A%0A
 function che
@@ -1138,16 +1138,17 @@
 2%22) %7B //
+ 
 spacebar
@@ -1225,16 +1225,17 @@
 8%22) %7B //
+ 
 d%0A      
@@ -1274,32 +1274,36 @@
  %3C 5) %7B%0A        
+    
 game.spaceTime.l
@@ -1382,44 +1382,25 @@
     
-game.spaceTime.ship.updateAngle(-15)
+keys%5B%2237%22%5D = true
 ;%0A  
@@ -1457,43 +1457,25 @@
     
-game.spaceTime.ship.updateAngle(15)
+keys%5B%2239%22%5D = true
 ;%0A  
@@ -1586,32 +1586,33 @@
 de == %2240%22) %7B //
+ 
 down%0A        gam
@@ -1612,146 +1612,421 @@
     
-game.spaceTime.activeShield();%0A    %7D%0A    game.spaceTime.ship.moveShip();%0A%0A%7D%0A%0Afunction checkKeyUp (e) %7B%0A    if (e.keyCode == %2240%22) %7B //down
+keys%5B%2240%22%5D = true;%0A    %7D%0A%7D%0A%0Afunction checkKeyUp (e) %7B%0A    if(e.keyCode == %2268%22) %7B // d%0A        keys%5B%2268%22%5D = false;%0A    %7D%0A    else if (e.keyCode == %2237%22) %7B // left%0A        keys%5B%2237%22%5D = false;%0A    %7D%0A    else if(e.keyCode == %2239%22) %7B // right%0A        keys%5B%2239%22%5D = false;%0A    %7D%0A    else if(e.keyCode == %2238%22) %7B // up%0A        keys%5B%2258%22%5D = false;%0A    %7D%0A    else if(e.keyCode == %2240%22) %7B //down%0A        keys%5B%2240%22%5D = false;
 %0A   
@@ -2619,17 +2619,17 @@
 ocity %3C 
-3
+2
 ) %7B%0A    

Remove delay from ship rotation