Game Development Reference
In-Depth Information
case 'T':
return this.loadTurtleTile(x, y);
case 'A':
case 'B':
case 'C':
return this.loadFlameTile(x, y, tileType);
Loading an enemy is straightforward. You simply create an instance of the enemy you would like to
add, set its position, and add it to the _enemies list of game objects. For example, here is the method
for loading a turtle enemy:
Level.prototype.loadTurtleTile = function (x, y) {
var tiles = this.find(ID.tiles);
var enemy = new Turtle(ID.layer_objects);
enemy.position = new powerupjs.Vector2((x + 0.5) * tiles.cellWidth,
(y + 1) * tiles.cellHeight + 25);
this._enemies.add(enemy);
return new Tile();
};
You've now defined a few different kinds of enemies with varying intelligence and capabilities. It's
up to you to define enemies that are smarter, more devious, or even more stupid, depending on the
needs of your game. You didn't apply any physics to the enemies; however, once you start building
smarter enemies that, for example, can jump or fall, you'll need to implement physics just as you did
for the player. As an exercise, try to think how you can make these enemies more capable without
having to rely on physics. Can you let them move faster when the player is nearby? Can you create
an enemy that launches particles toward the player? The possibilities are endless, so try these things
for yourself!
What You Have Learned
In this chapter, you have learned:
How to define different kinds of enemies
How to use inheritance to create variety in enemy behavior
 
Search WWH ::




Custom Search