import objectdraw.*;

/**
 * A Version of the Cow mover that
 * does use smooth scrolling.
 */
public class SmoothCow extends ActiveObject {

    private static final int PAUSE_TIME = 30;
    private static final double VELOCITY = -0.2;  // amount to move in pixels / ms
    
    private VisibleImage cowImage;
    private int finishX;
    private double startX;

    public SmoothCow(VisibleImage cowImg, int finish_x) {
        startX = cowImg.getX();
        cowImage = cowImg;
        finishX = finish_x;
        start();
    }

    public void run () {
        while (cowImage.getX() + cowImage.getWidth() > finishX) {
            
            // pause, and compute the amount of time we actually paused.
            double currentTime = System.currentTimeMillis();            
            pause (PAUSE_TIME);
            double delay = System.currentTimeMillis() - currentTime;
            
            // move the cow according to its velocity and the delay.
            cowImage.move (VELOCITY * delay, 0);
        }
        
        cowImage.moveTo(startX, cowImage.getY());
    }
}
