HTML and CSS Reference
In-Depth Information
Summoning the enemies
In this task, we spawn enemies on the board.
Prepare for lift off
We create one file for each type of enemy. They are enemy.js , enemy-dummy.js ,
enemy1.js , enemy2.js , enemy3.js , and boss.js . Let's create these files and put them
inside the scripts/board-objects/enemies/ folder. Then, we include them in the
game's HTML. The base enemy.js file comes first because all the other enemy types are
based on enemy.js and need its reference:
<script src="scripts/board-objects/enemies/enemy.js"></script>
<script src="scripts/board-objects/enemies/enemy-dummy.js"></script>
<script src="scripts/board-objects/enemies/enemy1.js"></script>
<script src="scripts/board-objects/enemies/enemy2.js"></script>
<script src="scripts/board-objects/enemies/enemy3.js"></script>
<script src="scripts/board-objects/enemies/boss.js"></script>
We need one more helper funcion. The removeItem funcion inds the given target
in the given array and removes it:
// remove an item from an array.
game.helper.removeItem = function(array, target) {
for(var i=0, len=array.length; i<len; i++) {
if (array[i] === target) {
array.splice(i, 1); // remove that target
return true;
return false;
If you are looking for more funcions to manipulate arrays, Lo-dash is a good
choice to check out ( ).
Search WWH ::

Custom Search