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 15: Mazes<br />

sequence <strong>to</strong> show is based on the values of the paths from that cell. For example if we have a<br />

‘T_Right’ junction when facing north, the value for this cell would be 7, made up of North (1),<br />

South (2) and East (4). If we faced south at the same cell then the image sequence should be<br />

‘T_Left’. Facing east we should show ‘Straight’ and facing west we should show ‘T_Both’. What<br />

we need is a mapping for each direction. When facing south, north maps <strong>to</strong> south and south<br />

maps <strong>to</strong> north, while west maps <strong>to</strong> east and east maps <strong>to</strong> west; so the value changes as shown in<br />

Table 15.4.<br />

Table 15.4 How mapping from a north <strong>to</strong> a south<br />

direction affects the value<br />

North South East West Total<br />

Original 1 2 4 0 7<br />

Mapped 1 2 0 8 11<br />

This maps a T_Right <strong>to</strong> a T_Left as you can see from the values displayed in Table 15.2.<br />

It is important that the program knows when an animation is playing and when <strong>to</strong> wait<br />

for user input. The movie clip ‘Tunnel’ contains a ‘mode’ variable that can take the values<br />

‘STATIONARY’, ‘EXITING’, ‘EXITED’, ‘ENTERING’ or ‘NOTLOADED’. These constants<br />

are declared on frame 1 of the Tunnel clip. It is cus<strong>to</strong>mary <strong>to</strong> define constants using upper-case<br />

letters.<br />

1 function enterCell(){<br />

2 var val, tmp, exitcell, nm, path = new Array(4);<br />

3<br />

4 nm = "lv.val" + row + "_" + col;<br />

5 val = eval(nm) & 0xF;<br />

6 exitcell = eval(nm) & 0x20;<br />

7<br />

8 cell = eval("cell" + row + "_" + col);<br />

9 Location._x = cell._x;<br />

10 Location._y = cell._y;<br />

11<br />

12 switch(dir){<br />

13 case NORTH:<br />

14 //Already correct value<br />

15 Location.go<strong>to</strong>AndS<strong>to</strong>p(1);<br />

16 break;<br />

17 case SOUTH:<br />

18 tmp = 0;<br />

19 if (val & SOUTH) tmp += NORTH;<br />

20 if (val & NORTH) tmp += SOUTH;<br />

237

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

Saved successfully!

Ooh no, something went wrong!