import java.awt.Graphics;
import java.awt.Color;

public class LaserShot
{
 Color  color;
 double posX;
 double posY;
 double speedX;
 double speedY;
 int    reached;
 int    maxReach;
 public int    targetX;
 public int    targetY;
 public boolean hitting;
 public boolean shooting;
 public boolean showTarget;

 public LaserShot(Color color, boolean showTargetCross)
 {
  this.color      = color;
  this.hitting    = false;
  this.shooting   = false;
  this.showTarget = showTargetCross;
  this.targetX    = -500;
  this.targetY    = -500;
 }

 public void shoot(int origX, int origY, int targetX, int targetY)
 {
  if(!shooting)
  {
   this.posX     = (double)origX;
   this.posY     = (double)origY;
   this.targetX  = targetX;
   this.targetY  = targetY;
   this.speedX   = 0;
   this.speedY   = 0;
   this.reached  = 0;
   this.maxReach = 10;
   this.shooting = true;
   this.hitting  = false;
  }
 }

 public void move()
 {
  if(shooting)
  {
   speedX = (targetX - posX) / (maxReach-reached+1);
   speedY = (targetY - posY) / (maxReach-reached+1);
   posX    += speedX;
   posY    += speedY;
   reached += 1;
   if(reached == maxReach)
   {
    hitting = true;
   }
   else if(reached > maxReach)
   {
    shooting = false;
    hitting  = false;
   }
  }
 }

 public void paint(Graphics g)
 {
  if(shooting && reached > 1)
  {
   g.setColor(color);
   if(showTarget)
   {
    g.drawLine(targetX-1, targetY-1, targetX+1, targetY+1);
    g.drawLine(targetX+1, targetY-1, targetX-1, targetY+1);
   }
   g.drawLine((int)(posX-speedX*2), (int)(posY-speedY*2), 
    (int)(posX), (int)(posY));
  }
 }
}