I have followed the Jim Stewart video on forming a lineof sight between object however the line that i have drawn is not in the world.
i have added the LineOfSight object into the world aswell
Actor Army1;
Actor Army2;
int army1X;
int army1Y;
int army2X;
int army2Y;
GreenfootImage myImage;
public LineOfSight (Actor a1, Actor a2)
{
Army1 = a1;
Army2 = a2;
setImage(new GreenfootImage(1,1));
}
/**
* Act - do whatever the LineOfSight wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if(Army1.getWorld()!=null && Army2.getWorld()!=null)
{
army1X = Army1.getX();
army1Y = Army1.getY();
army2X = Army2.getX();
army2Y = Army2.getY();
int myX = (army2X + army1X)/2;
int myY = (army2Y + army1Y)/2;
setLocation(myX, myY);
turnTowards(army1X, army1Y);
int d =(int)Math.sqrt(Math.pow((army2X-army1X),2)+Math.pow((army2Y-army1Y),2));
setImage(new GreenfootImage(d,1));
myImage = getImage();
//getWorld().getBackground().fillRect(army1X, army1Y, army2X, army2Y);
//getWorld().getBackground().drawRect(army1X,army1Y,army2X,army2Y);
myImage.setColor(Color.RED);
myImage.drawLine(1,1,d,1);
//getWorld().getBackground().setColor(Color.BLUE);
//getWorld().getBackground().drawLine(0,0,d,0);
}
}
}


