Game Development Reference
In-Depth Information
Figure 4-3. The walls, puck, paddle, and message board drawn to the stage
Creating Levels
A level in this game consists of adding a new set of bricks to the game after a predetermined amount of paddle hits.
The game continues in play, and all subsequent rows of bricks move down on the screen, making it increasingly
difficult to hit the puck.
Adding Levels
One more function remains in the initialization process. The newLevel function (see Listing 4-10) creates two new
rows of bricks, which make up a level. The game begins with two sets of bricks, so this function is initially called twice
and essentially starts the player on level 2.
Listing 4-10. Adding a New Level of Bricks to the Game
function newLevel() {
var i, brick, freeLifeTxt;
var data = levels[level];
var xPos = WALL_THICKNESS;
var yPos = WALL_THICKNESS;
var freeLife = Math.round(Math.random() * 20);
paddleHits = 0;
shiftBricksDown();
 
Search WWH ::




Custom Search