import java.awt.*;
import java.util.Random;

public class Alien extends Sprite {
    private final Random random;
    private long lastShot;
    private static final long timeBetweenShots = 5000;    // milliseconds

    public Alien(Image image, int x, int y, int w, int h, int dx, int dy)
    {
        super(x, y, w, h, dx, dy, image);
        random = new Random();
        lastShot = System.currentTimeMillis();
    }

    public boolean intersect(Missile m)
    {
        Rectangle r1 = new Rectangle(getX(), getY(), getWidth(), getHeight());
        Rectangle r2 = new Rectangle(m.getX(), m.getY(), m.getWidth(), m.getHeight());

        return r1.intersects(r2);
    }

    public boolean throwBomb()
    {
        if (System.currentTimeMillis() - lastShot > timeBetweenShots) {
            lastShot = System.currentTimeMillis();
            return random.nextFloat() < 0.1;
        }
        else {
            return false;
        }
    }
}
