// vim:syntax=javascript

class BombEnemy extends Enemy
{
    static var ENEMY_SIZE : Number = 20;
    static var ENEMY_SPEED : Number = 2;
    static var sprite_names : Array = ["bomb_up","bomb_left","bomb_down","bomb_right"];
    var _turn_around_type : Array;

    function BombEnemy(parent_mc : LevelClip, ei : EnemyInit) {
        super(parent_mc, sprite_names, ei.pos.x, ei.pos.y, ei.dir, ENEMY_SIZE);

        // bombs will always explode!
        setWillExplode();

        _turn_around_type = DIR_OPPOSITE;
    }

    function doFrame() {
        var dp = dir_point;
        var next_x = x+dp.x*ENEMY_SPEED;
        var next_y = y+dp.y*ENEMY_SPEED;

        var close_to_guy = false;

        get_parent_mc().doGuyInRadius(this, Explosion.BLAST_RADIUS-Guy.GUY_SIZE/2,
            function (a : Actor) {
                close_to_guy = true;
            });

        if (close_to_guy) {
            // suicide, which will be an explosion
            setDead();
        } else {
            if (canMoveTo(next_x, next_y)) {
                moveTo(next_x, next_y, dir);
            } else {
                moveTo(x,y, _turn_around_type[dir]);
            }
        }
    }

    function killsGuy() : Boolean {
        return true;
    }

    function canBeKilled() : Boolean {
        return true;
    }
}
