02.02.2013 Views

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Chapter 8: In tip-<strong>to</strong>p condition<br />

All Movie Clips have a number of properties you can access: ‘_x’ indicates the position across the<br />

screen, ‘_y’ is the position down the screen. Notice how in this example we nest one ‘if ’ statement<br />

inside another. You can do this as many times as you choose, but if nesting more than three then<br />

you are encouraged <strong>to</strong> find another way <strong>to</strong> execute the code, since nested ‘if ’ statements are very<br />

prone <strong>to</strong> difficult-<strong>to</strong>-detect bugs, sometimes a condition is not met and the code goes screwy.<br />

Testing for a specific position is not recommended; one reason for this is because positions in<br />

<strong>Flash</strong> are not integer values (whole numbers) and so the character may be at (100.1, 199.8), which<br />

is extremely close <strong>to</strong> the target position yet the condition would still fail. One way around this<br />

problem is <strong>to</strong> reduce the exercise <strong>to</strong> a distance away from the target.<br />

Figure 8.1 That pesky Pythagoras<br />

Now, you may be thinking, how can Pythagoras help with this problem? The answer is that the<br />

relationship between the three sides of a right-angle triangle is one of the most useful devices you<br />

will find when creating graphical games. Let’s start by reviewing the concept. If we have a triangle<br />

ABC where side AC has length x and side BC has length y then the length of side AB must equal<br />

103

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

Saved successfully!

Ooh no, something went wrong!