HTML and CSS Reference
In-Depth Information
board.add(new PlayerShip());
board.add(new Level(level1,winGame));
Game.setBoard(5,new GamePoints(0));
Board 5 was chosen because Board 4 was just used by the TouchControls in the last section.
If you were to reload the game, you'd now see the points in the top left of the page, but they are sadly stuck
at zero. Because the player should get points every time an enemy is killed, the easiest thing to do is add some
logic to the Enemy.hit method.
Modify that method in game.js to read:
Enemy.prototype.hit = function(damage) { -= damage;
if( <=0) {
if(this.board.remove(this)) {
Game.points += this.points || 100;
this.board.add(new Explosion(this.x + this.w/2,
this.y + this.h/2));
The points are increased on a per-enemy basis, but if the enemy doesn't have a point property set, it defaults
to 100 . You can modify the enemies blueprint to make the point amounts vary by enemy type.
Reload the game, and you should be able rack up a score. You can also run the version of the game to this
point at .
Making It a Fair Fight
Alien Invasion is now down to its last enhancement, giving the enemies a little bit of fire power to fight back.
Cribbing from PlayerMissile , the game needs an object, EnemyMissile , to represent the enemy pro-
jectiles being fired. Add the code in Listing 3-5 to the bottom of game.js to create EnemyMissile .
Listing 3-5: The EnemyMissile object
var EnemyMissile = function(x,y) {
this.setup('enemy_missile',{ vy: 200, damage: 10 });
this.x = x - this.w/2;
this.y = y;
EnemyMissile.prototype = new Sprite();
EnemyMissile.prototype.type = OBJECT_ENEMY_PROJECTILE;
Search WWH ::

Custom Search