mercredi 4 février 2015

actionscript 3 - x/y coordinates of a random array element

I basically have a bunch of enemies in my game stored in an array while they are alive. I want a friendly ship to pick a random target from the array of enemies and shoot it. For this I need the x and y coordinates of that randomly selceted enemy from the array as it is used in the following calculation for the bullets:



_endX = randomenemyship.x - 50 * _pcos + Math.random() * _bulletSpread - _bulletSpread * .5;
_endY = randomenemyship.y - 50 * _psin + Math.random() * _bulletSpread - _bulletSpread * .5;


Would anyone be able to help, Ive been looking at how to select a random array element but Im not sure how to get coordinates and use it in a calculation like above. Thanks.





Aucun commentaire:

Enregistrer un commentaire