Game Development Reference
In-Depth Information
photons[i] = new PolygonSprite();
photons[i].shape.addPoint(1, 1);
photons[i].shape.addPoint(1, -1);
photons[i].shape.addPoint(-1, 1);
photons[i].shape.addPoint(-1, -1);
}
// Create shape for the flying saucer.
ufo = new PolygonSprite();
ufo.shape.addPoint(-15, 0);
ufo.shape.addPoint(-10, -5);
ufo.shape.addPoint(-5, -5);
ufo.shape.addPoint(-5, -8);
ufo.shape.addPoint(5, -8);
ufo.shape.addPoint(5, -5);
ufo.shape.addPoint(10, -5);
ufo.shape.addPoint(15, 0);
ufo.shape.addPoint(10, 5);
ufo.shape.addPoint(-10, 5);
// Create shape for the guided missile.
missile = new PolygonSprite();
missile.shape.addPoint(0, -4);
missile.shape.addPoint(1, -3);
missile.shape.addPoint(1, 3);
missile.shape.addPoint(2, 4);
missile.shape.addPoint(-2, 4);
missile.shape.addPoint(-1, 3);
missile.shape.addPoint(-1, -3);
// Create asteroid sprites.
for (i = 0; i < Constants.MAX_ROCKS; i++)
asteroids[i] = new PolygonSprite();
// Create explosion sprites.
for (i = 0; i < Constants.MAX_SCRAP; i++)
explosions[i] = new PolygonSprite();
// Initialize game data and put it in 'game over' mode.
highScore = 0;
sound = true;
detail = true;
initGame();
endGame();
}
Drawing Sprites
Drawing 23.70the sprites is the next step in the game life cycle and the most important too. Here is
where all polygon sprites are drawn (see Listing 4-7). The most important steps are as follows:
Search WWH ::




Custom Search