// vim:syntax=javascript

class Enemy extends Actor
{
    static function makeEnemy(parent_mc : LevelClip, ei : EnemyInit) : Enemy {
        return new ei.type(parent_mc, ei);
    }

    private var _will_explode : Boolean;

    function Enemy(parent_mc : LevelClip, sprite_names : Array, px : Number, py : Number, pdir : Number, psize : Number) {
        super(parent_mc, sprite_names, px, py, pdir, psize);

        _will_explode = false;
        
        onDeath = function () : Actor {
            if (this._will_explode) {
                return new Explosion(parent_mc, this.x+this.size/2-Explosion.EXPLOSION_SIZE/2, this.y+this.size/2-Explosion.EXPLOSION_SIZE/2);
            } else {
                return null;
            }
        };


        var static_this = this;

        set_onPress(function () {
            if (parent_mc.canAsplode(static_this)) {
                static_this.setWillExplode();
                static_this.setDead();
            }
        });
    }

    function killsGuy() : Boolean {
        return true;
    }

    function canBeKilled() : Boolean {
        return true;
    }

    function setWillExplode() {
        _will_explode = true;
    }
}
