33
The rock scale will be set to one of the three rock-scale constants discussed earlier.
halfWidth and halfHeight will be set based on the scale, and they will be used in
calculations in the same manner as the player object versions. The dx and dy values
represent the values to apply to the x and y axes when updating the rock on each frame
tick.
Saucers
Unlike Atari’s Asteroids game, which has both small and large saucers, we are going to
have only one size in Geo Blaster Basic. It will be stored in the saucers array. On a 28×13
grid (using paths), it looks like Figure 8-6.
Figure 8-6. The saucer design
The variable attributes of the saucer object are very similar to the attributes of a rock
object, although without the rock scale attribute. Also, saucers don’t have a rotation; it
is always set at 0. The saucer also contains variables that are updated on each new level
to make the game more challenging for the player. Here are those variables, which will
be discussed in more detail in the upcoming section “Level Knobs” on page 479:
newSaucer.fireRate = levelSaucerFireRate;
newSaucer.fireDelay = levelSaucerFireDelay;
newSaucer.fireDelayCount = 0;
newSaucer.missileSpeed = levelSaucerMissileSpeed;
Missiles
Both the player missiles and saucer missiles will be 2×2-pixel blocks. They will be stored
in the playerMissiles and saucerMissiles arrays, respectively.
The objects are very simple. They contain enough attributes to move them across the
game screen and to calculate life values:
newPlayerMissile.dx = 5*Math.cos(Math.PI*(player.rotation)/180);
newPlayerMissile.dy = 5*Math.sin(Math.PI*(player.rotation)/180);
newPlayerMissile.x = player.x+player.halfWidth;
newPlayerMissile.y = player.y+player.halfHeight;
newPlayerMissile.life = 60;
newPlayerMissile.lifeCtr = 0;
newPlayerMissile.width = 2;
newPlayerMissile.height = 2;
478 | Chapter 8: Canvas Games: Part I