Euclidean distante = sqrt (dx * dx + dy * dy), for your distance you need to define dx as min(abs(x2-x1),screenwidth-abs(x2-x1)) same thing for dy.
Usualy the direction vector is Pt - Pm (Position vector target - Position vector missile). In your case you can define Direction vector x component as
if (x2-x1)>=0
DirX=if min(abs(x2-x1) ,< abs((x2-x1)-width))
DirX = x2-x1;
else
DirX= max DirX = (x2-x1)-width;
else
, if (abs(x2-x1) < abs(width + (x2-x1))
DirX=x2-x1;
else
DirX= width + (x2-x1);
In the same way (using HEIGTH) you can get DirY.