Game Development Reference
In-Depth Information
Chapter 27
Intelligent Enemies
As the next step in developing the Tick Tick game, let's introduce some peril to the player by adding
dangerous enemies. If the player touches an enemy, the player dies. The enemies generally aren't
controlled by the player (that would make it too easy). Therefore, you need to define some kind of
smart (or stupid) behavior. You don't want these enemies to be too smart: the player should be able
to complete the level. After all, that is the goal of playing a game: winning it. What is nice is that you
can build different types of enemies that exhibit different types of behavior. As a result, the player
has different gameplay options and must develop different strategies to complete the level.
Defining the behavior of an enemy can lead to some very complex code, with many different states,
reasoning, path planning, and much more. You see a few different types of enemies in this chapter: a
rocket, a sneezing turtle (seriously), Sparky, and a couple of different patrolling enemies. This chapter
doesn't deal with how the player should interact with enemies—you only define their basic behavior.
The Rocket
One of the most basic enemies is a rocket. A rocket flies from one side of the screen to the other and
then reappears after some time has passed. If the player comes in contact with the rocket, the player
dies. In the level description, you indicate with the r and R characters that a rocket enemy should be
placed in a level. For example, consider this level description:
window.LEVELS.push({
hint : "Many, many, many, many, many rockets...",
locked : true,
solved : false,
tiles : ["....................",
"r..W...........X....",
"...--..W.......--...",
"....W.--........W..R",
"...--..........--...",
"r..W......W....W....",
"...--....--....--...",
"....W...........W...",
355
 
Search WWH ::




Custom Search