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.

<strong>Flash</strong> <strong>MX</strong> <strong>2004</strong> <strong>Games</strong><br />

17 }<br />

18 }<br />

Listing 15.8<br />

Each of the functions called from a keyboard press tests for a suitable exit in the required<br />

direction. The variable ‘paths’ is the user-rotated view of the maze. If you are pointing east and<br />

there is a path <strong>to</strong> the east then this will have been mapped <strong>to</strong> a north direction using the enterCell<br />

function. The purpose of each of these functions is <strong>to</strong> move the player around the maze legally.<br />

Each function updates the ‘row’ and ‘col’ variables and adjusts the direction variable ‘dir’ if a turn<br />

is involved. Each function completes by setting the ‘mode’ variable and playing the appropriate<br />

animation <strong>to</strong> exit a cell.<br />

1 function moveForward(){<br />

2 if (paths & NORTH){<br />

3 //Only allowed if a NORTH movement is available<br />

4 switch (dir){<br />

5 case NORTH:<br />

6 row--;<br />

7 break;<br />

8 case SOUTH:<br />

9 row++;<br />

10 break;<br />

11 case EAST:<br />

12 col++;<br />

13 break;<br />

14 case WEST:<br />

15 col--;<br />

16 break;<br />

17 }<br />

18 Tunnel.mode = Tunnel.EXITING;<br />

19 Tunnel.anim.go<strong>to</strong>AndPlay("Forward");<br />

20 }<br />

21 }<br />

22<br />

23 function turnLeft(){<br />

24 if (paths & WEST){<br />

25 //Only allowed if a WEST movement is available<br />

26 switch (dir){<br />

27 case NORTH:<br />

28 dir = WEST;<br />

29 col--;<br />

30 break;<br />

31 case SOUTH:<br />

240

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

Saved successfully!

Ooh no, something went wrong!