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:
- We add the following damage logic to the building's base file:
// The base of Building definition. ;(function(game, cjs, lib){ function Building(){ cjs.Container.call(this); // 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...