Book Image

HTML5 Game Development Hotshot

By : Seng Hin Mak, Makzan Makzan (Mak Seng Hin)
Book Image

HTML5 Game Development Hotshot

By: Seng Hin Mak, Makzan Makzan (Mak Seng Hin)

Overview of this book

Table of Contents (15 chapters)
HTML5 Game Development HOTSHOT
About the Author
About the Reviewers

Enemies attacking the buildings

In this task, we allow the enemy to stop and attack the buildings that block their way.

Prepare for lift off

The explode animation is made up of three graphics. We may use the bundled assets.js file for this, or we may use the following spritesheet image if we do not have access to Adobe Flash's assets features:

Engage thrusters

Let's code the interactions between the enemies and buildings:

  1. We add the following damage logic to the building's base file:

    // The base of Building definition.
    ;(function(game, cjs, lib){
      function Building(){;
        // properties that need to be overridden
        this.hp = 100;
        this.shield = 0;
        this.damageDeal = 0;
        this.attackSpeed = 9999; // smaller means faster
      Building.prototype = Object.create(cjs.Container.prototype);
      Building.prototype.damage = function(damage) {
        var realDamage = Math.max(damage - this.shield, 0); // min 0.
        this.hp -= realDamage;
        if (this.hp <= 0 &amp...