Game Development Reference
In-Depth Information
Figure 27-1. A level with many rockets flying around
A Patrolling Enemy
The rocket is a type of enemy that basically has no intelligent behavior. It flies from left to right or
vice versa until it flies out of the screen, and then it resets itself. You can also add enemies that are
slightly smarter, such as a patrolling enemy. Let's set up a few different types of patrolling enemies
that you can add to the game.
The Basic PatrollingEnemy Class
The PatrollingEnemy class is similar to the Rocket class. You want the patrolling enemy to be
animated, so it inherits from the AnimatedGameObject class. You also need to define the behavior
of the enemy in the overridden update method. The basic behavior of the patrolling enemy is that
it walks from left to right and back again. If the enemy character reaches a gap or a wall tile, the
enemy stops walking, waits for some time, and turns around. You can place enemies at arbitrary
positions in the level. For the player, you define some rudimentary physics like falling and jumping.
You don't do that for the PatrollingEnemy class, because the enemies you define for this game only
walk from left to right and back.
 
Search WWH ::




Custom Search