Exemplo n.º 1
0
    /// <summary>
    /// 改變 p_x, p_y 位置的地城格子種類
    /// </summary>
    static public void ChangeCubeType(int p_x, int p_y, E_DUNGEON_CUBE_TYPE p_type)
    {
        DungeonMapData _mapData = mapsDatas[p_x, p_y];

        _mapData.SetCubeType(p_type);
        _mapData.RefrashObj();
    }
Exemplo n.º 2
0
    Vector3 GetEmptyPos()
    {
        // Try 30 times, may need refactor
        for (;;)
        {
            float x = Mathf.Floor(UnityEngine.Random.Range(0, DungeonManager.mapSize.x - 1));
            float y = Mathf.Floor(UnityEngine.Random.Range(0, DungeonManager.mapSize.y - 1));

            Vector2             _pos  = new Vector2(x, y);
            DungeonMapData      _data = DungeonManager.GetMapData(_pos);
            E_DUNGEON_CUBE_TYPE _type = _data.cubeType;
            if (_type == E_DUNGEON_CUBE_TYPE.NONE)
            {
                return(new Vector3(_pos.x, 0f, _pos.y));
            }
        }
        return(Vector3.zero);
    }
Exemplo n.º 3
0
    public void UpdateAtStep()
    {
        Vector3             _pos3 = PlayerManager.instance.playerInstance.transform.position;
        Vector2             _pos  = new Vector2(_pos3.x, _pos3.z);
        DungeonMapData      _data = DungeonManager.GetMapData(_pos);
        E_DUNGEON_CUBE_TYPE _type = _data.cubeType;

        if (_type == E_DUNGEON_CUBE_TYPE.NONE)
        {
            audiosource.PlayOneShot(slimestep, 1f);
        }
        if (_type == E_DUNGEON_CUBE_TYPE.WATER)
        {
            audiosource.PlayOneShot(water, 1f);
        }
        if (_type == E_DUNGEON_CUBE_TYPE.TRAP)
        {
            audiosource.PlayOneShot(fire, 1f);
        }
    }
Exemplo n.º 4
0
    /// <summary> 初始化地城 </summary>
    void InitDungeon()
    {
        #region "mapsDatas"
        int x, y;
        mapSize = new Vector2(sizeX, sizeY);
        homePos = new Vector2(sizeX / 2, sizeY / 2);
        //隨機中央
        for (y = 1; y < (mapSize.y - 1); y++)
        {
            for (x = 1; x < (mapSize.x - 1); x++)
            {
                E_DUNGEON_CUBE_TYPE _cubeType = GetRandomCubeType();
                Item.ItemType       _itemType = Item.ItemType.empty;
                if (_cubeType == E_DUNGEON_CUBE_TYPE.NONE)
                {
                    _itemType = GetRandomItemType();
                }
                mapsDatas [x, y] = new DungeonMapData(new Vector2(x, y), _cubeType, _itemType);
            }
        }
        //上下外牆
        y = (int)mapSize.y - 1;
        for (x = 0; x < mapSize.x; x++)
        {
            mapsDatas [x, 0] = new DungeonMapData(new Vector2(x, 0), E_DUNGEON_CUBE_TYPE.WALL, Item.ItemType.empty);
            mapsDatas [x, y] = new DungeonMapData(new Vector2(x, y), E_DUNGEON_CUBE_TYPE.WALL, Item.ItemType.empty);
        }
        x = (int)mapSize.x - 1;
        //左右外牆
        for (y = 1; y < (mapSize.y - 1); y++)
        {
            mapsDatas [0, y] = new DungeonMapData(new Vector2(0, y), E_DUNGEON_CUBE_TYPE.WALL, Item.ItemType.empty);
            mapsDatas [x, y] = new DungeonMapData(new Vector2(x, y), E_DUNGEON_CUBE_TYPE.WALL, Item.ItemType.empty);
        }

        //家
        Vector2[] _homePos = new Vector2[] {
            new Vector2(homePos.x - 1, homePos.y + 2),
            new Vector2(homePos.x, homePos.y + 2),
            new Vector2(homePos.x + 1, homePos.y + 2),

            new Vector2(homePos.x - 2, homePos.y + 1),
            new Vector2(homePos.x - 1, homePos.y + 1),
            new Vector2(homePos.x, homePos.y + 1),
            new Vector2(homePos.x + 1, homePos.y + 1),
            new Vector2(homePos.x + 2, homePos.y + 1),

            new Vector2(homePos.x - 2, homePos.y),
            new Vector2(homePos.x - 1, homePos.y),
            new Vector2(homePos.x, homePos.y),
            new Vector2(homePos.x + 1, homePos.y),
            new Vector2(homePos.x + 2, homePos.y),

            new Vector2(homePos.x - 2, homePos.y - 1),
            new Vector2(homePos.x - 1, homePos.y - 1),
            new Vector2(homePos.x, homePos.y - 1),
            new Vector2(homePos.x + 1, homePos.y - 1),
            new Vector2(homePos.x + 2, homePos.y - 1),

            new Vector2(homePos.x - 1, homePos.y - 2),
            new Vector2(homePos.x, homePos.y - 2),
            new Vector2(homePos.x + 1, homePos.y - 2),
        };
        int len = _homePos.Length;
        for (int f = 0; f < len; f++)
        {
            Vector2 _pos = _homePos[f];
            mapsDatas [(int)_pos.x, (int)_pos.y] = new DungeonMapData(_pos, E_DUNGEON_CUBE_TYPE.HOME, Item.ItemType.empty);
        }
        #endregion

        #region "Road"
        //分組
        int _groupID = 0;
        List <DungeonMapData> _wallList = new List <DungeonMapData>();

        int _stackCount = 0;
        for (y = 1; y < (mapSize.y - 1); y++)
        {
            for (x = 1; x < (mapSize.x - 1); x++)
            {
                DungeonMapData _mapData = mapsDatas [x, y];
                if (_mapData.cubeData.canThrough)
                {
                    if (_mapData.groupID < 0)
                    {
                        _groupID++;

                        PaintGroup(_mapData, _groupID);
                    }
                }
                else
                {
                    _wallList.Add(_mapData);
                }
            }
        }

//		dungeonTopObj = new GameObject().transform;
//		dungeonTopObj.gameObject.name = "First : ";
//		dungeonTopObj.gameObject.SetActive(false);
//		GenerateObj (_groupID);

        //建路
        List <int> _needRoadList = new List <int>();
        for (int f = 0; f <= _groupID; f++)
        {
            _needRoadList.Add(f);
        }

        int  whileCount = 0;
        bool _hasChange;
        while (_needRoadList.Count > 0)
        {
            _hasChange = false;
            whileCount++;
            if (whileCount >= 10)
            {
                break;
            }
            _wallList.Sort(DungeonMapData.CompareByNeighborCount);
            len = _wallList.Count;
            for (int f = 0; f < len; f++)
            {
                DungeonMapData _wallData = _wallList[f];
                int            len2      = _needRoadList.Count;
                bool           _isFirst  = true;
                int            _firstID  = 0;
                for (int f2 = 0; f2 < len2; f2++)
                {
                    int _nowID = _needRoadList[f2];
                    if (_wallData.neighborGroupID.Contains(_nowID))
                    {
                        if (_isFirst)
                        {
                            _firstID = _nowID;
                            _isFirst = false;
                        }
                        else
                        {
                            _wallData.SetCubeType(E_DUNGEON_CUBE_TYPE.NONE);
                            _wallData.groupID = _nowID;
                            PaintGroup(_wallData, _firstID);
//							Debug.Log("whileCount:" + whileCount + " pos:" + _wallData.pos + " firstID:" + _firstID + " nowID:" + _nowID);
                            _needRoadList.RemoveAt(f2);
                            len2--;
                            f2--;
                            _hasChange = true;
                            break;
                        }
                    }
                }
            }

//			dungeonTopObj = new GameObject().transform;
//			dungeonTopObj.gameObject.name = "whileCount : " + whileCount;
//			dungeonTopObj.gameObject.SetActive(false);
//			GenerateObj (_groupID);

            if (!_hasChange)
            {
                break;
            }
        }
//		Debug.Log("whileCount : " + whileCount);
        #endregion

        #region "Block"

        int _mainGroupId = mapsDatas [sizeX / 2, sizeY / 2].groupID;

        for (y = 1; y < (mapSize.y - 1); y++)
        {
            for (x = 1; x < (mapSize.x - 1); x++)
            {
                DungeonMapData _mapData = mapsDatas [x, y];
                if (_mapData.cubeData.canThrough && (_mapData.groupID != _mainGroupId))
                {
                    _mapData.SetCubeType(E_DUNGEON_CUBE_TYPE.WALL);
                    _mapData.groupID = -1;
                }
            }
        }

        #endregion

        //		GenerateObjWithColor (_groupID);

        EnemyBehavior.instance.Init();
    }
Exemplo n.º 5
0
 /// <summary>
 /// 改變 p_pos 位置的地城格子種類
 /// </summary>
 static public void ChangeCubeType(Vector2 p_pos, E_DUNGEON_CUBE_TYPE p_type)
 {
     ChangeCubeType((int)p_pos.x, (int)p_pos.y, p_type);
 }
Exemplo n.º 6
0
 /// <summary>
 /// 取得 p_type 種類的地形資料
 /// </summary>
 static public DungeonCubeData GetCubeData(E_DUNGEON_CUBE_TYPE p_type)
 {
     return(GetCubeData((int)p_type));
 }
Exemplo n.º 7
0
 public void SetCubeType(E_DUNGEON_CUBE_TYPE p_type)
 {
     cubeType = p_type;
     cubeData = DungeonManager.GetCubeData(cubeType);
 }
Exemplo n.º 8
0
 void Init(Vector2 p_pos, E_DUNGEON_CUBE_TYPE p_type, Item.ItemType p_itemType)
 {
     pos = p_pos;
     SetCubeType(p_type);
     SetItemType(p_itemType);
 }
Exemplo n.º 9
0
 public DungeonMapData(Vector2 p_pos, E_DUNGEON_CUBE_TYPE p_type, Item.ItemType p_itemType)
 {
     Init(p_pos, p_type, p_itemType);
 }