topical media & game development
out-of-bound(s)
if ( sprite.x - sprite.width/2 > right ||
sprite.x + sprite.width/2 < left ||
sprite.y - sprite.height/2 > bottom ||
sprite.y + sprite.height/2 < top )
{
...
}

out-of-bound wrap(s)
if (sprite.x - sprite.width/2 > right) {
sprite.x = left - sprite.width/2;
} else if (sprite.x + sprite.width/2 < left} {
sprite.x = right + sprite.width/2;
} if (sprite.y - sprite.height/2 > bottom) {
sprite.y = top - sprite.height/2;
} else if (sprite.y + sprite.height/2 < top)
sprite.y = bottom + sprite.height/2;
}

correct friction(s)
speed = Math.sqrt(vx*vx + vy*vy);
angle = Math.atan2(vy,vx);
if (speed > friction) { speed -= friction; }
else { speed = 0; }

easy friction(s)
vx *= friction;
vy *= friction;

(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.