Difference between revisions of "Game"

From CodeStuff
Jump to: navigation, search
Line 1: Line 1:
 
<edcode>
 
<edcode>
 +
  
  
Line 6: Line 7:
 
// make player stay in box
 
// make player stay in box
 
// make player hit balls
 
// make player hit balls
 +
  
  
Line 14: Line 16:
 
var ball_3 = {cx:340, cy:440, dx:-3, dy:3, colour:'blue'};
 
var ball_3 = {cx:340, cy:440, dx:-3, dy:3, colour:'blue'};
 
var ball_4 = {cx:350, cy:140, dx:3, dy:3, colour:'green'};
 
var ball_4 = {cx:350, cy:140, dx:3, dy:3, colour:'green'};
 +
 +
var activeBalls = [ball_1,ball_2,ball_3,ball_4];
 +
  
 
var player = {x:320, y:200, speed:3};
 
var player = {x:320, y:200, speed:3};
Line 31: Line 36:
 
   //        and if cy has crossed the top or bottom edges of the box
 
   //        and if cy has crossed the top or bottom edges of the box
 
   if (ball.cy<boxTop) ball.dy=3;
 
   if (ball.cy<boxTop) ball.dy=3;
   if (ball.cy>boxBottom)gb ball.dy=-3;
+
   if (ball.cy>boxBottom) ball.dy=-3;
 +
 
 +
 
 +
  var distance=distanceToPlayer(ball);
 +
 
 +
  if (distance < 20) {
 +
    ball.colour = "Black";
 +
  }
 +
 
 +
 
 
}
 
}
  
Line 53: Line 67:
  
 
function move() {
 
function move() {
  moveBall(ball_1);
 
  moveBall(ball_2);
 
  moveBall(ball_3);
 
  moveBall(ball_4);
 
 
    
 
    
   if (keyIsDown(38)) player.y-=player.speed;
+
  //moveBall(ball_1);
   if (keyIsDown(40)) player.y+=player.speed;
+
  //moveBall(ball_2);
   if (keyIsDown(37)) player.x-=player.speed;
+
  //moveBall(ball_3);
   if (keyIsDown(39)) player.x+=player.speed;
+
  //moveBall(ball_4);
 +
 
 +
  var i = 0;
 +
  for (i=0; i<activeBalls.length;i++) {
 +
    var ourBall = activeBalls[i];
 +
    moveBall(ourBall);
 +
  }
 +
 
 +
 
 +
   ///if (keyIsDown(38)) player.y-=player.speed;
 +
   //if (keyIsDown(40)) player.y+=player.speed;
 +
   //if (keyIsDown(37)) player.x-=player.speed;
 +
   //if (keyIsDown(39)) player.x+=player.speed;
 +
 
 +
  if (keyIsDown(32)) activeBalls.push({cx:350, cy:140, dx:Math.random()*6-3, dy:Math.random()*6-3, colour:'green'});
 +
 
 +
  var m = getMousePosition();
 +
  player.x=m.x;
 +
  player.y=m.y;
 +
 
 
}
 
}
  
Line 69: Line 98:
 
   //draw the balls  
 
   //draw the balls  
 
    
 
    
   drawBall(ball_1);
+
   //drawBall(ball_1);
   drawBall(ball_2);
+
   //drawBall(ball_2);
   drawBall(ball_3);
+
   //drawBall(ball_3);
   drawBall(ball_4);
+
   //drawBall(ball_4);
 +
 
 +
  var i = 0;
 +
  for (i=0; i<activeBalls.length;i++) {
 +
    var ourBall = activeBalls[i];
 +
    drawBall(ourBall);
 +
  }
 
    
 
    
 
   //draw the box
 
   //draw the box
Line 84: Line 119:
  
 
run(move,draw);
 
run(move,draw);
 
 
  
 
</edcode>
 
</edcode>

Revision as of 21:35, 16 May 2012