Exemple #1
0
    /// <summary>
    /// 改變 p_x, p_y 位置的道具種類
    /// </summary>
    static public void ChangeItemType(int p_x, int p_y, Item.ItemType p_type)
    {
        DungeonMapData _mapData = mapsDatas[p_x, p_y];

        _mapData.SetItemType(p_type);
        _mapData.RefrashObj();
    }
Exemple #2
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();
    }
Exemple #3
0
    void PaintGroup(DungeonMapData p_mapData, int p_groupId)
    {
        Stack <DungeonMapData> _mapStack = new Stack <DungeonMapData>();
        int _targetId = p_mapData.groupID;

        _mapStack.Push(p_mapData);
        int _stackCount = 1;

        while (_stackCount > 0)
        {
            DungeonMapData _nowData = _mapStack.Pop();
            _stackCount--;
            _nowData.groupID = p_groupId;

            for (int f = 0; f < 4; f++)
            {
                Vector2        _subPos  = _nowData.pos + neighborPos[f];
                DungeonMapData _subData = mapsDatas [(int)_subPos.x, (int)_subPos.y];
                if (_subData.cubeData.canThrough)
                {
                    if (_subData.groupID == _targetId)
                    {
                        _mapStack.Push(_subData);
                        _stackCount++;
                    }
                }
                else
                {
                    _subData.AddNeighbor(p_groupId);
                }
            }
        }
    }
Exemple #4
0
    void GenerateObjWithColor(int p_maxGroupID)
    {
        if (_colors == null)
        {
            _colors = new Color[p_maxGroupID + 1];
            for (int f = 0; f <= p_maxGroupID; f++)
            {
                _colors [f] = Random.ColorHSV();
            }
        }
        for (int y = 0; y < mapSize.y; y++)
        {
            for (int x = 0; x < mapSize.x; x++)
            {
                DungeonMapData _data = mapsDatas [x, y];
                _data.cubeObj = Instantiate(_data.cubeData.cubePrefab).GetComponent <CubeObj>();
                _data.cubeObj.transform.position = new Vector3(_data.pos.x, 0, _data.pos.y);
                _data.cubeObj.transform.SetParent(dungeonTopObj);
                if (_data.groupID >= 0)
                {
                    _data.cubeObj.SetColor(_colors[_data.groupID]);
//				}else if(_data.groupID == -2){
//					_data.cubeObj.SetColor(Color.white);
                }
                else
                {
                    _data.cubeObj.SetColor(Color.blue);
                }
            }
        }
    }
    private void Awake()
    {
        var bounds = TilePrefab.GetComponent <Renderer>().bounds;

        edgeLength = bounds.size.x / 2;
        persistor  = GameObject.FindGameObjectWithTag("GameStatsPersistor").GetComponent <GameStatsPersistor> ();
        GameStats  = persistor.GameStats;
        mapData    = GameStats.DungeonMap;
        mapData.CommitMovement();
    }
Exemple #6
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);
    }
Exemple #7
0
    public void Move()
    {
        lastFramePos = playerInstance.transform.position;

        if (checkHome())
        {
            destination = playerInstance.transform.position;
            return;
        }

        int condition = checkConflict();

        // Check Sys Text
        DungeonMapData data1 = DungeonManager.GetMapData(new Vector2(PlayerManager.instance.playerInstance.transform.position.x, PlayerManager.instance.playerInstance.transform.position.z));
        DungeonMapData data2 = DungeonManager.GetMapData(new Vector2(instance.destination.x, PlayerManager.instance.destination.z));

//        if (data1.cubeType != E_DUNGEON_CUBE_TYPE.HOME && data2.cubeType == E_DUNGEON_CUBE_TYPE.HOME && !UIManger.isSystemTextOpen)
//        {
//            UIManger.instance.ShowSystemText();
//        }

        if (condition == 1)
        {
            destination = playerInstance.transform.position;
            DecreaseHealth(MonsterMinusHealth);
            ParticleManager.ShowParticle((int)destination.x, (int)destination.z, E_PARTICLE_TYPE.HIT);
        }
        else if (condition == 2)
        {
            // 剛剛好跟怪錯位,扣血但是可以移動
            DecreaseHealth(MonsterMinusHealth);
            ParticleManager.ShowParticle((int)destination.x, (int)destination.z, E_PARTICLE_TYPE.HIT);
            StartCoroutine(LerpPosition());
        }
        else if (condition == 0 || condition == 3)
        {
            StartCoroutine(LerpPosition());
        }
        else         // Posion 的狀況
        {
            EnemyBehavior.instance.Dead(LoserEnemy);
            destination = playerInstance.transform.position;
        }
    }
 public static void Initialize()
 {
     //EventGetter.BeginGame();
     //tower1 = EventGetter.CreateTower();
     //dining1 = EventGetter.CreateDining();
     //research1 = EventGetter.CreateResearch();
     //sports1 = EventGetter.CreateSports();
     //art1 = EventGetter.CreateArts();
     //health1 = EventGetter.CreateHealth();
     //lecture1 = EventGetter.CreateLecture();
     bossLocations = new List <int>();
     //EventGetter.PlaceBosses(tower1, dining1, research1, sports1, art1, health1, lecture1);
     //tower = new Queue<Event>(tower1);
     //dining = new Queue<Event>(dining1);
     //research = new Queue<Event>(research1);
     //sports = new Queue<Event>(sports1);
     //art = new Queue<Event>(art1);
     //health = new Queue<Event>(health1);
     //lecture = new Queue<Event>(lecture1);
     DungeonMapData.Initialize();
     followUp      = null;
     Time.timeUnit = 0;
     cleared       = new Dictionary <string, bool>(); cleared.Add("tower", false); cleared.Add("dining", false); cleared.Add("research", false);
     cleared.Add("sports", false); cleared.Add("art", false); cleared.Add("health", false); cleared.Add("lecture", false);
     shops = new Dictionary <string, Inventory>(); shops.Add("tower", new Inventory("tower")); shops.Add("dining", new Inventory("dining"));
     shops.Add("research", new Inventory("research")); shops.Add("sports", new Inventory("sports")); shops.Add("art", new Inventory("art"));
     shops.Add("health", new Inventory("health")); shops.Add("lecture", new Inventory("lecture"));
     shops[IndexToWord(bossLocations[0])].scoutMessage = "The trail of this areas boss leads back to " + IndexToWord(bossLocations[3]);
     shops[IndexToWord(bossLocations[1])].scoutMessage = "The trail of this areas boss leads back to " + IndexToWord(bossLocations[3]);
     shops[IndexToWord(bossLocations[2])].scoutMessage = "The trail of this areas boss leads back to " + IndexToWord(bossLocations[3]);
     shops[IndexToWord(bossLocations[3])].scoutMessage = "HACKER! YOU SHOULDN'T SEE THIS!";
     shops[IndexToWord(bossLocations[4])].scoutMessage = "It seems suspicious activity was seen in " + IndexToWord(bossLocations[0]);
     shops[IndexToWord(bossLocations[5])].scoutMessage = "It seems suspicious activity was seen in " + IndexToWord(bossLocations[1]);
     shops[IndexToWord(bossLocations[6])].scoutMessage = "It seems suspicious activity was seen in " + IndexToWord(bossLocations[2]);
     defeatedP       = false;
     defeatedC       = false;
     defeatedG       = false;
     Battle.inBattle = false;
     Dungeon.fled    = false;
     tutorialPlayed  = false;
     location        = Map.currentPosition;
     Score.Reset();
     Investigate.Initialize();
 }
Exemple #9
0
    IEnumerator LerpPosition()
    {
        islerping = true;
        while ((playerInstance.transform.position - destination).sqrMagnitude > 0.0001f)
        {
            playerInstance.transform.position = Vector3.MoveTowards(playerInstance.transform.position, destination, moveSpeed * Time.deltaTime);
            yield return(null);
        }
        playerInstance.transform.position = destination;

        DungeonMapData _data = DungeonManager.GetMapData((int)destination.x, (int)destination.z);

        if ((_data.itemType != Item.ItemType.empty))
        {
            AddItem(_data.itemData);
            DungeonManager.ChangeItemType((int)destination.x, (int)destination.z, Item.ItemType.empty);
        }

        islerping = false;
        if (_data.cubeType == E_DUNGEON_CUBE_TYPE.HOME)
        {
            if (instance.food > 0)
            {
                IncreaseSatiation(instance.food);
                SetFood(0);
                UIManger.instance.ShowSystemText();
                UIManger.StartChangeMap();
            }
            CameraManager.instance.cmrAnimator.SetBool("inHome", true);
        }
        else
        {
            if (_data.cubeType == E_DUNGEON_CUBE_TYPE.WATER)
            {
                ParticleManager.ShowParticle((int)destination.x, (int)destination.z, E_PARTICLE_TYPE.WATER);
            }

            CameraManager.instance.cmrAnimator.SetBool("inHome", false);
            IncreaseSatiation(-1f);
        }
        //		Fuse (slimeMode, _data.itemType);
    }
Exemple #10
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);
        }
    }
Exemple #11
0
    public void GetNextStepTranslate()
    {
        if (Input.GetKeyDown(KeyCode.W))
        {
            keyQueue.Enqueue(KeyCode.W);
        }
        else if (Input.GetKeyDown(KeyCode.S))
        {
            keyQueue.Enqueue(KeyCode.S);
        }
        else if (Input.GetKeyDown(KeyCode.A))
        {
            keyQueue.Enqueue(KeyCode.A);
        }
        else if (Input.GetKeyDown(KeyCode.D))
        {
            keyQueue.Enqueue(KeyCode.D);
        }


        if (!islerping)
        {
            if (keyQueue.Count <= 0)
            {
                return;
            }

            KeyCode _nowKey = keyQueue.Dequeue();

            switch (_nowKey)
            {
            case KeyCode.W:
                nextPosition   = Vector3.forward;
                rotationAngles = Vector3.zero * 90f;
                break;

            case KeyCode.S:
                nextPosition   = Vector3.back;
                rotationAngles = Vector3.down * 180f;
                break;

            case KeyCode.A:
                nextPosition   = Vector3.left;
                rotationAngles = Vector3.down * 90f;
                break;

            case KeyCode.D:
                nextPosition   = Vector3.right;
                rotationAngles = Vector3.up * 90f;
                break;
            }

            playerInstance.GetComponent <Animator>().Play("Armature|jump", -1, 0);

            Vector3        _nextPos             = instance.destination + instance.nextPosition;
            bool           isConflictWithYogurt = (yogurtInstance.transform.position.x != -9999 && (yogurtInstance.transform.position - _nextPos).magnitude < 0.01f);
            DungeonMapData _data = DungeonManager.GetMapData((int)_nextPos.x, (int)_nextPos.z);

            if (_data.cubeData.canThrough && !isConflictWithYogurt)
            {
                if ((_data.itemData.canFuse) && (slimeMode != Item.ItemType.empty))
                {
                    Item.ItemType resultType = CheckFuse(slimeMode, _data.itemType);
                    if ((int)resultType > (int)Item.ItemType.poison)
                    {
                        // 吃到全部,不能合成
                    }
                    else
                    {
                        StepManager.InvokeStep();
                    }
                }
                else
                {
                    StepManager.InvokeStep();
                }

                if (_data.cubeType == E_DUNGEON_CUBE_TYPE.WATER)
                {
                    SlimeBehaviourManger.instance.GetNextStep(_data);

                    SlimeBehaviourManger.instance.WalkOnWater();
                }

                if (_data.cubeType == E_DUNGEON_CUBE_TYPE.TRAP)
                {
                    SlimeBehaviourManger.instance.GetNextStep(_data);

                    SlimeBehaviourManger.instance.WalkOnTrap();
                }
            }
            else if (_data.cubeType == E_DUNGEON_CUBE_TYPE.EARTH && slimeMode == Item.ItemType.acid)
            {
                SlimeBehaviourManger.instance.GetNextStep(_data);

                SlimeBehaviourManger.instance.AcidMeltWall();
                Rotate();
            }
            else
            {
                Rotate();
            }
        }
    }
Exemple #12
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();
    }
Exemple #13
0
 public static int CompareByNeighborCount(DungeonMapData p_A, DungeonMapData p_B)
 {
     return(p_A.neighborCount.CompareTo(p_B.neighborCount));
 }
Exemple #14
0
 public void GetNextStep(DungeonMapData getNextStepData)
 {
     // Debug.Log(getNextStepData);
     nextStepData = getNextStepData;
 }