예제 #1
0
        private WorldGridController CreateWorldGrid()
        {
            GameObject          worldGridObject     = Instantiate(m_WorldGridPrefab);
            WorldGridController worldGridController = worldGridObject.GetAndAssertComponent <WorldGridController>();

            return(worldGridController);
        }
예제 #2
0
        private void UpdatePosition(WorldGridController worldGridController)
        {
            NodeWalkable nextNode = worldGridController.GetNextWalkableNodeInDirection(ActiveNode, m_MovementDirection, m_UpVector);

            if (nextNode != null && nextNode != ActiveNode)
            {
                NodeWalkable previousNode = ActiveNode;
                ActiveNode = nextNode;

                Vector3Int movementDirection = ActiveNode.Coordinates - previousNode.Coordinates;
                if (movementDirection != m_MovementDirection)
                {
                    Quaternion rotation = Quaternion.FromToRotation(m_MovementDirection, movementDirection);
                    m_UpVector = Vector3IntUtil.Rotate(m_UpVector, rotation);

                    m_MovementDirection = movementDirection;
                }

                // Check before adding active node to path!
                bool collidedWithSelf     = m_PathNodes.Contains(ActiveNode) == true;
                bool collidedWithObstacle = ActiveNode.IsObstacle == true;

                m_PathNodes.Enqueue(ActiveNode);

                if (collidedWithSelf == true || collidedWithObstacle == true)
                {
                    Die();
                }
            }
        }
예제 #3
0
        public void MoveToNextPosition(WorldGridController worldGridController)
        {
            UpdateInput();
            UpdatePosition(worldGridController);
            UpdatePath();

            m_View.UpdatePath(ActiveNode, m_PathNodes);
        }
예제 #4
0
        public void Initialize(PlayerController playerController, WorldGridController worldGridController)
        {
            if (AreReferencesAssigned == true)
            {
                StopAllCoroutines();
                m_CameraRotationRoutine = null;
                m_CameraShakeRoutine    = null;

                float cameraDistance = worldGridController.GridSize / 2f;
                cameraDistance *= m_DistanceMultiplier;
                m_CameraTransform.localPosition = new Vector3(0, 0, -cameraDistance);

                Quaternion lookAtRotation = CalculateCameraLookAtRotation(playerController, worldGridController.transform, Vector3.up);
                transform.rotation = lookAtRotation;
            }
        }
예제 #5
0
        private void EndGame()
        {
            StopAllCoroutines();

            if (m_PlayerController != null)
            {
                Destroy(m_PlayerController.gameObject);
                m_PlayerController = null;
            }

            if (m_WorldGridController != null)
            {
                Destroy(m_WorldGridController.gameObject);
                m_WorldGridController = null;
            }

            m_MenuUI.SetIsVisible(false);
        }
예제 #6
0
        private void StartNewGame()
        {
            Debug.Assert(m_WorldGridController == null && m_PlayerController == null, "Game already started!", this);

            m_PlayerController = CreatePlayer();
            if (m_PlayerController != null)
            {
                m_WorldGridController = CreateWorldGrid();
                if (m_WorldGridController != null && m_WorldGridController.GenerateWorldGrid(m_WorldGridGenerator) == true)
                {
                    m_ScoreManager.InitializeScore(m_WorldGridGenerator.PlayerPrefKey);
                    m_ScoreUI.SetIsVisible(true);

                    m_PlayerController.Initialize(m_WorldGridController.PlayerStartNode, m_WorldGridGenerator.PlayerStartDirection);
                    m_WorldGridController.UpdatePlayerTarget(m_PlayerController.PathNodes);

                    m_CameraController.Initialize(m_PlayerController, m_WorldGridController);

                    StartCoroutine(UpdateGameRoutine());
                }
            }
        }