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.

Chapter 18: Sports simulations<br />

For much of the time the camera is scaled as in Figure 18.4 with the centre located in the middle<br />

of a triangle that includes the two players with focus and the ball. This movement is achieved using<br />

the ‘move’ function for the ‘Pitch’ clip. All the players and the ball are children of the ‘Pitch’ clip.<br />

Because the players with focus change regularly and yet we do not want the camera view <strong>to</strong> jump,<br />

we calculate a ramp between the positions using the ‘movecount’ variable. Whenever the player<br />

with focus changes the ‘movecount’ variable is set <strong>to</strong> the value of the constant PANFRAMES.<br />

A first call <strong>to</strong> the ‘move’ function with ‘movecount’ equal <strong>to</strong> PANFRAMES gives a value for a<br />

of 1 and a value for b of 0. The x and y values are calculated using the ramp value.<br />

1 function move(){<br />

2 //Position the pitch so that it is centred around<br />

3 //the ball and the nearest player and opponent<br />

4 if (_root.playerTeam==_root.RED){<br />

5 x = eval("Red" + _root.playerNo)._x;<br />

6 x += eval("Blue" + _root.opponentNo)._x;<br />

7 y = eval("Red" + _root.playerNo)._y;<br />

8 y += eval("Blue" + _root.opponentNo)._y;<br />

9 }else{<br />

10 x = eval("Red" + _root.playerNo)._x;<br />

11 x += eval("Blue" + _root.opponentNo)._x;<br />

12 y = eval("Red" + _root.playerNo)._y;<br />

13 y += eval("Blue" + _root.opponentNo)._y;<br />

14 }<br />

15<br />

16 scale = _xscale/100;<br />

17<br />

18 x = (x + Ball._x)/3;<br />

19 x = 270 - x *scale;<br />

20<br />

21 if (movecount>0){<br />

22 a = movecount/_root.PANFRAMES;<br />

23 b = 1 - a;<br />

24 x = b * x + a * _x;<br />

25 }<br />

26<br />

27 if (x>-247 && x0){<br />

303

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

Saved successfully!

Ooh no, something went wrong!