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.

26 break;<br />

27 }<br />

28 }<br />

29 name = "_root.Pitch.Red" + i;<br />

30 if (playerCollide(name)){<br />

31 clearCollision(name);<br />

32 break;<br />

33 }<br />

34<br />

35 }<br />

}<br />

Listing 18.14<br />

Chapter 18: Sports simulations<br />

Testing for collisions<br />

A collision occurs if the squared value of the vec<strong>to</strong>r between the two players is greater than<br />

the constant PLAYERSIZESQ. The ‘playerCollide’ returns true if a collision occurs and false<br />

otherwise.<br />

1 function playerCollide(name){<br />

2 x = (_x + vecx) - (eval(name)._x + eval(name).vecx);<br />

3 y = (_y + vecy) - (eval(name)._y + eval(name).vecy);<br />

4 if ((x*x + y*y)

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

Saved successfully!

Ooh no, something went wrong!