import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class LineOfSight here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class LineOfSight extends Actor
{
Actor Warrior1;
Actor Soceror;
int Warrior1X;
int Warrior1Y;
int SocerorX;
int SocerorY;
GreenfootImage myImage;
/**
* Act - do whatever the LineOfSight wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public LineOfSignt (Actor W, Actor S)
{
Warrior1 = W;
Soceror = S;
setImage(new GreenfootImage(1,1));
}
public void act()
{
if(Warrior1.getWorld()!=null && Soceror.getWorld()!=null)
{
Warrior1X = Warrior1.getX();
Warrior1Y = Warrior1.getY();
SocerorX = Soceror.getX();
SocerorY = Soceror.getY();
int myX = (SocerorX + Warrior1X)/2;
int myY = (SocerorY + Warrior1Y)/2;
setLocation(myX, myY);
turnTowards(Warrior1X, Warrior1Y);
int d = (int)Math.sqrt(Math.pow((SocerorX-Warrior1X),2)+Math.pow((SocerorY-Warrior1Y),2));
setImage(new GreenfootImage(d,1));
myImage = getImage();
myImage.setColor(Color.BLACK);
myImage.drawLine(0,0,d,0);
}
}
public boolean clearLineOfSight()
{
return(getOneIntersectingObject(Fence.class)==null);
}
}

