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 17: Platformers<br />

game much easier. When in debug mode several extra keys are used. The shift key causes the<br />

sprite <strong>to</strong> move up the screen by one pixel for each screen redraw. The control key works in<br />

the opposite direction. The space bar fixes the up and down movement set by the shift and control<br />

keys. The tab key forces the character in<strong>to</strong> a distinct mode and reactivates ‘usercontrol’, a variable<br />

that is used <strong>to</strong> activate and deactivate keyboard input. If the caps lock key is down then the variable<br />

‘tracemotion’ is set <strong>to</strong> true. This causes dump of the location of the sprite <strong>to</strong> be sent <strong>to</strong> the output<br />

window. The value of the variable is used within another function that actually does this work,<br />

which we will examine later.<br />

The bulk of the code is inside the ‘Cat’ clip on frame 1. Before we examine that, take a look at<br />

the timeline for the ‘Cat’ movie clip. There are 14 labels, each one indicating the first frame of an<br />

animation. Within the Control layer there are a few small <strong>ActionScript</strong>s that set variables specific<br />

<strong>to</strong> certain actions or reset the action; we will examine these later. The labels used are:<br />

WalkRight, FallRight, JumpRight, LandRight, S<strong>to</strong>pRight, StartRight, TurnRight<br />

WalkLeft, FallLeft, JumpLeft, LandLeft, S<strong>to</strong>pLeft, StartLeft, TurnLeft<br />

The code on frame 1 starts with some simple initialization, but most of the code defines functions<br />

that are used <strong>to</strong> control the character. Both ‘userAction’ and ‘move’ are called by the ‘onClipEvent’<br />

<strong>ActionScript</strong>.<br />

1 //Init variables<br />

2 JUMP = 1;<br />

3 TURNLEFT = 2;<br />

4 STARTRIGHT = 3;<br />

5 WALKRIGHT = 4;<br />

6 FALLRIGHT = 5;<br />

7 JUMPRIGHT = 6;<br />

8 LANDRIGHT = 7;<br />

9 STOPRIGHT = 8;<br />

10 TURNRIGHT = 9;<br />

11 STARTLEFT = 10;<br />

12 WALKLEFT = 11;<br />

13 FALLLEFT = 12;<br />

14 JUMPLEFT = 13;<br />

15 LANDLEFT = 14;<br />

16 STOPLEFT = 15;<br />

17 HALT = 16;<br />

18 actionNames = new Array(<br />

19 "No action", "Jump", "TurnLeft", "StartRight",<br />

20 "WalkRight", "FallRight", "JumpRight", "LandRight",<br />

21 "S<strong>to</strong>pRight", "TurnRight", "StartLeft", "WalkLeft",<br />

22 "FallLeft", "JumpLeft", "LandLeft", "S<strong>to</strong>pLeft",<br />

23 "Halt");<br />

24 x = 0;<br />

25 y = 0;<br />

26 jumping = false;<br />

263

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

Saved successfully!

Ooh no, something went wrong!