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.

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

142<br />

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

FIGURE 6-2<br />

Simple sine wave attack<br />

Figure 6-2 shows the shape of the resulting attack pattern for enemyactor as a<br />

standard sine wave.<br />

All right, so enemyactor follows the sine wave path. Well that’s okay for one attack<br />

pattern (I think we’ve seen it before), but we want to build many others. In a very simple<br />

shooter, we would probably want at least one unique attack pattern for each <strong>game</strong><br />

level. Maybe we want a big lazy sloping attack pattern. We can start to build one by<br />

tweaking the sine wave values.<br />

Here’s a practical point: Plenty of scripting work involves just tweaking or editing<br />

variables, saving, and rebuilding. Sometimes you will spend days just working on<br />

many tweaked script versions for a range of behaviors. In some cases, you won’t even<br />

be writing the scripts or “line commands” as we’re looking at them here; you may<br />

just tweak values to get an intended effect.<br />

Now, let’s change the amplitude of the sine wave to create a different attack pattern.<br />

This example should help demonstrate the idea that shaping many behaviors, like<br />

this simple attack behavior, is often a matter of starting to tweak values:<br />

// Alter sine wave attack for enemyactor by modulating amplitude<br />

function moveEnemy() {<br />

enemyactor.moveLeft();<br />

// Modulate sine wave amplitude by another sine wave<br />

var x = enemyactor.getX()%360;<br />

enemyactor.setY((50*sin(x)+50) * sin(x*4) + 240);<br />

}<br />

Figure 6-3 shows the result of adjusting the attack pattern by modulating amplitude.<br />

Now our enemyactor has a tweaked attack pattern. As you can see, we could make<br />

many other attack patterns by simply changing values and playing around with<br />

numbers. We might create even more types of attack patterns by altering the frequency<br />

of the sine wave.

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

Saved successfully!

Ooh no, something went wrong!