I have 3 Classes.
One is a Global class that has my function:
public static function getDistance(ObjOne, ObjTwo)
{
var distance = Math.sqrt( ( ObjOne.x - ObjTwo.x ) * ( ObjOne.x - ObjTwo.x ) + ( ObjOne.y - ObjTwo.y ) * ( ObjOne.y - ObjTwo.y ) );
return distance;
}
Then I have a MovieClip that is the class: Minion and another called: Turret
In the Minion class I am calling: Global.getDistance
And setting the args to: Global.getDistance(this, ?????)
How can I get the Turret Object from the Turret class for the final param?
If each minion has a single turret that it is targeting, then you should hold a reference to the turret inside of your
Minionclass. There should be no need for a static function to get distance (unless it’s used for other things besides the minion/turret relation).For your turrets to be aware of ALL minions (to decide which minion to attack), a good way to do this is to store them all in a statically assessable vector (array).
Here would be a sample of your Minion class:
This passes in the appropriate turret when you create a new Minion –
new Minion(turretInstance), and has a statically accessible array that holds all the minions that are on the display list at any given time. It also adds a function to take damageFor the turrets to attack, you’d want to scan the array of all minions, and determine which are close enough to attack, either attack all (if that’s the type of turret) or pick one (the closest one usually) to attack.
Turret class: