Example #1
0
        public void InitBlockComponent(SectionComponent sectionComponent, BlockModel blockData)
        {
            animator.SetTrigger("reset");
            this.sectionComponent = sectionComponent;
            this.blockData        = blockData;
            isCollapsing          = isCollapsed = false;

            if (isGrid)
            {
                if ((Mathf.Abs(blockData.origin.x) % 2 == 0 && Mathf.Abs(blockData.origin.y) % 2 == 0) ||
                    (Mathf.Abs(blockData.origin.x) % 2 == 1 && Mathf.Abs(blockData.origin.y) % 2 == 1))
                {
                    foreach (Renderer renderer in renderers)
                    {
                        renderer.sharedMaterial = brightMaterial;
                    }
                }
                else
                {
                    foreach (Renderer renderer in renderers)
                    {
                        renderer.sharedMaterial = darkMaterial;
                    }
                }
            }
            else
            {
                foreach (Renderer renderer in renderers)
                {
                    renderer.sharedMaterial = brightMaterial;
                }
            }
            SetBlockPosition(this.blockData.origin);
            SetBlockDirection(this.blockData.direction);
        }
Example #2
0
        public void InitItemComponent(SectionComponent sectionComponent, Node origin, Direction direction)
        {
            this.sectionComponent = sectionComponent;
            this.origin           = origin;
            this.direction        = direction;

            SetItemPositionAndDirection(this.origin, this.direction);
        }
Example #3
0
        public void InitPath()
        {
            int startSectionId = 0;

            sectionIndex = 0;
            ClearPath();

            SectionModel firstCornerSection = new SectionModel(
                startSectionId,
                SectionType.corner,
                Direction.right,
                new Node(0, 0),
                pathWidth, pathWidth, MapManager.Instance.verticalCornerSectionContent.terrains);

            int unitLength = Random.Range(3, 6);

            unitLength = 2;
            int            firstStraightSectionLength = unitLength * 3;
            SectionContent sectionContent             = MapManager.Instance.GetSectionContentByUnitLength(unitLength);
            SectionModel   firstStraightSection       = new SectionModel(
                firstCornerSection.sectionId + 1,
                SectionType.straight,
                Direction.right,
                new Node(3, 0),
                firstStraightSectionLength, pathWidth);

            Direction secondCornerSectionDirection = Random.Range(0, 100) < 50 ? Direction.up : Direction.down;

            secondCornerSectionDirection = pm.playMode == PlayMode.campaign ? Direction.up : Direction.down;
            SectionModel secondCornerSection = new SectionModel(
                firstStraightSection.sectionId + 1,
                SectionType.corner,
                secondCornerSectionDirection,
                new Node(3 + firstStraightSectionLength, 0),
                pathWidth, pathWidth, secondCornerSectionDirection == Direction.up ? MapManager.Instance.decreaseCornerSectionContent.terrains : MapManager.Instance.increaseCornerSectionContent.terrains);

            SectionComponent firstCornerSectionComponent = MakeSection(firstCornerSection, firstStraightSection);

            PutSectionComponent(firstCornerSectionComponent);
            SectionComponent firstStraightSectionComponent = MakeSection(firstStraightSection, secondCornerSection);

            PutSectionComponent(firstStraightSectionComponent);
            SectionComponent secondCornerSectionComponent = MakeSection(secondCornerSection);

            PutSectionComponent(secondCornerSectionComponent);

            firstCornerSectionComponent.nextSectionComponent     = firstStraightSectionComponent;
            firstStraightSectionComponent.beforeSectionComponent = firstCornerSectionComponent;
            firstStraightSectionComponent.nextSectionComponent   = secondCornerSectionComponent;
            secondCornerSectionComponent.beforeSectionComponent  = firstStraightSectionComponent;
            currentSectionComponent = firstCornerSectionComponent;


            for (int i = 0; i < 5; i++)
            {
                AddSection(pm.playMode);
            }
        }
Example #4
0
 public void PutSectionComponent(SectionComponent sectionComponent)
 {
     if (sectionDictionary.ContainsKey(sectionComponent.sectionData.sectionId))
     {
         // Debug.Log("sectionDictionary already have key: " + sectionComponent.sectionData.sectionId.ToString());
         return;
     }
     sectionList.Add(sectionComponent);
     sectionDictionary.Add(sectionComponent.sectionData.sectionId, sectionComponent);
 }
Example #5
0
        SectionComponent MakeSection(SectionModel sectionData, SectionModel nextSectionData = null, bool isLastSection = false)
        {
            // Debug.Log("PathManager.MakeSection(" + sectionData.sectionId + ")");
            Transform sectionTransform = Instantiate(sectionPrefab) as Transform;

            sectionTransform.gameObject.name = "section#" + sectionData.sectionId.ToString();
            sectionTransform.SetParent(sectionContainer);
            SectionComponent sectionComponent = sectionTransform.GetComponent <SectionComponent>();

            sectionComponent.InitSectionComponent(sectionData, nextSectionData, lastSectionComponent, isLastSection);

            return(sectionComponent);
        }
Example #6
0
        public void InitTrapComponent(SectionComponent sectionComponent, Node origin, Direction direction, TiledObject tiledObject)
        {
            animator.SetTrigger("reset");
            this.sectionComponent = sectionComponent;
            this.origin           = origin;
            this.direction        = direction;
            this.axeDirection     = direction;

            SetTrapPosition(this.origin);
            SetTrapDirection(this.direction);
            float delay = 0.0f;

            if (tiledObject.properties != null)
            {
                delay = tiledObject.properties.delay;
            }

            if (trapType == TrapType.thornfloor || trapType == TrapType.punchmachine || trapType == TrapType.crossbow)
            {
                Invoke("StartTrap", delay);
            }
        }
Example #7
0
        public void SetInitialRotation(Node championOrigin)
        {
            BlockComponent   currentBlockComponent         = pm.pathManager.GetBlockComponentByOrigin(championOrigin);
            SectionComponent firstStraightSectionComponent = currentBlockComponent.sectionComponent.nextSectionComponent;
            // SectionComponent firstSectionComponent = pm.pathManager.GetSectionComponent(1);
            // SectionComponent secondSectionComponent = pm.pathManager.GetSectionComponent(2);
            int currentProgress = currentBlockComponent.blockData.progress;

            currentProgress = 1;
            int        minProgressInSection = firstStraightSectionComponent.minProgress;
            int        maxProgressInSection = firstStraightSectionComponent.maxProgress;
            float      startPercent         = (float)(currentProgress - minProgressInSection - 1) / (float)(maxProgressInSection - minProgressInSection);
            float      endPercent           = (float)(currentProgress - minProgressInSection) / (float)(maxProgressInSection - minProgressInSection);
            Quaternion initialRotation      = Quaternion.identity;
            Quaternion targetRotation       = Quaternion.identity;

            if (firstStraightSectionComponent.nextSectionComponent.nextSectionComponent.sectionData.direction == Direction.up)
            {
                initialRotation = Quaternion.Euler(pm.cameraController.championRightUpAngle);
            }
            else if (firstStraightSectionComponent.nextSectionComponent.nextSectionComponent.sectionData.direction == Direction.down)
            {
                initialRotation = Quaternion.Euler(pm.cameraController.championRightDownAngle);
            }

            if (firstStraightSectionComponent.nextSectionComponent.nextSectionComponent.sectionData.direction == Direction.up)
            {
                targetRotation = Quaternion.Euler(pm.cameraController.championUpAngle);
            }
            else if (firstStraightSectionComponent.nextSectionComponent.nextSectionComponent.sectionData.direction == Direction.down)
            {
                targetRotation = Quaternion.Euler(pm.cameraController.championDownAngle);
            }

            pm.cameraController.AnimatePivotAngle(initialRotation, initialRotation, startPercent, endPercent, 0.3f);
        }
Example #8
0
        public void ContinueGame()
        {
            playSceneState  = PlaySceneState.ready;
            isContinued     = true;
            champion.isDead = false;
            SectionComponent sectionComponent = pathManager.currentSectionComponent.nextSectionComponent;
            Node             continueNode     = new Node(0, 0);

            if (sectionComponent.sectionData.direction == Direction.right)
            {
                continueNode = sectionComponent.sectionData.origin + new Node(sectionComponent.sectionData.sectionType == SectionType.corner ? 1 : 0, 1);
            }
            else if (sectionComponent.sectionData.direction == Direction.up)
            {
                continueNode = sectionComponent.sectionData.origin + new Node(1, sectionComponent.sectionData.sectionType == SectionType.corner ? 1 : 0);
            }
            else if (sectionComponent.sectionData.direction == Direction.down)
            {
                continueNode = sectionComponent.sectionData.origin + new Node(1, sectionComponent.sectionData.height - 1 - (sectionComponent.sectionData.sectionType == SectionType.corner ? 1 : 0));
            }
            champion.InitChampionComponent(continueNode, sectionComponent.sectionData.direction);
            champion.animator.SetTrigger("continue");
            gameOverPanel.HideGameOverPanel();
            pausePanel.button_pause.gameObject.SetActive(true);
            gameOverPanel.animator_continue.SetTrigger("slideout");
            uiManager.animator_control.SetTrigger("slidein");
            uiManager.InitHpUI(champion.maxHp, champion.startingHp, false);
            // cameraController.SetInitialRotation(continueNode);

            Quaternion     targetRotation        = Quaternion.identity;
            BlockComponent currentBlockComponent = pathManager.GetBlockComponentByOrigin(continueNode);

            if (currentBlockComponent.sectionComponent.sectionData.direction == Direction.right)
            {
                if (currentBlockComponent.sectionComponent.beforeSectionComponent == null)
                {
                    if (currentBlockComponent.sectionComponent.nextSectionComponent.nextSectionComponent.sectionData.direction == Direction.up)
                    {
                        targetRotation = Quaternion.Euler(cameraController.championRightUpAngle);
                    }
                    else if (currentBlockComponent.sectionComponent.nextSectionComponent.nextSectionComponent.sectionData.direction == Direction.down)
                    {
                        targetRotation = Quaternion.Euler(cameraController.championRightDownAngle);
                    }
                }
                else if (currentBlockComponent.sectionComponent.beforeSectionComponent.beforeSectionComponent == null)
                {
                    if (currentBlockComponent.sectionComponent.nextSectionComponent.nextSectionComponent.sectionData.direction == Direction.up)
                    {
                        targetRotation = Quaternion.Euler(cameraController.championRightUpAngle);
                    }
                    else if (currentBlockComponent.sectionComponent.nextSectionComponent.nextSectionComponent.sectionData.direction == Direction.down)
                    {
                        targetRotation = Quaternion.Euler(cameraController.championRightDownAngle);
                    }
                }
                else if (currentBlockComponent.sectionComponent.beforeSectionComponent.beforeSectionComponent.sectionData.direction == Direction.down)
                {
                    targetRotation = Quaternion.Euler(cameraController.championRightDownAngle);
                }
                else if (currentBlockComponent.sectionComponent.beforeSectionComponent.beforeSectionComponent.sectionData.direction == Direction.up)
                {
                    targetRotation = Quaternion.Euler(cameraController.championRightUpAngle);
                }
            }
            else if (currentBlockComponent.sectionComponent.sectionData.direction == Direction.up)
            {
                targetRotation = Quaternion.Euler(cameraController.championUpAngle);
            }
            else if (currentBlockComponent.sectionComponent.sectionData.direction == Direction.down)
            {
                targetRotation = Quaternion.Euler(cameraController.championDownAngle);
            }
            cameraController.AnimatePivotAngle(targetRotation, 0.3f);
        }
Example #9
0
        public void InitSectionComponent(SectionModel sectionData, SectionModel nextSectionData, SectionComponent lastSectionComponent, bool isLastSection = false)
        {
            // Debug.Log("SectionComponent.InitSectionComponent(" + sectionData.sectionId.ToString() + ")");
            isCollapsing = false;
            blockComponents.Clear();
            this.sectionData = sectionData;
            SetSectionPosition(this.sectionData.origin);

            // Debug.Log("pm.pathManager.sectionList.Count: " + pm.pathManager.sectionList.Count.ToString());
            // if (lastSectionComponent != null) { Debug.Log("lastSectionComponent: " + lastSectionComponent); }
            // else { Debug.Log("lastSectionComponent is null"); }

            int baseProgress = lastSectionComponent != null ? lastSectionComponent.maxProgress : 0;

            minProgress = baseProgress;
            int _maxProgress = -1;

            // Debug.Log("sectionData.height: " + sectionData.height.ToString());
            // Debug.Log("sectionData.width: " + sectionData.width.ToString());
            for (int i = 0; i < this.sectionData.height; i++)
            {
                for (int j = 0; j < this.sectionData.width; j++)
                {
                    TerrainGid terrainGid = TerrainGid.empty;
                    if (sectionData.terrains != null)
                    {
                        terrainGid = (TerrainGid)sectionData.terrains[i, j];
                    }
                    else
                    {
                        //terrain정보가 들어오지 않는 경우는 코너섹션일 때
                        terrainGid = TerrainGid.basic_dirt;
                    }
                    if (terrainGid == TerrainGid.empty)
                    {
                        continue;
                    }

                    GameObject blockPrefab     = PrefabManager.Instance.GetBlockPrefab(terrainGid);
                    GameObject blockGameObject = Instantiate(blockPrefab) as GameObject;
                    // GameObject blockGameObject = ObjectPool.Spawn(blockPrefab);

                    blockGameObject.name = "block#" + pm.pathManager.lastBlockComponentId.ToString();
                    blockGameObject.transform.SetParent(blockContainer);
                    BlockComponent blockComponent = blockGameObject.GetComponent <BlockComponent>();
                    BlockCategory  blockCategory  = this.sectionData.sectionType == SectionType.corner ? BlockCategory.corner : BlockCategory.straight;
                    if (this.sectionData.sectionType == SectionType.corner)
                    {
                        SectionComponent _beforeSectionComponent = pm.pathManager.GetSectionComponent(this.sectionData.sectionId - 1);
                        // SectionComponent _beforeBeforeSectionComponent = pm.pathManager.GetSectionComponent(this.sectionData.sectionId - 2);
                        if (_beforeSectionComponent == null) //first corner section
                        {
                            blockCategory = BlockCategory.corner;
                        }
                        else if (this.sectionData.direction == Direction.up || (this.sectionData.direction == Direction.right && (_beforeSectionComponent.sectionData.direction == Direction.up)))
                        {
                            if (i + j >= 2 && !(i == 2 && j == 2))
                            {
                                blockCategory = BlockCategory.turn;
                            }
                            else
                            {
                                blockCategory = BlockCategory.corner;
                            }
                        }
                        else if (this.sectionData.direction == Direction.down || (this.sectionData.direction == Direction.right && (_beforeSectionComponent.sectionData.direction == Direction.down)))
                        {
                            if (j >= i && !(i == 0 && j == 2))
                            {
                                blockCategory = BlockCategory.turn;
                            }
                            else
                            {
                                blockCategory = BlockCategory.corner;
                            }
                        }

                        if (isLastSection)
                        {
                            blockCategory = BlockCategory.straight;
                        }
                    }
                    else if (this.sectionData.sectionType == SectionType.straight)
                    {
                        if (this.sectionData.direction == Direction.up)
                        {
                            if (j == this.sectionData.width - 1 && i == this.sectionData.height - 1)
                            {
                                blockCategory = BlockCategory.shortcut_start;
                            }
                            else if (j == 0 && i == 0)
                            {
                                blockCategory = BlockCategory.shortcut_end;
                            }
                            else
                            {
                                blockCategory = BlockCategory.straight;
                            }
                        }
                        else if (this.sectionData.direction == Direction.down)
                        {
                            if (j == this.sectionData.width - 1 && i == 0)
                            {
                                blockCategory = BlockCategory.shortcut_start;
                            }
                            else if (j == 0 && i == this.sectionData.height - 1)
                            {
                                blockCategory = BlockCategory.shortcut_end;
                            }
                            else
                            {
                                blockCategory = BlockCategory.straight;
                            }
                        }
                        else if (this.sectionData.direction == Direction.right)
                        {
                            SectionComponent _beforeSectionComponent       = pm.pathManager.GetSectionComponent(this.sectionData.sectionId - 1);
                            SectionComponent _beforeBeforeSectionComponent = pm.pathManager.GetSectionComponent(this.sectionData.sectionId - 2);
                            if ((nextSectionData.direction == Direction.up) && (j == this.sectionData.width - 1 && i == this.sectionData.height - 1))
                            {
                                blockCategory = BlockCategory.shortcut_start;
                            }
                            else if ((nextSectionData.direction == Direction.down) && (j == this.sectionData.width - 1 && i == 0))
                            {
                                blockCategory = BlockCategory.shortcut_start;
                            }
                            else if (_beforeBeforeSectionComponent != null)
                            {
                                if (_beforeBeforeSectionComponent.sectionData.direction == Direction.up && (j == 0 && i == 0))
                                {
                                    blockCategory = BlockCategory.shortcut_end;
                                }
                                else if (_beforeBeforeSectionComponent.sectionData.direction == Direction.down && (j == 0 && i == this.sectionData.height - 1))
                                {
                                    blockCategory = BlockCategory.shortcut_end;
                                }
                                else
                                {
                                    blockCategory = BlockCategory.straight;
                                }
                            }
                            else
                            {
                                blockCategory = BlockCategory.straight;
                            }
                        }
                        //다음 코너에서 방향이 어떨게 되냐에따라 현재 스트레이트 섹션의 숏컷이 결정된다

                        /*
                         *
                         * if ((this.sectionData.direction == Direction.right && nextSectionData.direction == Direction.up) ||
                         * (this.sectionData.direction == Direction.up && nextSectionData.direction == Direction.right))
                         * {
                         *  if (j == this.sectionData.width - 1 && i == this.sectionData.height - 1)
                         *  {
                         *      blockCategory = BlockCategory.shortcut_start;
                         *  }
                         *  else if (this.sectionData.direction == Direction.right && j == this.sectionData.width - 1)
                         *  {
                         *      blockCategory = BlockCategory.straight_edge;
                         *  }
                         *  else if (this.sectionData.direction == Direction.up && i == this.sectionData.height - 1)
                         *  {
                         *      blockCategory = BlockCategory.straight_edge;
                         *  }
                         *  else if (j == 0 && i == 0)
                         *  {
                         *      Debug.Log("???");
                         *      blockCategory = BlockCategory.shortcut_end;
                         *  }
                         *  else
                         *  {
                         *      blockCategory = BlockCategory.straight;
                         *  }
                         * }
                         * else
                         * {
                         *  if (j == this.sectionData.width - 1 && i == 0)
                         *  {
                         *      blockCategory = BlockCategory.shortcut_start;
                         *  }
                         *  else if (this.sectionData.direction == Direction.right && j == this.sectionData.width - 1)
                         *  {
                         *      blockCategory = BlockCategory.straight_edge;
                         *  }
                         *  else if (this.sectionData.direction == Direction.down && i == 0)
                         *  {
                         *      blockCategory = BlockCategory.straight_edge;
                         *  }
                         *  else if (j == 0 && i == this.sectionData.height - 1)
                         *  {
                         *      Debug.Log("!!!");
                         *      blockCategory = BlockCategory.shortcut_end;
                         *  }
                         *  else
                         *  {
                         *      blockCategory = BlockCategory.straight;
                         *  }
                         * }
                         */
                    }
                    int progress = 0;

                    if (sectionData.sectionType == SectionType.straight)
                    {
                        if (sectionData.direction == Direction.right)
                        {
                            progress = baseProgress + j + 1;
                        }
                        else if (sectionData.direction == Direction.up)
                        {
                            progress = baseProgress + i + 1;
                        }
                        else if (sectionData.direction == Direction.down)
                        {
                            progress = baseProgress + (this.sectionData.height - i);
                        }
                    }
                    else if (sectionData.sectionType == SectionType.corner)
                    {
                        progress = baseProgress + 1;
                    }

                    if (progress > _maxProgress)
                    {
                        _maxProgress = progress;
                    }

                    BlockModel blockData = new BlockModel(
                        pm.pathManager.lastBlockComponentId++,
                        blockCategory,
                        this.sectionData.direction,
                        this.sectionData.origin + new Node(j, i),
                        progress);

                    blockComponent.InitBlockComponent(this, blockData);
                    blockComponents.Add(blockComponent);
                    pm.pathManager.PutBlockComponent(blockComponent);
                }
            }

            if (sectionData.objects != null)
            {
                // Debug.Log("---------");
                // Debug.Log(sectionData.objects.Count);
                // Debug.Log("sectionData.direction: " + sectionData.direction);
                // Debug.Log("sectionData.width: " + sectionData.width.ToString());
                // Debug.Log("sectionData.height: " + sectionData.height.ToString());
                foreach (KeyValuePair <Node, TiledObject> kv in sectionData.objects)
                {
                    Node node = kv.Key;
                    // Debug.Log("node: " + node.ToString());
                    TiledObject tiledObject = kv.Value;
                    int         objectGid   = tiledObject.gid;

                    BlockComponent blockComponent = pm.pathManager.GetBlockComponentByOrigin(this.sectionData.origin + node);
                    if (blockComponent == null)
                    {
                        Debug.Log("blockComponent is null");
                        continue;
                    }

                    if (17 <= objectGid && objectGid < 33) //item
                    {
                        Node       itemOrigin = this.sectionData.origin + node;
                        GameObject itemPrefab = PrefabManager.Instance.GetItemPrefab((ItemGid)objectGid);
                        // GameObject itemInstance = Instantiate(itemPrefab) as GameObject;
                        GameObject itemInstance = ObjectPool.Spawn(itemPrefab);
                        itemInstance.transform.SetParent(blockComponent.objectContainer);
                        ItemComponent itemComponent = itemInstance.GetComponent <ItemComponent>();
                        itemComponent.InitItemComponent(this, itemOrigin, blockComponent.blockData.direction);
                        itemComponents.Add(itemComponent);
                        pm.pathManager.PutItemComponent(itemComponent);
                        if (itemComponent.itemType == ItemType.food)
                        {
                            FoodItemComponent foodItemComponent = itemComponent.GetComponent <FoodItemComponent>();
                            foodItemComponent.InitFoodRender();
                        }
                    }
                    else if (33 <= objectGid && objectGid < 49) //trap
                    {
                        Node       trapOrigin = this.sectionData.origin + node;
                        GameObject trapPrefab = PrefabManager.Instance.GetTrapPrefab((TrapGid)objectGid);
                        // GameObject trapInstance = Instantiate(trapPrefab) as GameObject;
                        GameObject trapInstance = ObjectPool.Spawn(trapPrefab);
                        trapInstance.transform.SetParent(blockComponent.objectContainer);
                        TrapComponent trapComponent = trapInstance.GetComponent <TrapComponent>();
                        trapComponent.name = trapComponent.GetInstanceID().ToString();
                        Direction trapDirection = blockComponent.blockData.direction;
                        if (tiledObject.properties != null)
                        {
                            //TODO TileProperty의 direction을 그대로 사용하는것이 아니라
                            //섹션의 방향에 따라 수정된 direction을 사용해야 한다
                            if (sectionData.direction == Direction.right)
                            {
                                trapDirection = tiledObject.properties.direction;
                            }
                            else if (sectionData.direction == Direction.up)
                            {
                                if (tiledObject.properties.direction == Direction.up)
                                {
                                    trapDirection = Direction.left;
                                }
                                else if (tiledObject.properties.direction == Direction.right)
                                {
                                    trapDirection = Direction.up;
                                }
                                else if (tiledObject.properties.direction == Direction.down)
                                {
                                    trapDirection = Direction.right;
                                }
                                else if (tiledObject.properties.direction == Direction.left)
                                {
                                    trapDirection = Direction.down;
                                }
                            }
                            else if (sectionData.direction == Direction.down)
                            {
                                if (tiledObject.properties.direction == Direction.up)
                                {
                                    trapDirection = Direction.right;
                                }
                                else if (tiledObject.properties.direction == Direction.right)
                                {
                                    trapDirection = Direction.down;
                                }
                                else if (tiledObject.properties.direction == Direction.down)
                                {
                                    trapDirection = Direction.left;
                                }
                                else if (tiledObject.properties.direction == Direction.left)
                                {
                                    trapDirection = Direction.up;
                                }
                            }
                        }
                        trapComponent.InitTrapComponent(this, trapOrigin, trapDirection, tiledObject);
                        trapComponents.Add(trapComponent);
                        pm.pathManager.PutTrapComponent(trapComponent);
                    }
                    else if (49 <= objectGid && objectGid < 65) //enemy
                    {
                        Node       itemOrigin  = this.sectionData.origin + node;
                        GameObject enemyPrefab = PrefabManager.Instance.GetEnemyPrefab((EnemyGid)objectGid);
                        // GameObject enemyInstance = Instantiate(enemyPrefab) as GameObject;
                        GameObject enemyInstance = ObjectPool.Spawn(enemyPrefab);
                        enemyInstance.transform.SetParent(blockComponent.objectContainer);
                        EnemyComponent enemyComponent = enemyInstance.GetComponent <EnemyComponent>();
                        enemyComponent.InitEnemyComponent(itemOrigin, blockComponent.blockData.direction);
                        enemyComponents.Add(enemyComponent);
                        pm.pathManager.PutEnemyComponent(enemyComponent);
                    }
                }
            }

            this.maxProgress = _maxProgress;
        }
Example #10
0
        public void AddSection(PlayMode playMode)
        {
            SectionContent sectionContent        = null;
            int            unitLength            = -1;
            int            straightSectionLength = -1;

            if (playMode == PlayMode.infinity)
            {
                unitLength            = Random.Range(2, 6);
                straightSectionLength = unitLength * 3; //6, 9, 12, 15
                sectionContent        = MapManager.Instance.GetSectionContentByUnitLength(unitLength);
            }
            else if (playMode == PlayMode.campaign)
            {
                sectionContent = MapManager.Instance.GetSectionContentBySectionIndex(sectionIndex++);
                if (sectionContent == null)
                {
                    // Debug.Log("sectionContent is null, sectionIndex : " + sectionIndex.ToString());
                    return;
                }
                unitLength            = sectionContent.unitLength;
                straightSectionLength = unitLength * 3;
            }

            Node straightSectionOrigin = lastSectionComponent.sectionData.origin;
            int  straightSectionWidth  = 0;
            int  straightSectionHeight = 0;

            if (lastSectionComponent.sectionData.direction == Direction.up)
            {
                straightSectionOrigin += new Node(0, pathWidth);
                straightSectionWidth   = pathWidth;
                straightSectionHeight  = straightSectionLength;
            }
            else if (lastSectionComponent.sectionData.direction == Direction.right)
            {
                straightSectionOrigin += new Node(pathWidth, 0);
                straightSectionWidth   = straightSectionLength;
                straightSectionHeight  = pathWidth;
            }
            else if (lastSectionComponent.sectionData.direction == Direction.down)
            {
                straightSectionOrigin += new Node(0, -straightSectionLength);
                straightSectionWidth   = pathWidth;
                straightSectionHeight  = straightSectionLength;
            }
            int[,] terrains = new int[straightSectionHeight, straightSectionWidth];
            Dictionary <Node, TiledObject> objects = new Dictionary <Node, TiledObject>();

            if (lastSectionComponent.sectionData.direction == Direction.right)
            {
                terrains = sectionContent.terrains;

                foreach (KeyValuePair <Node, TiledObject> kv in sectionContent.objects)
                {
                    Node node = new Node(kv.Key.y, kv.Key.x);
                    objects.Add(node, kv.Value);
                }
            }
            else if (lastSectionComponent.sectionData.direction == Direction.up)
            {
                for (int i = 0; i < sectionContent.terrains.GetLength(0); i++)
                {
                    for (int j = 0; j < sectionContent.terrains.GetLength(1); j++)
                    {
                        terrains[j, sectionContent.terrains.GetLength(0) - 1 - i] = sectionContent.terrains[i, j];
                    }
                }

                foreach (KeyValuePair <Node, TiledObject> kv in sectionContent.objects)
                {
                    Node node = new Node(sectionContent.terrains.GetLength(0) - 1 - kv.Key.x, kv.Key.y);
                    objects.Add(node, kv.Value);
                }
            }
            else if (lastSectionComponent.sectionData.direction == Direction.down)
            {
                for (int i = 0; i < sectionContent.terrains.GetLength(0); i++)
                {
                    for (int j = 0; j < sectionContent.terrains.GetLength(1); j++)
                    {
                        terrains[sectionContent.terrains.GetLength(1) - 1 - j, i] = sectionContent.terrains[i, j];
                    }
                }

                foreach (KeyValuePair <Node, TiledObject> kv in sectionContent.objects)
                {
                    objects.Add(new Node(kv.Key.x, sectionContent.terrains.GetLength(1) - 1 - kv.Key.y), kv.Value);
                }
            }

            SectionModel addStraightSection = new SectionModel(
                lastSectionComponent.sectionData.sectionId + 1,
                SectionType.straight,
                lastSectionComponent.sectionData.direction,
                straightSectionOrigin,
                straightSectionWidth, straightSectionHeight,
                terrains,
                objects);


            Direction cornerSectionDirection = Direction.none;
            Node      cornerSectionOrigin    = addStraightSection.origin;

            if (addStraightSection.direction == Direction.up)
            {
                cornerSectionDirection = Direction.right;
                cornerSectionOrigin   += new Node(0, addStraightSection.height);
            }
            else if (addStraightSection.direction == Direction.right)
            {
                cornerSectionDirection = Random.Range(0, 100) < 50 ? Direction.up : Direction.down;
                cornerSectionOrigin   += new Node(addStraightSection.width, 0);
            }
            else if (addStraightSection.direction == Direction.down)
            {
                cornerSectionDirection = Direction.right;
                cornerSectionOrigin   += new Node(0, -pathWidth);
            }
            SectionContent cornerSectionContent = null;

            if (playMode == PlayMode.campaign && sectionIndex == MapManager.Instance.campaignSectionContent.Count)
            {
                cornerSectionContent = MapManager.Instance.finishSectionContent;
            }
            else if (cornerSectionDirection == Direction.up)
            {
                cornerSectionContent = MapManager.Instance.decreaseCornerSectionContent;
            }
            else if (cornerSectionDirection == Direction.down)
            {
                cornerSectionContent = MapManager.Instance.increaseCornerSectionContent;
            }
            else if (cornerSectionDirection == Direction.right)
            {
                if (addStraightSection.direction == Direction.up)
                {
                    cornerSectionContent = MapManager.Instance.decreaseCornerSectionContent;
                }
                else if (addStraightSection.direction == Direction.down)
                {
                    cornerSectionContent = MapManager.Instance.increaseCornerSectionContent;
                }
            }

            bool         isLastSection    = playMode == PlayMode.campaign && sectionIndex == MapManager.Instance.campaignSectionContent.Count;
            SectionModel addCornerSection = new SectionModel(
                addStraightSection.sectionId + 1,
                SectionType.corner,
                isLastSection ? addStraightSection.direction : cornerSectionDirection,
                cornerSectionOrigin,
                pathWidth, pathWidth, cornerSectionContent.terrains);

            SectionComponent straightSectionComponent = MakeSection(addStraightSection, addCornerSection);

            lastSectionComponent.nextSectionComponent       = straightSectionComponent;
            straightSectionComponent.beforeSectionComponent = lastSectionComponent;
            PutSectionComponent(straightSectionComponent);
            SectionComponent cornerSectionComponent = MakeSection(addCornerSection, null, isLastSection);

            straightSectionComponent.nextSectionComponent = cornerSectionComponent;
            cornerSectionComponent.beforeSectionComponent = straightSectionComponent;
            PutSectionComponent(cornerSectionComponent);

            if (sectionList.Count > maxMaintainSectionCount)
            {
                SectionComponent firstStraightSection = sectionList[0];
                SectionComponent firstCornerSection   = sectionList[1];
                RemoveSectionComponent(firstStraightSection);
                RemoveSectionComponent(firstCornerSection);
                firstStraightSection.RemoveSection();
                firstCornerSection.RemoveSection();
            }
        }
Example #11
0
 public void RemoveSectionComponent(SectionComponent sectionComponent)
 {
     sectionList.Remove(sectionComponent);
     sectionDictionary.Remove(sectionComponent.sectionData.sectionId);
 }