//game objects
var paddle1;
var paddle2;
var ball;
var divider;
var player1Score;
var player2Score;

//initialize all the things
function init() {

    //game pieces
    leftPaddle = new component(20, 100, "white", 60, 120);
    rightPaddle = new component(20, 100, "white", 1200, 120);

    player1Score = new scoreNumbers(30, 30, "green", 10, 120);
    player2Score = new scoreNumbers(30, 30, "green", 10, 120);
    
    //start the game
    game.start();
}

//main game object
var game = {
    canvas : document.getElementById("pong"),
    start : function() {
        this.canvas.width = 1280;
        this.canvas.height = 720;
        this.context = this.canvas.getContext("2d");
        this.interval = setInterval(update, 20);
        //background
        this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);

        //input
        window.addEventListener('keydown', function (e) {
            e.preventDefault();
            game.keys = (game.keys || []);
            game.keys[e.keyCode] = (e.type == "keydown");
        });
        window.addEventListener('keyup', function (e) {
            game.keys[e.keyCode] = (e.type == "keydown");
        });
    },
    stop : function() {
        clearInterval(this.interval);
    },    
    clear : function() {
        this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
    }
}

function scoreNumbers(score,x,y){

}

//game object
function component(width, height, color, x, y) {
    //object attributes
    this.width = width;
    this.height = height;
    this.speedX = 0;
    this.speedY = 0; 
    this.x = x;
    this.y = y;

    //functions called by update loop
    this.update = function() {
        context = game.context;
        context.fillStyle = color;
        context.fillRect(this.x, this.y, this.width, this.height);
    }
    this.newPos = function() {
        this.y += this.speed; 
    }

    //check for collison with another object 
    this.crashWith = function(otherobj) {
        
        var myleft = this.x;
        var myright = this.x + (this.width);
        var mytop = this.y;
        var mybottom = this.y + (this.height);

        var otherleft = otherobj.x;
        var otherright = otherobj.x + (otherobj.width);
        var othertop = otherobj.y;
        var otherbottom = otherobj.y + (otherobj.height);

        //should maybe re-write this to assume false, rather than assume true and prove wrong - may reduce any possible false positives
        var crash = true;
        
        if ((mybottom < othertop) ||
               (mytop > otherbottom) ||
               (myright < otherleft) ||
               (myleft > otherright)) {
           crash = false;
        }

        return crash;
    }
}

//update loop
function update(){
    //if collision, stop the game, else, update all the things
    // if (myGamePiece.crashWith(myObstacle)) {
    //     mygame.stop();
    // } else {
    //     mygame.clear();
    //     myObstacle.update();
    //     myGamePiece.newPos(); 
    //     myGamePiece.update();
    // }
    game.clear();

    rightPaddle.speed = 0;
    leftPaddle.speed = 0;
    
    if (game.keys && game.keys[38]) {rightPaddle.speed = -10; }
    if (game.keys && game.keys[40]) {rightPaddle.speed = 10; }

    leftPaddle.newPos();
    leftPaddle.update();

    rightPaddle.newPos();
    rightPaddle.update();
}

@@ -1,105 +1,4 @@
-//game objects%0Avar paddle1;%0Avar paddle2;%0Avar ball;%0Avar divider;%0Avar player1Score;%0Avar player2Score;%0A%0A
 //in
@@ -58,24 +58,28 @@
  pieces%0A    
+var 
 leftPaddle =
@@ -121,24 +121,28 @@
 , 120);%0A    
+var 
 rightPaddle 
@@ -188,24 +188,28 @@
  120);%0A%0A    
+var 
 player1Score
@@ -259,16 +259,20 @@
 0);%0A    
+var 
 player2S
@@ -540,16 +540,73 @@
  = 720;%0A
+        this.canvas.style.cursor = %22none%22; //hide cursor%0A
         
@@ -813,16 +813,35 @@
 //input%0A
+        //Keyboard%0A
         
@@ -1157,24 +1157,172 @@
         %7D);%0A
+        //mouse%0A        window.addEventListener('mousemove', function (e) %7B%0A            game.x = e.pageX;%0A            game.y = e.pageY;%0A        %7D);%0A
     %7D,%0A    s
@@ -2957,19 +2957,16 @@
 ings%0A   
- //
  if (myG
@@ -2998,27 +2998,24 @@
 acle)) %7B%0A   
- //
      mygame.
@@ -3025,19 +3025,16 @@
 p();%0A   
- //
  %7D else 
@@ -3034,27 +3034,24 @@
 %7D else %7B%0A   
- //
      mygame.
@@ -3058,27 +3058,24 @@
 clear();%0A   
- //
      myObsta
@@ -3087,27 +3087,24 @@
 pdate();%0A   
- //
      myGameP
@@ -3122,19 +3122,16 @@
 (); %0A   
- //
      myG
@@ -3152,19 +3152,16 @@
 e();%0A   
- //
  %7D%0A    g
@@ -3228,24 +3228,48 @@
 d = 0;%0A    %0A
+    //keyboard movement%0A
     if (game
@@ -3380,24 +3380,182 @@
 ed = 10; %7D%0A%0A
+    //mouse movement, y axis only%0A    if (game.y) %7B%0A        //DISABLED FOR NOW, testing is easier with the keyboard%0A        //rightPaddle.y = game.y; %0A    %7D%0A%0A
     leftPadd

clean up, add mouse control