HTML and CSS Reference
In-Depth Information
update ();
testWalls ();
collide ();
render ();
}
function
function update () {
for
for ( var
var i = 0 ; i < balls . length ; i ++ ) {
ball = balls [ i ];
//Friction
ball . velocityx = ball . velocityx - ( ball . velocityx * friction );
ball . velocityy = ball . velocityy - ( ball . velocityy * friction );
ball . nextx = ( ball . x += ball . velocityx );
ball . nexty = ( ball . y += ball . velocityy );
}
}
function
function testWalls () {
var
var ball ;
var
var testBall ;
for
for ( var
var i = 0 ; i < balls . length ; i ++ ) {
ball = balls [ i ];
iif ( ball . nextx + ball . radius > theCanvas . width ) {
ball . velocityx = ball . velocityx *- 1 ;
ball . nextx = theCanvas . width - ball . radius ;
} else
else iif ( ball . nextx - ball . radius < 0 ) {
ball . velocityx = ball . velocityx *- 1 ;
ball . nextx = ball . radius ;
} else
else iif ( ball . nexty + ball . radius > theCanvas . height ) {
ball . velocityy = ball . velocityy *- 1 ;
ball . nexty = theCanvas . height - ball . radius ;
} else
else iif ( ball . nexty - ball . radius < 0 ) {
ball . velocityy = ball . velocityy *- 1 ;
ball . nexty = ball . radius ;
}
}
Search WWH ::




Custom Search