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

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

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

56 }else if (moveY-4){<br />

57 moveY -= 2;<br />

58 }else if (moveY < 0){<br />

59 moveY *= 1.3;<br />

60 }<br />

61 }<br />

62 }<br />

63 break;<br />

64 }<br />

65 _x = x + orgX;<br />

66<br />

67 }<br />

_y = y + orgY;<br />

Listing 17.9<br />

Chapter 17: Platformers<br />

One of the most important parts of the code in this example is the collision detection involved<br />

in the ‘land’ function. There are two possible landings: either on the floor at y > 0, or on a<br />

platform. To decide if the cat has landed on a platform we must go through each platform in turn.<br />

There are 11 boxes and 3 bins, and each of these must be tested. To achieve a landing the cat must<br />

be in a legal position both horizontally and vertically. We determine this position using the debug<br />

box. On screen for debugging purposes you can see a multi-line dynamic text box which tracks<br />

the value of the variable ‘_root.debug’. A considerable quantity of debugging values is displayed<br />

using string functions. To work out the values needed <strong>to</strong> land on a platform, simply move the cat<br />

using the control keys and the debug keys and work out the values for the upper left and lower<br />

right of the rectangle that defines a legal landing area.<br />

Figure 17.2 Legal area for a landing<br />

The vertical range must use the current value for moveY <strong>to</strong> ensure that the platform is not<br />

missed. It is remarkably easy when checking for a collision with a platform <strong>to</strong> check on one frame<br />

273

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

Saved successfully!

Ooh no, something went wrong!