﻿function Enemy(x, y, type, holder)
{
    this.xPos = x;
    this.yPos = y;
    this.type = type;
    this.holder = holder;
    this.holder.enemy = this;
    this.init();
}

Enemy.prototype.init = function()
{
    this.height = Settings.ENEMY_HEIGHT;
    this.width = Settings.ENEMY_WIDTH;
    var en = this.enemy = document.createElement('div');
    with(en.style)
    {
        position = "absolute";
        top = this.yPos + "px";
        left = this.xPos + "px";
        width = this.width + "px";
        height = this.height + "px";
        zIndex = "10";
        background = Settings["ENEMY_IMAGE" + this.type] || "#123123";
    }
    this.holder.appendChild(en);
}

Enemy.prototype.fire = function(x, y)
{
    this.shotChance = Settings.ENEMY_SHOT_CHANCE + LevelManager.LEVEL / 5
    if(Math.random() < this.shotChance)
    {
        var xPos = x + this.width / 2;
        var yPos = y + this.height ;
        var type = "enemy";
        new Bullet(xPos, yPos, type, this.enemy);
    }
}

Enemy.prototype.die = function()
{
    EventCenter.broadcast(Events.ENEMY_HIT, this.type);
    
    this.holder.removeChild(this.enemy);
}
