The following examples show that collisions work in two dimensional play as well. They also demonstrate some additional concepts like bouncing, wrapping, and random direction at constant speed.
Bouncing smiles
Getting a smiley face on the canvas and making it bounce around.
Note the game’s helper function definitions are now outside the game.onload function but still indide the myGame function.
The randomInt function definition has been lumped together with the game’s helper functions because nothing outside the game will need it.
Additional properties to store speed and direction of smiley sprite instance are added to the sprite instance itself.