AI

BlitzMax Forums/BlitzMax Programming/AI

Make FireMissile() a method of TEnemyShip. Call it with the parameters of the target locations X,Y. Then, inside of the FireMissile function, you can instantiate a TMissile with the target X,Y and the X,Y fields of the EnemyShip that is creating it.

i.e.
Type TEnemyShip
field x:int
field y:int
field lastfired:int

method FireMissile( targetx:int, targety:int )
if( millisecs() < lastfired + fireinterval)
 return 'enough time hasn't elapsed yet
else
 local newMissile:TMissile = new TMissile
 newMissile.TargetX = targetx
 newMissile.TargetY = targety
 newMissile.x = x 'this assigns the missile the x position of the parent ship
 newMissile.y = y 'this assigns the missile the y position of the parent ship
 GlobalMissileList.Addlast(newMissile) 
 lastfired = millisecs()
endif
EndMethod
EndType