Skip to content

Commit

Permalink
Impeach the ball to go out
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed May 11, 2012
1 parent 2f6e0b5 commit b738ec5
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions javascript/ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,37 @@ var Ball=new Class({
var nextX=this.x + Math.cos(this.angle)*this.speed;
var nextY=this.y + Math.sin(this.angle)*this.speed;
this.remove();
this.x=nextX;
this.y=nextY;
if(nextY >this.game.height)
{
this.speed=0;
}
else
{
if(nextX < 0 || nextX > this.game.width)
{
this.inverseAngleX();
}
else
{
this.x=nextX;
}
if(nextY < 0)
{
this.inverseAngleY();
}
else
{
this.y=nextY;
}
}
this.draw();
},
inverseAngleX : function() {
this.angle=(Math.PI - this.angle)%(2*Math.PI);
},
inverseAngleY : function(deviation) {
this.angle=(2*Math.PI - this.angle -(deviation?deviation:0))%(2*Math.PI);
},
destruct : function() {
}
});

0 comments on commit b738ec5

Please sign in to comment.