コード例 #1
0
    //todo
    public static Stage NewMap(int times)
    {
        Clear();
        //Random pick a **start** room and register it;
        DRoom _room = RoomPresetsManager.GetInstance().RandomPicking().GetRoomInfo();

        //DRoom _room = RoomPresetsManager.GetInstance().GetPreset(0).GetRoomInfo();
        RegisterNewRoom(_room, _room.d_DoorList.First.Value, new DPointN(0, 0));

        for (int i = 0; i < times; i++)
        {
            AddNewRoom();
            if (m_OpeningDoorList.Count == 0)
            {
                Debug.Log(i);
                break;
            }
        }


        //make map

        Rect  _rct   = GetMapRect();
        Stage _stage = new Stage((int)_rct.width, (int)_rct.height);

        foreach (DSavedRoom _svroom in m_RoomList)
        {
            DRoomPreset _preset = RoomPresetsManager.GetInstance().GetPreset(_svroom.d_ID);
            if (_preset == null)
            {
                continue;
            }

            int _x = (int)_svroom.d_Rect.x - (int)_rct.x;
            int _y = (int)_svroom.d_Rect.y - (int)_rct.y;
            int _w = (int)_svroom.d_Rect.width + 1;
            int _h = (int)_svroom.d_Rect.height + 1;

            for (int i = 0; i < _w; i++)
            {
                for (int j = 0; j < _h; j++)
                {
                    int _mapPos    = (_x + i) + (_y + j) * (int)_rct.width;
                    int _presetPos = i + j * _w;

                    DCell _cell = _preset.d_Data[_presetPos];
                    if (_cell.d_bIsDoor)
                    {
                        _stage.GetMap()[_mapPos] = new DCell(0, false, true, false);
                    }
                    else
                    {
                        _stage.GetMap()[_mapPos] = _cell;
                    }
                }
            }
        }
        //Add ClosedDoors to data
        foreach (DDoor _door in m_ClosedDoorList)
        {
            int _x      = _door.d_ptGlobalPos.x - (int)_rct.x;
            int _y      = _door.d_ptGlobalPos.y - (int)_rct.y;
            int _mapPos = _x + _y * (int)_rct.width;
            _stage.GetMap()[_mapPos] = new DCell(0, true, false, false);//get data from DDoor?todo
        }

        return(_stage);
    }
コード例 #2
0
ファイル: luatest.cs プロジェクト: lozzmki/ZProject
    // Use this for initialization
    void Start()
    {
        //         GameObject obj = new GameObject("ItemPattern");
        //         obj.AddComponent<Item>();
        //         obj.GetComponent<Item>().m_LuaScript = "ItemRangePattern";
        //         _dic = ObjectManager.getInstance().addObject(obj);
        //
        //
        //         GameObject oobj = new GameObject("ItemPattern2");
        //         oobj.AddComponent<Item>();
        //         oobj.GetComponent<Item>().m_LuaScript = "ItemMeleePattern";
        //         _dic2 = ObjectManager.getInstance().addObject(oobj);

        //Debug.Log(Resources.Load("Meshes/Shell"));

        GameObject _obj = ObjectDictionary.GetItemDic().CreateObject("ItemRangePattern",
                                                                     gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                                     Quaternion.AngleAxis(0, Vector3.up));

        ObjectDictionary.GetItemDic().CreateObject("ItemRangePattern",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));

        ObjectDictionary.GetItemDic().CreateObject("ItemPartsPattern",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("CubeAmmo",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("ItemPartsPattern",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("CubeAmmo",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("ItemPartsPattern",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("CubeAmmo",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));


        //map test
        DCell W = new DCell(0, false, true, false);
        DCell R = new DCell();
        DCell D = new DCell(0, true, false);

        DRoomPreset _room1 = new DRoomPreset();

        _room1.d_Size = new DSizeN(7, 7);
        _room1.d_Data = new DCell[]
        {
            W, W, W, D, W, W, W,
            W, R, R, R, R, R, W,
            W, R, R, R, R, R, W,
            D, R, R, R, R, R, D,
            W, R, R, R, R, R, W,
            W, R, R, R, R, R, W,
            W, W, W, D, W, W, W,
        };

        DRoomPreset _room2 = new DRoomPreset();

        _room2.d_Size = new DSizeN(5, 13);
        _room2.d_Data = new DCell[]
        {
            W, W, W, D, W,
            W, R, R, R, W,
            W, R, R, R, W,
            W, R, R, R, W,
            W, R, R, R, W,
            D, R, R, R, W,
            W, R, R, R, D,
            W, R, R, R, W,
            W, R, R, R, W,
            W, R, R, R, W,
            W, R, R, R, W,
            D, R, R, R, W,
            W, W, D, W, W,
        };

        DRoomPreset _room3 = new DRoomPreset();

        _room3.d_Size = new DSizeN(13, 5);
        _room3.d_Data = new DCell[]
        {
            W, W, D, W, W, W, W, W, D, W, W, W, W,
            W, R, R, R, R, R, R, R, R, R, R, R, W,
            W, R, R, R, R, R, R, R, R, R, R, R, W,
            D, R, R, R, R, R, R, R, R, R, R, R, D,
            W, W, W, W, W, D, W, W, W, W, W, D, W,
        };

        //RoomPresetsManager.GetInstance().AddPreset(_room1);
        //RoomPresetsManager.GetInstance().AddPreset(_room2);
        //RoomPresetsManager.GetInstance().AddPreset(_room3);
        //test
        RoomPresetsManager.GetInstance().AddPreset(mapEditor.Output.GetPresetByMap("C:/Users/FLYPLUSSS/Desktop/ZProject-dev/maps/7x7.txt"));

        Stage _stage = MapGenerator.NewMap(100);

        _stage.CreateStage();


        GameObject go = new GameObject("aaa");

        go.AddComponent(typeof(ttest));
        go.GetComponent <ttest>().tc    = new testClass();
        go.GetComponent <ttest>().tc.aa = 10;
        go.GetComponent <ttest>().tc.bb = 10;
        GameObject go2 = Instantiate(go);

        go.GetComponent <ttest>().tc.aa = 20;
        go.GetComponent <ttest>().tc.bb = 20;
        GameObject go3 = Instantiate(go);

        go.GetComponent <ttest>().tc.aa = 30;
        go.GetComponent <ttest>().tc.bb = 30;

        Debug.Log(go.GetComponent <ttest>().tc.aa);
        Debug.Log(go.GetComponent <ttest>().tc.bb);
        Debug.Log(go2.GetComponent <ttest>().tc.aa);
        Debug.Log(go2.GetComponent <ttest>().tc.bb);
        Debug.Log(go3.GetComponent <ttest>().tc.aa);
        Debug.Log(go3.GetComponent <ttest>().tc.bb);
    }
コード例 #3
0
 public void AddPreset(DRoomPreset preset)
 {
     m_Presets.Add(m_nNextID, preset);
     preset.setID(m_nNextID++);
 }
コード例 #4
0
ファイル: Output.cs プロジェクト: lozzmki/ZProject
        public static DRoomPreset GetPresetByMap(string filename)
        {
            FileStream   fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);

            //var map = GameObject.Find("CellContainer").GetComponent<CellManager>();


            int width  = br.ReadInt32();
            int height = br.ReadInt32();

            //map.RegenerateMap_Editor(width, height);
            DRoomPreset rlsPreset = new DRoomPreset(width, height);

            SCENEOBJ_TYPE[,] objmap = new SCENEOBJ_TYPE[width, height];
            int[,] texMap           = new int[width, height];

            Debug.Log(width + " , " + height);
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    var mat_id = br.ReadInt32();
                    texMap[i, j] = mat_id;
                    Debug.Log(mat_id);
                    //map.getCell(new Vector2(i, j)).GetComponent<Cell>().ChangeFoorMat(mat_id);
                }
            }

            var objLength = br.ReadInt32();

            for (int i = 0; i < objLength; i++)
            {
                var mapx     = br.ReadInt32();
                var mapy     = br.ReadInt32();
                var rotateId = br.ReadInt32();
                var name     = br.ReadString();
                Debug.Log(mapx + " , " + mapy + "ROTATE :" + rotateId + " NAME:" + name);
                objmap[mapx, mapy] = NameToSceneObj(name);
                //map.getCell(new Vector2(mapx, mapy)).GetComponent<Cell>().BuildBox(
                //   GameObject.Find("GameStone").GetComponent<ResrouceManager>().NameToSceneObj(name));
                //map.getCell(new Vector2(mapx, mapy)).GetComponent<Cell>().GetBuilding.GetObjRotate = rotateId;
            }
            for (int w = 0; w < width; w++)
            {
                for (int h = 0; h < height; h++)
                {
                    DCell cell = new DCell(texMap[w, h]);
                    if (objmap[w, h] == SCENEOBJ_TYPE.DOOR0)
                    {
                        cell.d_bIsDoor = true;
                    }
                    if (objmap[w, h] == SCENEOBJ_TYPE.WALL_1 || objmap[w, h] == SCENEOBJ_TYPE.WALL_CORNER_1)
                    {
                        cell.d_bIsWall = true;
                    }
                    rlsPreset.d_Data[h * width + w] = cell;
                }
            }
            fs.Close();
            br.Close();
            return(rlsPreset);
        }
コード例 #5
0
    // Use this for initialization
    void Start()
    {
        //         GameObject obj = new GameObject("ItemPattern");
        //         obj.AddComponent<Item>();
        //         obj.GetComponent<Item>().m_LuaScript = "ItemRangePattern";
        //         _dic = ObjectManager.getInstance().addObject(obj);
        //
        //
        //         GameObject oobj = new GameObject("ItemPattern2");
        //         oobj.AddComponent<Item>();
        //         oobj.GetComponent<Item>().m_LuaScript = "ItemMeleePattern";
        //         _dic2 = ObjectManager.getInstance().addObject(oobj);

        //Debug.Log(Resources.Load("Meshes/Shell"));

        ObjectDictionary.GetItemDic().CreateObject("ItemRangePattern",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));

        ObjectDictionary.GetItemDic().CreateObject("ItemPartsPattern",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("CubeAmmo",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("ItemPartsPattern",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("CubeAmmo",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("ItemPartsPattern",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("CubeAmmo",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));


        //map test
        DCell W = new DCell(0, false, true, false);
        DCell R = new DCell();
        DCell D = new DCell(0, true, false);

        DRoomPreset _room1 = new DRoomPreset();

        _room1.d_Size = new DSizeN(7, 7);
        _room1.d_Data = new DCell[]
        {
            W, W, W, D, W, W, W,
            W, R, R, R, R, R, W,
            W, R, R, R, R, R, W,
            D, R, R, R, R, R, D,
            W, R, R, R, R, R, W,
            W, R, R, R, R, R, W,
            W, W, W, D, W, W, W,
        };

        DRoomPreset _room2 = new DRoomPreset();

        _room2.d_Size = new DSizeN(5, 13);
        _room2.d_Data = new DCell[]
        {
            W, W, W, D, W,
            W, R, R, R, W,
            W, R, R, R, W,
            W, R, R, R, W,
            W, R, R, R, W,
            D, R, R, R, W,
            W, R, R, R, D,
            W, R, R, R, W,
            W, R, R, R, W,
            W, R, R, R, W,
            W, R, R, R, W,
            D, R, R, R, W,
            W, W, D, W, W,
        };

        DRoomPreset _room3 = new DRoomPreset();

        _room3.d_Size = new DSizeN(13, 5);
        _room3.d_Data = new DCell[]
        {
            W, W, D, W, W, W, W, W, D, W, W, W, W,
            W, R, R, R, R, R, R, R, R, R, R, R, W,
            W, R, R, R, R, R, R, R, R, R, R, R, W,
            D, R, R, R, R, R, R, R, R, R, R, R, D,
            W, W, W, W, W, D, W, W, W, W, W, D, W,
        };

        RoomPresetsManager.GetInstance().AddPreset(_room1);
        RoomPresetsManager.GetInstance().AddPreset(_room2);
        RoomPresetsManager.GetInstance().AddPreset(_room3);

        Stage _stage = MapGenerator.NewMap(100);

        _stage.CreateStage();
    }