class Tools.TBrounExp extends MovieClip
{
    var width, hiegth, ch_Depth, this_name, mc_ml, mc_ch, Chastitza;
    function TBrounExp(tmp_mc_name, tmp_mc_ch_name, tmp_mc_ml_name, ch_X, ch_Y, ch_R, ch_D, cnt_M, speed, wid, hie)
    {
        super();
        this.width = wid;
        this.hiegth = hie;
        this.cnt_Mol = cnt_M;
        this.curr_Speed = speed;
        this.ch_Depth = ch_D;
        eval(tmp_mc_name).createEmptyMovieClip("Tr_paint", ch_D - 1000);
        this.this_name = eval(tmp_mc_name).Tr_paint;
        this.mc_ml = tmp_mc_ml_name;
        this.mc_ch = tmp_mc_ch_name;
        this.Chastitza = new Tools.TChastitza(tmp_mc_name, tmp_mc_ch_name, ch_R, ch_X, ch_Y, 0, 0, ch_D);
        eval(tmp_mc_ch_name)._visible = true;
        var tmp_speed_X;
        var tmp_speed_Y;
        var i = 1;
        while (i <= cnt_M)
        {
            tmp_speed_X = random(this.curr_Speed / 3) + 3 * this.curr_Speed / 4;
            tmp_speed_Y = random(this.curr_Speed / 3) + 3 * this.curr_Speed / 4;
            if (random(2) < 1)
            {
                tmp_speed_X = -tmp_speed_X;
            } // end if
            if (random(2) < 1)
            {
                tmp_speed_Y = -tmp_speed_Y;
            } // end if
            this.arrMolekuls.push(new Tools.TMolekula(tmp_mc_name, tmp_mc_ml_name, ch_D - i, random(wid), random(hie), tmp_speed_X, tmp_speed_Y, 3));
            ++i;
        } // end while
    } // End of the function
    function Sqr(x)
    {
        return (x * x);
    } // End of the function
    function GetDistance(x1, y1, x2, y2)
    {
        return (Math.sqrt(this.Sqr(x1 - x2) + this.Sqr(y1 - y2)));
    } // End of the function
    function count_Alpha(M_x, M_y)
    {
        if (M_x == Chastitza.X)
        {
            M_x = M_x - 1;
        } // end if
        if (M_y == Chastitza.Y)
        {
            M_y = M_y - 1;
        } // end if
        var _loc4 = 180 * Math.atan((M_x - Chastitza.X) / (-M_y + Chastitza.Y)) / 3.141593;
        if (M_x > Chastitza.X && M_y > Chastitza.Y)
        {
            return (-_loc4);
        }
        else if (M_x > Chastitza.X && M_y < Chastitza.Y)
        {
            return (180 - _loc4);
        }
        else if (M_x < Chastitza.X && M_y > Chastitza.Y)
        {
            return (180 - _loc4);
        }
        else if (M_x < Chastitza.X && M_y < Chastitza.Y)
        {
            return (360 - _loc4);
        } // end else if
    } // End of the function
    function povorot(alpha, p1)
    {
        var _loc3 = Math.round(p1.x * Math.cos(alpha * 3.141593 / 180) + p1.y * Math.sin(alpha * 3.141593 / 180));
        var _loc2 = Math.round(p1.y * Math.cos(alpha * 3.141593 / 180) - p1.x * Math.sin(alpha * 3.141593 / 180));
        _loc2 = -_loc2;
        var _loc6 = Math.round(_loc3 * Math.cos(-alpha * 3.141593 / 180) + _loc2 * Math.sin(-alpha * 3.141593 / 180));
        var _loc5 = Math.round(_loc2 * Math.cos(-alpha * 3.141593 / 180) - _loc3 * Math.sin(-alpha * 3.141593 / 180));
        return ({x: _loc6, y: _loc5});
    } // End of the function
    function set_Speed(tmp_Speed)
    {
        if (tmp_Speed >= 0)
        {
            for (var _loc2 = 0; _loc2 < arrMolekuls.length; ++_loc2)
            {
                arrMolekuls[_loc2].Vx = arrMolekuls[_loc2].Vx * (tmp_Speed / curr_Speed);
                arrMolekuls[_loc2].Vy = arrMolekuls[_loc2].Vy * (tmp_Speed / curr_Speed);
            } // end of for
            curr_Speed = tmp_Speed;
        } // end if
    } // End of the function
    function set_cntM(tmp_cnt_M, tmp_mc_ml_name)
    {
        if (tmp_cnt_M >= 0)
        {
            if (tmp_cnt_M > cnt_Mol)
            {
                var _loc3;
                var _loc2;
                for (var _loc4 = 1; _loc4 <= tmp_cnt_M - cnt_Mol; ++_loc4)
                {
                    _loc3 = random(curr_Speed / 3) + 3 * curr_Speed / 4;
                    _loc2 = random(curr_Speed / 3) + 3 * curr_Speed / 4;
                    if (random(2) < 1)
                    {
                        _loc3 = -_loc3;
                    } // end if
                    if (random(2) < 1)
                    {
                        _loc2 = -_loc2;
                    } // end if
                    arrMolekuls.push(new Tools.TMolekula(this_name, tmp_mc_ml_name, ch_Depth - cnt_Mol - _loc4, random(width), random(hiegth), _loc3, _loc2, 3));
                } // end of for
            }
            else if (tmp_cnt_M < cnt_Mol)
            {
                for (var _loc4 = 1; _loc4 <= cnt_Mol - tmp_cnt_M; ++_loc4)
                {
                    arrMolekuls.pop().destroyMolekula();
                } // end of for
            } // end else if
            cnt_Mol = tmp_cnt_M;
        } // end if
    } // End of the function
    function set_k(koef)
    {
        if (koef > 0)
        {
            k = koef / 100;
        } // end if
    } // End of the function
    function set_stop_mode(flag)
    {
        stop_mode = flag;
    } // End of the function
    function set_drawing_mode(flag)
    {
        if (flag)
        {
            this_name.lineStyle(3, 16711680);
            this_name.moveTo(Chastitza.X, Chastitza.Y);
        }
        else
        {
            this_name.clear();
        } // end else if
        drawing_mode = flag;
    } // End of the function
    function timerPlay()
    {
        if (!stop_mode)
        {
            for (var _loc2 = 0; _loc2 < cnt_Mol; ++_loc2)
            {
                if (arrMolekuls[_loc2].X + arrMolekuls[_loc2].Vx >= width || arrMolekuls[_loc2].X + arrMolekuls[_loc2].Vx <= 0)
                {
                    arrMolekuls[_loc2].Vx = -arrMolekuls[_loc2].Vx;
                } // end if
                if (arrMolekuls[_loc2].Y + arrMolekuls[_loc2].Vy >= hiegth || arrMolekuls[_loc2].Y + arrMolekuls[_loc2].Vy <= 0)
                {
                    arrMolekuls[_loc2].Vy = -arrMolekuls[_loc2].Vy;
                } // end if
                arrMolekuls[_loc2].Move(arrMolekuls[_loc2].X = arrMolekuls[_loc2].X + arrMolekuls[_loc2].Vx, arrMolekuls[_loc2].Y = arrMolekuls[_loc2].Y + arrMolekuls[_loc2].Vy);
                if (this.GetDistance(arrMolekuls[_loc2].X, arrMolekuls[_loc2].Y, Chastitza.X, Chastitza.Y) <= Chastitza.R)
                {
                    if (!arrMolekuls[_loc2].wasCollision)
                    {
                        Chastitza.Vx = Chastitza.Vx + k * arrMolekuls[_loc2].Vx;
                        Chastitza.Vy = Chastitza.Vy + k * arrMolekuls[_loc2].Vy;
                        var _loc3 = this.povorot(-this.count_Alpha(arrMolekuls[_loc2].X, arrMolekuls[_loc2].Y), {x: arrMolekuls[_loc2].Vx, y: arrMolekuls[_loc2].Vy});
                        arrMolekuls[_loc2].Vx = _loc3.x;
                        arrMolekuls[_loc2].Vy = _loc3.y;
                        arrMolekuls[_loc2].wasCollision = true;
                    } // end if
                    continue;
                } // end if
                arrMolekuls[_loc2].wasCollision = false;
            } // end of for
            if (Chastitza.X + Chastitza.R + Chastitza.Vx > width || Chastitza.X - Chastitza.R + Chastitza.Vx < 0)
            {
                Chastitza.Vx = -Chastitza.Vx;
            } // end if
            if (Chastitza.Y + Chastitza.R + Chastitza.Vy > hiegth || Chastitza.Y - Chastitza.R + Chastitza.Vy < 0)
            {
                Chastitza.Vy = -Chastitza.Vy;
            } // end if
            Chastitza.Move(Chastitza.X = Chastitza.X + Chastitza.Vx, Chastitza.Y = Chastitza.Y + Chastitza.Vy);
            if (drawing_mode)
            {
                this_name.lineStyle(2, 11299500);
                this_name.lineTo(Chastitza.X, Chastitza.Y);
            } // end if
        } // end if
    } // End of the function
    function destroy()
    {
        this.set_cntM(0, mc_ml);
        mc_ch._visible = false;
        this_name.clear();
    } // End of the function
    var cnt_Mol = 0;
    var curr_Speed = 0;
    var arrMolekuls = Array();
    var k = 0.100000;
    var drawing_mode = false;
    var stop_mode = false;
} // End of Class
