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

Figure 18.3 The effect of ramping between moving the player <strong>to</strong> the ball and <strong>to</strong> three times the ball’s diameter<br />

10 //Move out by 3 times ball diameter<br />

11 x *= _root.BALLDIAMETER3;<br />

12 y *= _root.BALLDIAMETER3;<br />

13 gx = x + _root.Pitch.Ball._x;<br />

14 gy = y + _root.Pitch.Ball._y;<br />

15 //Create a ramp between the outer target and the ball<br />

16 //a is target proportion<br />

17 //b is ball proportion<br />

18 if (balldist>_root.BALLDIAMETER3){<br />

19 a = 1;<br />

20 b = 0;<br />

21 }else{<br />

22 a = (balldist - _root.BALLDIAMETER)/_root.BALLDIAMETER3;<br />

23 b = 1 - a;<br />

24 }<br />

25<br />

26 c = _root.ROTATIONFRAMES/3;<br />

27 x = a * (_x - gx) + b * (_x - _root.Pitch.Ball._x);<br />

28 y = a * (_y - gy) + b * (_y - _root.Pitch.Ball._y);<br />

29 angle = Math.atan2(y, x) + _root.PI;<br />

30 frame = int(angle/_root.FRAMETORADIANS) + 1;<br />

31<br />

32 if ( balldist c && frame < (_root.ROTATIONFRAMES - c)){<br />

34 //Test whether the player is running back<br />

35 //If so and the balldist less than the ball<br />

36 //diameter then kick ball<br />

290

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

Saved successfully!

Ooh no, something went wrong!