示例#1
0
        IEnumerator MoveChampionHelper(Node beforeNode, Node afterNode, float moveDuration, bool isRotate)
        {
            BlockComponent currentBlockComponent = pm.pathManager.GetBlockComponentByOrigin(beforeNode);
            BlockComponent afterBlockComponent   = pm.pathManager.GetBlockComponentByOrigin(afterNode);

            origin   = afterNode;
            isMoving = true;
            Vector3 initialPosition = new Vector3(beforeNode.x + 0.5f, 0, beforeNode.y + 0.5f);
            Vector3 targetPosition  = new Vector3(afterNode.x + 0.5f, 0, afterNode.y + 0.5f);

            if (currentBlockComponent.terrainGid == TerrainGid.water)
            {
                initialPosition += new Vector3(0, -0.083333f * 2, 0);
            }
            if (afterBlockComponent != null && afterBlockComponent.terrainGid == TerrainGid.water)
            {
                targetPosition += new Vector3(0, -0.083333f * 2, 0);
            }
            float percent = 0;

            while (percent <= 1)
            {
                percent           += Time.deltaTime * (1.0f / moveDuration);
                transform.position = Vector3.Lerp(initialPosition, targetPosition, percent);
                yield return(null);
            }

            isMoving = false;
            OnMoveComplete(beforeNode, isRotate);
            //if need callback here
        }
示例#2
0
 public void RemoveBlockComponent(BlockComponent blockComponent)
 {
     blockDictionary.Remove(blockComponent.blockData.blockId);
     if (blockDictionaryByOrigin.ContainsKey(blockComponent.blockData.origin.x))
     {
         blockDictionaryByOrigin[blockComponent.blockData.origin.x].Remove(blockComponent.blockData.origin.y);
     }
 }
示例#3
0
        IEnumerator AttackHelper(Node championNode, Node enemyNode, float attackDuration)
        {
            isAttacking = true;
            Vector3 initialPosition = new Vector3(championNode.x + 0.5f, 0, championNode.y + 0.5f);
            Vector3 targetPosition  = new Vector3(enemyNode.x + 0.5f, 0, enemyNode.y + 0.5f);
            float   percent         = 0;

            while (percent <= 1)
            {
                percent           += Time.deltaTime * (1.0f / attackDuration);
                transform.position = Vector3.Lerp(initialPosition, targetPosition, percent);
                yield return(null);
            }
            EnemyComponent enemyComponent = pm.pathManager.GetEnemyComponent(enemyNode);

            if (enemyComponent.TakeDamage(this, attack))
            {
                animator.SetTrigger("jump");
                percent = 0;
                while (percent <= 1)
                {
                    percent           += Time.deltaTime * (1.0f / attackDuration);
                    transform.position = Vector3.Lerp(targetPosition, initialPosition, percent);
                    yield return(null);
                }
            }
            else
            {
                pm.AddKill(1);
                origin = enemyNode;


                BlockComponent currentBlockComponent = pm.pathManager.GetBlockComponentByOrigin(origin);

                pm.pathManager.RemoveEnemyComponent(enemyComponent);
                currentBlockComponent.sectionComponent.enemyComponents.Remove(enemyComponent);
                Destroy(enemyComponent.gameObject);

                // CameraWork(currentBlockComponent);
            }

            isAttacking = false;
        }
示例#4
0
 public void PutBlockComponent(BlockComponent blockComponent)
 {
     if (blockDictionary.ContainsKey(blockComponent.blockData.blockId))
     {
         Debug.Log("blockDictionary already have key: " + blockComponent.blockData.blockId.ToString());
         return;
     }
     blockDictionary.Add(blockComponent.blockData.blockId, blockComponent);
     if (!blockDictionaryByOrigin.ContainsKey(blockComponent.blockData.origin.x))
     {
         blockDictionaryByOrigin.Add(blockComponent.blockData.origin.x, new Dictionary <int, BlockComponent>());
     }
     if (!blockDictionaryByOrigin[blockComponent.blockData.origin.x].ContainsKey(blockComponent.blockData.origin.y))
     {
         blockDictionaryByOrigin[blockComponent.blockData.origin.x].Add(blockComponent.blockData.origin.y, blockComponent);
     }
     else
     {
         Debug.Log("blockDictionaryByOrigin already have key: " + blockComponent.blockData.origin.ToString());
     }
 }
示例#5
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);
        }
示例#6
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);
        }
示例#7
0
        //TODO:특수스킬이나 아이템 사용과 같은 입력이 들어올 수 있으
        public void PlayerAction(PlayerInput input)
        {
            // if (!isHpDecreasing)
            // {
            //     isHpDecreasing = true;
            //     hpDecreasingCoroutine = StartCoroutine(DecreasingPlayerHp());
            // }
            if (isClear)
            {
                return;
            }

            if (playSceneState == PlaySceneState.main ||
                playSceneState == PlaySceneState.gameover ||
                playSceneState == PlaySceneState.pause)
            {
                return;
            }
            if (playSceneState == PlaySceneState.ready)
            {
                playSceneState = PlaySceneState.play;
            }
            if (!isSpIncreasing)
            {
                isSpIncreasing        = true;
                spIncreasingCoroutine = StartCoroutine(IncreasingPlayerSp());
            }

            //플레이어의 방향과 서있는 블럭의 타잎에 따라 다음에 가야할 노드와 회전유무가 정해진다.
            if (input == PlayerInput.left || input == PlayerInput.right || input == PlayerInput.forward)
            {
                if (champion.isDead)
                {
                    // Debug.Log("player is dead");
                    return;
                }
                if (champion.isMoving)
                {
                    Debug.Log("champion is moving. so skip action");
                    return;
                }
                if (champion.isAttacking)
                {
                    return;
                }

                Node           targetNode         = champion.origin;
                Node           nextNode           = GetNextNode(champion, input);
                BlockComponent blockComponent     = pathManager.GetBlockComponentByOrigin(champion.origin);
                BlockComponent nextBlockComponent = pathManager.GetBlockComponentByOrigin(nextNode); //null 일 수도있다
                Direction      targetDirection    = champion.direction;

                if (champion.isWatered)
                {
                    champion.isWatered = false;
                    champion.MoveChampion(champion.origin, champion.origin, GameManager.championMoveDuration, MoveType.walk, false);
                    return;
                }
                else if (champion.isBitten)
                {
                    champion.isBitten = false;
                    champion.MoveChampion(champion.origin, champion.origin, GameManager.championMoveDuration, MoveType.walk, false);
                    return;
                }


                //스트레이트 블럭 위에 있고 입력받은곳에 적이 있는지 확인해야한다
                //공격후 적이 죽는다면 적이 있던 자리로 이동하고 적이 죽지 않으면 원래 있던 자리로 돌아와야 한다
                // Debug.Log("player.origin: " + player.origin.ToString());
                TrapComponent trapComponent = pathManager.GetTrapComponent(nextNode);
                if (trapComponent != null && trapComponent.isObstacle)
                {
                    champion.MoveChampion(champion.origin, champion.origin, GameManager.championMoveDuration, MoveType.walk, false);
                    return;
                }

                if (IsEnemyInDirection(nextNode))
                {
                    champion.Attack(champion.origin, nextNode, GameManager.championMoveDuration);
                    return;
                }
                else
                {
                    targetDirection = champion.direction;
                    if (champion.direction == Direction.right)
                    {
                        if (input == PlayerInput.left)
                        {
                            targetNode += new Node(1, 1);
                        }
                        else if (input == PlayerInput.right)
                        {
                            targetNode += new Node(1, -1);
                        }
                        else if (input == PlayerInput.forward)
                        {
                            targetNode += new Node(1, 0);
                        }
                    }
                    else if (champion.direction == Direction.up)
                    {
                        if (input == PlayerInput.left)
                        {
                            targetNode += new Node(-1, 1);
                        }
                        else if (input == PlayerInput.right)
                        {
                            targetNode += new Node(1, 1);
                        }
                        else if (input == PlayerInput.forward)
                        {
                            targetNode += new Node(0, 1);
                        }
                    }
                    else if (champion.direction == Direction.down)
                    {
                        if (input == PlayerInput.left)
                        {
                            targetNode += new Node(1, -1);
                        }
                        else if (input == PlayerInput.right)
                        {
                            targetNode += new Node(-1, -1);
                        }
                        else if (input == PlayerInput.forward)
                        {
                            targetNode += new Node(0, -1);
                        }
                    }
                    if (nextBlockComponent != null && (nextBlockComponent.blockData.blockCategory == BlockCategory.turn || nextBlockComponent.blockData.blockCategory == BlockCategory.shortcut_end))
                    {
                        targetDirection = nextBlockComponent.blockData.direction;
                    }
                }

                bool isRotate = champion.direction != targetDirection;
                champion.MoveChampion(champion.origin, targetNode, GameManager.championMoveDuration, MoveType.walk
                                      , isRotate);
                if (isRotate)
                {
                    champion.RotateChampion(champion.direction, targetDirection, GameManager.championMoveDuration);
                }
            }
            else
            {
                //이동이외의 입력이 들어온다면 여기서 구현해야 한다
            }
        }
示例#8
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;
        }
示例#9
0
        void CameraWork(BlockComponent currentBlockComponent)
        {
            // Debug.Log("ChampionComponent.CameraWork()");
            int        currentProgress      = currentBlockComponent.blockData.progress;
            int        minProgressInSection = currentBlockComponent.sectionComponent.minProgress;
            int        maxProgressInSection = currentBlockComponent.sectionComponent.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 (currentBlockComponent.sectionComponent.sectionData.direction == Direction.right)
            {
                if (currentBlockComponent.sectionComponent.beforeSectionComponent == null)
                {
                    if (currentBlockComponent.sectionComponent.nextSectionComponent.nextSectionComponent.sectionData.direction == Direction.up)
                    {
                        initialRotation = Quaternion.Euler(pm.cameraController.championRightUpAngle);
                    }
                    else if (currentBlockComponent.sectionComponent.nextSectionComponent.nextSectionComponent.sectionData.direction == Direction.down)
                    {
                        initialRotation = Quaternion.Euler(pm.cameraController.championRightDownAngle);
                    }
                }
                else if (currentBlockComponent.sectionComponent.beforeSectionComponent.beforeSectionComponent == null)
                {
                    if (currentBlockComponent.sectionComponent.nextSectionComponent.nextSectionComponent.sectionData.direction == Direction.up)
                    {
                        initialRotation = Quaternion.Euler(pm.cameraController.championRightUpAngle);
                    }
                    else if (currentBlockComponent.sectionComponent.nextSectionComponent.nextSectionComponent.sectionData.direction == Direction.down)
                    {
                        initialRotation = Quaternion.Euler(pm.cameraController.championRightDownAngle);
                    }
                }
                else if (currentBlockComponent.sectionComponent.beforeSectionComponent.beforeSectionComponent.sectionData.direction == Direction.down)
                {
                    initialRotation = Quaternion.Euler(pm.cameraController.championRightDownAngle);
                }
                else if (currentBlockComponent.sectionComponent.beforeSectionComponent.beforeSectionComponent.sectionData.direction == Direction.up)
                {
                    initialRotation = Quaternion.Euler(pm.cameraController.championRightUpAngle);
                }

                if (currentBlockComponent.sectionComponent.nextSectionComponent.nextSectionComponent.sectionData.direction == Direction.up)
                {
                    targetRotation = Quaternion.Euler(pm.cameraController.championUpAngle);
                }
                else if (currentBlockComponent.sectionComponent.nextSectionComponent.nextSectionComponent.sectionData.direction == Direction.down)
                {
                    targetRotation = Quaternion.Euler(pm.cameraController.championDownAngle);
                }
            }
            else if (currentBlockComponent.sectionComponent.sectionData.direction == Direction.up)
            {
                initialRotation = Quaternion.Euler(pm.cameraController.championUpAngle);
                targetRotation  = Quaternion.Euler(pm.cameraController.championRightUpAngle);
            }
            else if (currentBlockComponent.sectionComponent.sectionData.direction == Direction.down)
            {
                initialRotation = Quaternion.Euler(pm.cameraController.championDownAngle);
                targetRotation  = Quaternion.Euler(pm.cameraController.championRightDownAngle);
            }

            pm.cameraController.AnimatePivotAngle(initialRotation, targetRotation, startPercent, endPercent, 0.3f);
        }
示例#10
0
        void OnMoveComplete(Node beforeNode, bool isRotate)
        {
            // Debug.Log("ChampionComponent.OnMoveComplete()");
            isSliping = false;
            animator.SetBool("isCrouch", false);
            int            addScore              = 0;
            BlockComponent beforeBlockComponent  = pm.pathManager.GetBlockComponentByOrigin(beforeNode);
            BlockComponent currentBlockComponent = pm.pathManager.GetBlockComponentByOrigin(this.origin);

            if (currentBlockComponent == null)
            {
                //there is no block blow player
                TakeDamage(currentHp, DamageType.drop);
            }
            else
            {
                if ((beforeBlockComponent.sectionComponent != currentBlockComponent.sectionComponent))
                {
                    pm.pathManager.currentSectionComponent = currentBlockComponent.sectionComponent;
                }


                if ((beforeBlockComponent.sectionComponent != currentBlockComponent.sectionComponent) &&
                    (currentBlockComponent.sectionComponent.sectionData.sectionType == SectionType.straight) &&
                    (currentBlockComponent.blockData.progress > progress))
                {
                    //time to generate more section
                    pm.pathManager.AddSection(pm.playMode);
                }

                ItemComponent itemComponent = pm.pathManager.GetItemComponent(this.origin);
                if (itemComponent != null)
                {
                    if (!gotItem)
                    {
                        gotItem = true;
                    }
                    pm.AddCombo();

                    if (!string.IsNullOrEmpty(itemComponent.sfx))
                    {
                        SoundManager.Instance.Play(itemComponent.sfx);
                    }
                    //eat item and destroy
                    if (itemComponent.itemType == ItemType.hp)
                    {
                        AddHp((int)itemComponent.value);
                        pm.uiManager.UpdateHpUI(true);
                        addScore += 2;
                        pm.score += 2;
                    }
                    else if (itemComponent.itemType == ItemType.sp)
                    {
                        AddSp(itemComponent.value);
                        pm.uiManager.UpdateSp();
                        addScore += 2;
                        pm.score += 2;
                    }
                    else if (itemComponent.itemType == ItemType.coin)
                    {
                        pm.totalCoin += (int)itemComponent.value;
                        pm.addCoin   += (int)itemComponent.value;
                        GameManager.Instance.SetPlayerCoinToPref(pm.totalCoin);
                        pm.uiManager.UpdateCoin(true);
                        addScore += 1;
                        pm.score += 1;
                    }
                    else if (itemComponent.itemType == ItemType.heart)
                    {
                        int addHp = (int)itemComponent.value;
                        pm.champion.maxHp     += addHp;
                        pm.champion.maxHp      = Mathf.Clamp(pm.champion.maxHp, 1, 14);
                        pm.champion.currentHp += addHp;
                        pm.champion.currentHp  = Mathf.Clamp(pm.champion.currentHp, 1, 14);
                        pm.uiManager.InitHpUI(pm.champion.maxHp, pm.champion.currentHp, true);
                        addScore += 5;
                        pm.score += 5;
                    }

                    pm.pathManager.RemoveItemComponent(itemComponent);
                    currentBlockComponent.sectionComponent.itemComponents.Remove(itemComponent);
                    // Destroy(itemComponent.gameObject);

                    ObjectPool.Recycle(itemComponent);
                }
                else
                {
                    pm.ResetCombo();
                    gotItem = false;
                }

                if (beforeBlockComponent != currentBlockComponent && currentBlockComponent.terrainGid == TerrainGid.water)
                {
                    isWatered = true;
                }

                if (currentBlockComponent.hasStepEffect)
                {
                    currentBlockComponent.MakeStepEffect();
                }

                if (currentBlockComponent.terrainGid == TerrainGid.cracked)
                {
                    currentBlockComponent.StartCollapse(1.5f, 1.5f, true);
                }
                else if (currentBlockComponent.terrainGid == TerrainGid.magma)
                {
                    MagmaComponent magmaComponent = currentBlockComponent.GetComponentInChildren <MagmaComponent>();
                    if (magmaComponent.isHot)
                    {
                        TakeDamage(magmaComponent.attack, DamageType.magma);
                    }
                }
                else if (currentBlockComponent.terrainGid == TerrainGid.ice)
                {
                    //한칸 앞으로 미끄러져 이동해야한다
                    Node targetNode = origin;
                    if (currentBlockComponent.blockData.direction == Direction.right)
                    {
                        targetNode += new Node(1, 0);
                    }
                    else if (currentBlockComponent.blockData.direction == Direction.up)
                    {
                        targetNode += new Node(0, 1);
                    }
                    else if (currentBlockComponent.blockData.direction == Direction.down)
                    {
                        targetNode += new Node(0, -1);
                    }
                    TrapComponent _trapComponent = pm.pathManager.GetTrapComponent(targetNode);
                    if (_trapComponent == null || !_trapComponent.isObstacle)
                    {
                        MoveChampion(origin, targetNode, GameManager.championMoveDuration, MoveType.slip, true);
                    }
                }
                else if (currentBlockComponent.terrainGid == TerrainGid.finish)
                {
                    //finish!
                    pm.pathManager.currentSectionComponent.StopCollapse();
                    pm.isClear = true;
                    gameObject.transform.SetParent(currentBlockComponent.objectContainer);
                    animator.SetTrigger("finish");
                    currentBlockComponent.Finish();
                    Vector3 targetRotation = pm.cameraController.pivot.rotation.eulerAngles + new Vector3(0, 180, 0);
                    pm.cameraController.AnimatePivotAngle(Quaternion.Euler(targetRotation), 0.5f);
                    pm.GameOver("Clear", "", true);
                }


                // 새로운 섹션에 도착했고 해당 섹션은 스트레이트 세션이다
                // 도착한 섹션에다가 자동파괴명령을 내리자
                if (beforeBlockComponent.sectionComponent != currentBlockComponent.sectionComponent)
                {
                    if (currentBlockComponent.sectionComponent.sectionData.sectionType == SectionType.straight)
                    {
                        currentBlockComponent.sectionComponent.StartCollapse(1.5f, 1.5f);
                    }
                    else if (currentBlockComponent.sectionComponent.sectionData.sectionType == SectionType.corner)
                    {
                        currentBlockComponent.sectionComponent.StartCollapse(1.5f, 3.0f);
                    }
                }

                // Debug.Log("currentBlockComponent.blockData.progress: " + currentBlockComponent.blockData.progress.ToString());
                // Debug.Log("progress: " + progress.ToString());
                if (currentBlockComponent.blockData.progress > progress)
                {
                    // Debug.Log("Here");
                    pm.AddDistance(currentBlockComponent.blockData.progress - progress, !gotItem);
                    progress = currentBlockComponent.blockData.progress;
                }

                // if (currentBlockComponent.sectionComponent.sectionData.sectionType == SectionType.straight)
                // {
                //     currentBlockComponent.sectionComponent.StartCollapse(progress);
                // }



                TrapComponent trapComponent = pm.pathManager.GetTrapComponent(this.origin);
                if (trapComponent != null)
                {
                    if (trapComponent.trapType == TrapType.thornfloor && trapComponent.isThornUp)
                    {
                        trapComponent.ThornfloorAttack();
                    }
                    else if (trapComponent.trapType == TrapType.jawmachine && !trapComponent.isInvoked)
                    {
                        trapComponent.JawmachineAttack();
                    }
                    else if (trapComponent.trapType == TrapType.pushpad)
                    {
                        trapComponent.PushpadAction(this, origin, beforeNode);
                    }
                }
            }

            if (!isDead &&
                // !isRotate &&
                currentBlockComponent != null &&
                currentBlockComponent.sectionComponent.sectionData.sectionType == SectionType.straight &&
                currentBlockComponent.blockData.progress >= progress &&
                beforeBlockComponent != currentBlockComponent)
            {
                // CameraWork(currentBlockComponent);
            }
            if (isRotate)
            {
                // Debug.Log("champion rotate");
                Quaternion targetRotation = Quaternion.identity;
                if (currentBlockComponent.sectionComponent.sectionData.direction == Direction.right)
                {
                    if (currentBlockComponent.sectionComponent.beforeSectionComponent == null)
                    {
                        if (currentBlockComponent.sectionComponent.nextSectionComponent.nextSectionComponent.sectionData.direction == Direction.up)
                        {
                            targetRotation = Quaternion.Euler(pm.cameraController.championRightUpAngle);
                        }
                        else if (currentBlockComponent.sectionComponent.nextSectionComponent.nextSectionComponent.sectionData.direction == Direction.down)
                        {
                            targetRotation = Quaternion.Euler(pm.cameraController.championRightDownAngle);
                        }
                    }
                    else if (currentBlockComponent.sectionComponent.beforeSectionComponent.beforeSectionComponent == null)
                    {
                        if (currentBlockComponent.sectionComponent.nextSectionComponent.nextSectionComponent.sectionData.direction == Direction.up)
                        {
                            targetRotation = Quaternion.Euler(pm.cameraController.championRightUpAngle);
                        }
                        else if (currentBlockComponent.sectionComponent.nextSectionComponent.nextSectionComponent.sectionData.direction == Direction.down)
                        {
                            targetRotation = Quaternion.Euler(pm.cameraController.championRightDownAngle);
                        }
                    }
                    else if (currentBlockComponent.sectionComponent.beforeSectionComponent.beforeSectionComponent.sectionData.direction == Direction.down)
                    {
                        targetRotation = Quaternion.Euler(pm.cameraController.championRightDownAngle);
                    }
                    else if (currentBlockComponent.sectionComponent.beforeSectionComponent.beforeSectionComponent.sectionData.direction == Direction.up)
                    {
                        targetRotation = Quaternion.Euler(pm.cameraController.championRightUpAngle);
                    }
                }
                else if (currentBlockComponent.sectionComponent.sectionData.direction == Direction.up)
                {
                    targetRotation = Quaternion.Euler(pm.cameraController.championUpAngle);
                }
                else if (currentBlockComponent.sectionComponent.sectionData.direction == Direction.down)
                {
                    targetRotation = Quaternion.Euler(pm.cameraController.championDownAngle);
                }
                pm.cameraController.AnimatePivotAngle(targetRotation, 0.3f);
            }
            if (addScore > 0)
            {
                pm.uiManager.UpdateScoreUI(pm.score, addScore);
            }
        }