25.12.2012 Views

Ultimate Game Design : Building game worlds

Ultimate Game Design : Building game worlds

Ultimate Game Design : Building game worlds

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

136<br />

SCRIPTING<br />

in <strong>game</strong>s gives developers a pathway right<br />

into the control of many critical aspects of<br />

<strong>game</strong>play functionality, some of which are small and barely perceptible, while others<br />

are rather large and looming. At this point in the book, you’re becoming familiar with<br />

the process of building up a polygonal <strong>game</strong> environment (for example, by using geometric<br />

primitives like planes, spheres, cones, and cylinders, and by “adding and sub<br />

tracting” or merging these primitives together to form entirely new shapes) by introducing<br />

characters, props, and items. Now we’re going to turn our attention to learning something<br />

about how to control each of these scripts for the purposes of building up <strong>game</strong>play.<br />

Many kinds of behaviors can be controlled by a script system. Script systems in total<br />

are largely proprietary and currently vary greatly in approach among <strong>game</strong> developers.<br />

Many <strong>game</strong> engines provide scripting languages that let you program complex behaviors<br />

into your <strong>game</strong>. For instance, a monster might travel from the barn to the<br />

farmhouse to the silo and back over and over again, but walk toward the player if it<br />

sees him, run toward the player if the player is bleeding, and run away from the<br />

player and toward the silo if the player has a weapon. As today’s <strong>game</strong>s go, this is a<br />

moderately complex behavior, and it would be tedious to encode this behavior directly<br />

in C++. Scripting languages make it possible to “script” these actions so that you can<br />

focus on the behavior rather than the programming.<br />

Here’s a quick example of this behavior scenario:<br />

behavior monster;<br />

if (monster->idle) {<br />

monster->walk(barn);<br />

monster->walk(farmhouse);<br />

monster->walk(silo);<br />

}elsif (monster->sees(player)) {<br />

if (player->bleeding) {<br />

monster->run(player);<br />

} elsif (player->has_weapon) {<br />

monster->run(silo);<br />

} else { monster->walk(player) }<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!