Ejemplo n.º 1
0
    private void CreateRoom(Layer2DDungeonUnit layer, DgDivision.DgRect r)
    {
        Guid name = Guid.NewGuid();

        Rooms.Add(name, new RoomInformation(r.Top, r.Bottom, r.Right, r.Left, name));
        layer.FillRectLTRB(r.Left, r.Top, r.Right, r.Bottom, LoadStatus.Room, name);
    }
Ejemplo n.º 2
0
 /// <summary>
 /// 垂直方向に線を引く (上と下の位置は自動で反転する)
 /// </summary>
 /// <param name="top">上</param>
 /// <param name="bottom">下</param>
 /// <param name="x">X座標</param>
 void FillVLine(Layer2DDungeonUnit layer, int top, int bottom, int x, LoadStatus none)
 {
     if (top > bottom)
     {
         // 上下の位置関係が逆なので値をスワップする
         int tmp = top;
         top    = bottom;
         bottom = tmp;
     }
     layer.FillRectLTRB(x, top, x + 1, bottom + 1, none, Guid.Empty);
 }
Ejemplo n.º 3
0
    /// <summary>
    /// 指定した部屋の間を通路でつなぐ
    /// </summary>
    /// <param name="divA">部屋1</param>
    /// <param name="divB">部屋2</param>
    /// <param name="bGrandChild">孫チェックするかどうか</param>
    /// <returns>つなぐことができたらtrue</returns>
    //bool CreateRoad(DgDivision divA, DgDivision divB, bool bGrandChild = false)
    //{
    //    if (divA.Outer.Bottom == divB.Outer.Top || divA.Outer.Top == divB.Outer.Bottom)
    //    {
    //        // 上下でつながっている
    //        // 部屋から伸ばす通路の開始位置を決める
    //        int x1 = UnityEngine.Random.Range(divA.Room.Left, divA.Room.Right);
    //        int x2 = UnityEngine.Random.Range(divB.Room.Left, divB.Room.Right);
    //        int y = 0;

    //        if (bGrandChild)
    //        {
    //            // すでに通路が存在していたらその情報を使用する
    //            if (divA.HasRoad()) { x1 = divA.Road.Left; }
    //            if (divB.HasRoad()) { x2 = divB.Road.Left; }
    //        }

    //        if (divA.Outer.Top > divB.Outer.Top)
    //        {
    //            // B - A (Bが上側)
    //            y = divA.Outer.Top;
    //            // 通路を作成
    //            divA.CreateRoad(x1, y + 1, x1 + 1, divA.Room.Top);
    //            divB.CreateRoad(x2, divB.Room.Bottom, x2 + 1, y);
    //        }
    //        else
    //        {
    //            // A - B (Aが上側)
    //            y = divB.Outer.Top;
    //            // 通路を作成
    //            divA.CreateRoad(x1, divA.Room.Bottom, x1 + 1, y);
    //            divB.CreateRoad(x2, y, x2 + 1, divB.Room.Top);
    //        }

    //        FillDgRect(DungeonMap, divA.Road, LoadStatus.Load);
    //        FillDgRect(DungeonMap, divB.Road, LoadStatus.Load);

    //        // 通路同士を接続する
    //        FillHLine(DungeonMap, x1, x2, y, LoadStatus.Load);

    //        // 通路を作れた
    //        return true;
    //    }

    //    if (divA.Outer.Left == divB.Outer.Right || divA.Outer.Right == divB.Outer.Left)
    //    {
    //        // 左右でつながっている
    //        // 部屋から伸ばす通路の開始位置を決める
    //        int y1 = UnityEngine.Random.Range(divA.Room.Top, divA.Room.Bottom);
    //        int y2 = UnityEngine.Random.Range(divB.Room.Top, divB.Room.Bottom);
    //        int x = 0;

    //        if (bGrandChild)
    //        {
    //            // すでに通路が存在していたらその情報を使う
    //            if (divA.HasRoad()) { y1 = divA.Road.Top; }
    //            if (divB.HasRoad()) { y2 = divB.Road.Top; }
    //        }

    //        if (divA.Outer.Left > divB.Outer.Left)
    //        {
    //            // B - A (Bが左側)
    //            x = divA.Outer.Left;
    //            // 通路を作成
    //            divB.CreateRoad(divB.Room.Right, y2, x, y2 + 1);
    //            divA.CreateRoad(x + 1, y1, divA.Room.Left, y1 + 1);
    //        }
    //        else
    //        {
    //            // A - B (Aが左側)
    //            x = divB.Outer.Left;
    //            divA.CreateRoad(divA.Room.Right, y1, x, y1 + 1);
    //            divB.CreateRoad(x, y2, divB.Room.Left, y2 + 1);
    //        }

    //        FillDgRect(DungeonMap, divA.Road, LoadStatus.Load);
    //        FillDgRect(DungeonMap, divB.Road, LoadStatus.Load);

    //        // 通路同士を接続する
    //        FillVLine(DungeonMap, y1, y2, x, LoadStatus.Load);

    //        // 通路を作れた
    //        return true;
    //    }


    //    // つなげなかった
    //    return false;
    //}

    /// <summary>
    /// 水平方向に線を引く (左と右の位置は自動で反転する)
    /// </summary>
    /// <param name="left">左</param>
    /// <param name="right">右</param>
    /// <param name="y">Y座標</param>
    void FillHLine(Layer2DDungeonUnit layer, int left, int right, int y, LoadStatus none)
    {
        if (left > right)
        {
            // 左右の位置関係が逆なので値をスワップする
            int tmp = left;
            left  = right;
            right = tmp;
        }
        layer.FillRectLTRB(left, y, right + 1, y + 1, none, Guid.Empty);
    }
Ejemplo n.º 4
0
    public void CreateDungeon(int width, int height, bool isRecycle)
    {
        // ■1. 初期化
        // 2次元配列初期化
        if (isRecycle == true)
        {
            if (CommonFunction.IsNull(DungeonMap) == true)
            {
                DungeonMap = new Layer2DDungeonUnit(width, height);
            }
            else
            {
            }
        }
        else
        {
            DungeonMap = new Layer2DDungeonUnit(width, height);
        }

        Rooms.Clear();

        // 区画リスト作成
        _divList = new List <DgDivision>();

        // ■2. すべてを壁にする
        DungeonMap.Fill(LoadStatus.Wall);
        DungeonMap.Fill(DungeonInformation.Info.BaseLoadState, 1, width - 1, 1, height - 1);

        // ■3. 最初の区画を作る
        DgDivision div = CreateDivision(0, 0, width - 1, height - 1);

        // ■4. 区画を分割する
        // 垂直 or 水平分割フラグの決定
        bool bVertical = (UnityEngine.Random.Range(0, 2) == 0);

        SplitDivison(bVertical, div);

        // ■5. 区画に部屋を作る
        CreateRooms();

        // ■6. 部屋同士をつなぐ
        ConnectRooms();
    }
Ejemplo n.º 5
0
    public void CreateBossRoom(int width, int height, bool isRecycle)
    {
        // ■1. 初期化
        // 2次元配列初期化
        if (isRecycle == true)
        {
            if (CommonFunction.IsNull(DungeonMap) == true)
            {
                DungeonMap = new Layer2DDungeonUnit(width, height);
            }
            else
            {
            }
        }
        else
        {
            DungeonMap = new Layer2DDungeonUnit(width, height);
        }

        Rooms.Clear();

        // 区画リスト作成
        _divList = new List <DgDivision>();

        // ■2. すべてを壁にする
        DungeonMap.Fill(LoadStatus.Wall);

        //
        DungeonMap.Fill(DungeonInformation.Info.BaseLoadState, 1, width - 1, 1, height - 1);

        //広さの1/5取得
        int dist = width / 5;

        // ■3. 最初の区画を作る
        DgDivision div = CreateDivision(1 + dist, 1 + dist, width - 1 - dist, height - 1 - dist);

        div.Room.Set(1 + dist, 1 + dist, width - 1 - dist, height - 1 - dist);
        _divList.Add(div);

        // ■5. 区画に部屋を作る
        // 部屋を作る
        CreateRoom(DungeonMap, div.Room);
    }
Ejemplo n.º 6
0
 /// <summary>
 /// DgRectの範囲を塗りつぶす
 /// </summary>
 /// <param name="rect">矩形情報</param>
 void FillDgRect(Layer2DDungeonUnit layer, DgDivision.DgRect r, LoadStatus none)
 {
     layer.FillRectLTRB(r.Left, r.Top, r.Right, r.Bottom, none, Guid.Empty);
 }