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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Building</strong> <strong>Game</strong> Worlds<br />

140<br />

U L T I M A T E G A M E D E S I G N<br />

Python Sample<br />

Perl Sample<br />

def moveMonster():<br />

if monster.canSeePlayer():<br />

monster.attack()<br />

elif monster.canSeeWeapon():<br />

monster.pickupWeapon()<br />

else:<br />

monster.patrol()<br />

sub moveMonster {<br />

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

monster->attack();<br />

} elsif ( monster->canSeeWeapon() ) {<br />

monster->pickupWeapon();<br />

} else {<br />

monster->patrol();<br />

}<br />

}<br />

APPLIED SCRIPTING EXAMPLES<br />

One of the best ways to demonstrate the power of scripting is to cover several common<br />

cases in which scripts are used in <strong>game</strong>s to control behavior. Scripts can be used to<br />

control many kinds of custom events, so this is not by any means an exhaustive<br />

sampling of every possible script-based control. Script-based controls are customand<br />

user-defined. This is where collaboration with a tools or engine technology<br />

programmer or team is so very important. Both sides (programmer and scripter) need<br />

to agree on which behavior aspects make for the most powerful kinds of <strong>game</strong>play<br />

edits. The samples that follow should give you a solid idea of how you might use<br />

scripts to control different types of <strong>game</strong> behaviors.<br />

NPC Conversation Templates<br />

NPCs populate many <strong>game</strong> <strong>worlds</strong> and are used in a variety of ways. You might want<br />

to control how an NPC handles conversation with a player’s character. Let’s assume<br />

that actor_21 is a cave guard (a beast protecting the entrance to a cave). We want this<br />

cave guard actor to simply pass along three clues or pieces of information to the<br />

player about what’s inside the cave. A script might look like this:

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

Saved successfully!

Ooh no, something went wrong!