import java.awt.Point;
import java.awt.Rectangle;
import java.util.Random;

/**
 *
 @author Justin Mobijohn and Zander
 */
public class Enemy extends GameObject {
    private static Random RANDOM_GENERATOR = new Random();
    private float m_NextTimeToFire;
    private float m_ElapsedTimeSinceLastFire;
    private boolean m_HasReachedBottom;

    /**
     * Default constructor for an Enemy
     */
    public Enemy() {
        this.m_Image = GameObject.m_ImageManager.LoadImageFromDisk("GameImages/Enemy.jpg");
        this.m_Currentposition = new Rectangle(Enemy.RANDOM_GENERATOR.nextInt(80064, Enemy.RANDOM_GENERATOR.nextInt(300)6464);
        this.m_MovementVector = new Point(Enemy.RANDOM_GENERATOR.nextInt(410);
        this.SetGameObjectType(GameObject.GameObjectType.ENEMY);
        this.m_Life = 10;
        // Every time an enemy fires, it randomly chooses when to fire next:
        this.m_NextTimeToFire = Enemy.RANDOM_GENERATOR.nextFloat() 2;
        this.m_ElapsedTimeSinceLastFire = 0;
        this.m_HasReachedBottom = false;
    }

    /**
     * Returns whether or not it has hit the bottom.
     @return true If the monster has reached the bottom.
     */
    public boolean GetHasReachedBottom() {
        return this.m_HasReachedBottom;
    }

    /**
     * Updates its position and if a certain amount of time has gone by,
     * fire a missile.
     *
     @param  elapsedTime The amount of time that has gone by since
     * last screen refresh.
     */
    @Override
    public void Update(float elapsedTime) {
        super.Update(elapsedTime);
        if (this.m_ElapsedTimeSinceLastFire > this.m_NextTimeToFire) {
            // Time to fire a missile!
            Missile m = new Missile(new Point(this.m_Currentposition.x + this.m_Currentposition.width / 2this.m_Currentposition.y)2true);
            GameObject.m_AllMissiles.add(m);
            this.m_NextTimeToFire = Enemy.RANDOM_GENERATOR.nextFloat() 2;
            this.m_ElapsedTimeSinceLastFire = 0;
        else {
            this.m_ElapsedTimeSinceLastFire += elapsedTime;
        }
        if (this.m_Currentposition.y + 64 >= 600 64) {
            // Monster has reached the bottom of the screen, so kill the spaceship:
            this.m_HasReachedBottom = true;
        }
    }
}