My brain has failed me…
I wish to have some sprites which move along the boundary of the player’s view screen what indicate the direction the play needs to travel to locate other players.
I currently have the following logic:
double screenX=background[zoom].getX()+background[zoom].getWidth()/2;
double screenY=background[zoom].getY()+background[zoom].getHeight()/2;
double screenHalfX=background[zoom].getWidth()/2;
double screenHalfY=background[zoom].getHeight()/2;
xdiff=currentPlayer.label.getX()-screenX;
ydiff=currentPlayer.label.getY()-screenY;
angle = Math.atan2(ydiff,xdiff)*180/PI;
if (angle>315 || angle<45)
{
newX=background[zoom].getX()+background[zoom].getWidth();
newY=screenY+ydiff*(Math.abs(screenHalfX/xdiff));
}
else if (angle>=45 && angle<135)
{
newX=screenX+xdiff*(Math.abs(screenHalfY/ydiff));
newY=background[zoom].getY()+background[zoom].getHeight();
}
else if (angle>=135 && angle<225)
{
newX=background[zoom].getX();
newY=screenY+ydiff*(Math.abs(screenHalfX/xdiff));
}
else
{
newX=screenX+xdiff*(Math.abs(screenHalfY/ydiff));
newY=background[zoom].getY();
}
where background is the a class representing the player’s current view.
so when the angle is greater than 315 or less than 45 then the x position of the sprite will be on the far right edge of the screen. The y position of the sprite is calculated using the ratio of half the screen width and the calculated difference.
Similar calculations are performed for the other quadrents.
This is not working… can anyone find a flaw in my logic?