// vim:syntax=javascript

class Level
{
    var _parent_mc : MovieClip;
    var _mc : MovieClip;
    var _mc_name : String;
    var _level_width : Number;
    var _level_height : Number;

    function Level(
        parent_config : Object,
        guypos : Point,
        blasts : Number,
        filled_blocks : /*Rectangle*/ Array,
        exitpos : Point,
        enemy_inits : /*EnemyInit*/ Array
        ) {

        _parent_mc = parent_config.mc;
        _level_width = parent_config.level_rect.width;
        _level_height = parent_config.level_rect.height;

        _mc_name = "level_"+parent_config.sequence_no+"_mc";
        _mc = _parent_mc.attachMovie(
            "levelclip", _mc_name, parent_config.depth,
            {_x : parent_config.level_rect.x,
             _y : parent_config.level_rect.y,
             _level_width : _level_width,
             _level_height : _level_height,
             _initial_guypos : guypos,
             _initial_enemies : enemy_inits,
             _initial_filled : filled_blocks,
             _initial_blasts : blasts,
             _exitpos : exitpos,
             _blocks_wide : Math.floor(_level_width / parent_config.block_size),
             _blocks_high : Math.floor(_level_height / parent_config.block_size),
             _block_size : parent_config.block_size,
             _whenDone : parent_config.whenDone,
             _blast_meter_mc : parent_config.blast_meter_mc
             });
        //_parent_mc.attachMovie(
        //    "floor", "floor_mc", 2);
    }

    static function makeBox(x : Number, y : Number, width : Number, height : Number) : /*Rectangle*/ Array {
        var fills : /*Rectangle*/ Array = [
            new Rectangle(x, y, width, 1),
            new Rectangle(x+width-1, y+1, 1, height-2),
            new Rectangle(x, y+1, 1, height-2),
            new Rectangle(x, y+height-1, width, 1)
            ];
        return fills;
    }

    static function makeDot(x:Number, y:Number) : Rectangle {
        return new Rectangle(x,y,1,1);
    }

    static function makeCheckerboard(x : Number, y : Number, width : Number, height : Number) : /*Rectangle*/ Array {
        var fills : /*Rectangle*/ Array = new Array();

        for (var ix = x; ix < x + width; ix ++) {
            for (var iy = y; iy < y + height; iy ++) {
                if ((1+ix+iy)%2 == 0) {
                    fills.push(makeDot(ix,iy));
                }
            }
        }

        return fills;
    }
}
