private WorldGridController CreateWorldGrid() { GameObject worldGridObject = Instantiate(m_WorldGridPrefab); WorldGridController worldGridController = worldGridObject.GetAndAssertComponent <WorldGridController>(); return(worldGridController); }
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(); } } }
public void MoveToNextPosition(WorldGridController worldGridController) { UpdateInput(); UpdatePosition(worldGridController); UpdatePath(); m_View.UpdatePath(ActiveNode, m_PathNodes); }
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; } }
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); }
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()); } } }