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 />

If the cat calls ‘userRight’ then we need <strong>to</strong> decide what <strong>to</strong> do based on the current action. The<br />

cat action could be ‘STOPRIGHT’, ’STOPLEFT’ or ‘WALKLEFT’. The current action dictates<br />

what the cat action should be set <strong>to</strong>.<br />

1 //===============userRight=====================================<br />

2 //This is called by the userAction function<br />

3 //parameters=======================================================<br />

4 //none<br />

5 //=================================================================<br />

6 function userRight() {<br />

7 switch (action) {<br />

8 case STOPRIGHT :<br />

9 initAction(STARTRIGHT);<br />

10 break;<br />

11 case STOPLEFT :<br />

12 initAction(STARTLEFT);<br />

13 break;<br />

14 case WALKLEFT :<br />

15 initAction(TURNRIGHT);<br />

16 break;<br />

17 }<br />

18 }<br />

Listing 17.5<br />

‘userLeft’ works in a similar way with the directions reversed.<br />

1 //===============userLeft=====================================<br />

2 //This is called by the userAction function<br />

3 //parameters=======================================================<br />

4 //none<br />

5 //=================================================================<br />

6 function userLeft() {<br />

7 switch (action) {<br />

8 case STOPLEFT :<br />

9 initAction(STARTLEFT);<br />

10 break;<br />

11 case STOPRIGHT :<br />

12 initAction(STARTRIGHT);<br />

13 break;<br />

14 case WALKRIGHT :<br />

15 initAction(TURNLEFT);<br />

16 break;<br />

17 }<br />

18 }<br />

Listing 17.6<br />

265

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

Saved successfully!

Ooh no, something went wrong!