Game Development Reference
In-Depth Information
case 'T':
return LoadTurtleTile(x, y);
case 'R':
return LoadRocketTile(x, y, true );
case 'r':
return LoadRocketTile(x, y, false );
case 'S':
return LoadSparkyTile(x, y);
case 'A':
case 'B':
case 'C':
return LoadFlameTile(x, y, tileType);}
Loading an enemy is rather straightforward. We simply create an instance of the
enemy we 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:
private Tile LoadTurtleTile( int x, int y)
{
GameObjectList enemies = this .Find("enemies") as GameObjectList;
TileField tiles = this .Find("tiles") as TileField;
Turtle enemy = new Turtle();
enemy.Position = new Vector2((( float )x + 0.5f)
tiles.CellWidth,
(y + 1)
tiles.CellHeight + 25.0f);
enemies.Add(enemy);
return new Tile();
}
We now have defined a few different kinds of enemies, with varying intelligence
and capabilities. It is up to you to define enemies that are smarter, more deviant,
or even more stupid, depending on the needs of your game. We did not apply any
physics to the enemies. However, once you start building smarter enemies that for
example can also jump or fall, you are going to need physics just like we imple-
mented for the player. As an exercise, try to think how you can make these enemies
smarter, without having to rely on physics. Can you let them move faster when the
player is nearby? Or perhaps you can create an enemy that launches particles toward
the player? The possibilities are endless, so try these things out for yourself!
28.6 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 behavior of enemies.
Search WWH ::




Custom Search