예제 #1
0
    public void SpawnObstacles()
    {
        _ObstaclePattern = GameUtility.RandomEnumValue <ObstaclePattern>(rand);

        if (gameController.obstacleCourses.Count > 0)
        {
            GameObject latestObstacleCourse = gameController.obstacleCourses[gameController.obstacleCourses.Count - 1].gameObject;
            Vector3    size = latestObstacleCourse.GetComponent <BoxCollider2D>().bounds.size;
            nextSpawnPos = latestObstacleCourse.transform.position + new Vector3(0, size.y + spawnHeightOffset);
        }

        switch (_ObstaclePattern)
        {
        case ObstaclePattern.Circle:
            SpawnCircleObstacle();
            break;

        case ObstaclePattern.Square:
            SpawnSquareObstacle();
            break;

        default:
            SpawnWaveObstacle();
            break;
        }
    }
예제 #2
0
 public void OnSceneLoaded(LevelConfiguration argument)
 {
     _towerSize       = argument.TowerSize;
     _block           = argument.BlockPattern;
     _obstaclePattern = argument.ObstaclePattern;
 }
예제 #3
0
        private static bool CheckIfNodeMatchesObstaclePattern(NodeWalkable walkableNode, ObstaclePattern pattern)
        {
            bool nodeMatchesObstaclePattern = false;

            if (walkableNode != null)
            {
                Vector3Int nodeCoordinates = walkableNode.Coordinates;
                Vector3Int nodeUpVector    = walkableNode.UpVectors[0];
                int        remainder       = pattern == ObstaclePattern.Even ? 0 : 1;

                // Add obstacles in a pattern so that the player can always pass through and the player target is always reachable.
                // Pattern:
                // #-#
                // ---
                // #-#
                nodeMatchesObstaclePattern  = true;
                nodeMatchesObstaclePattern &= nodeCoordinates.y % 2 == remainder || Mathf.Abs(nodeUpVector.y) > 0;
                nodeMatchesObstaclePattern &= nodeCoordinates.x % 2 == remainder || Mathf.Abs(nodeUpVector.x) > 0;
                nodeMatchesObstaclePattern &= nodeCoordinates.z % 2 == remainder || Mathf.Abs(nodeUpVector.z) > 0;
            }

            return(nodeMatchesObstaclePattern);
        }
예제 #4
0
 private static void AddObstacles(Node[] gridNodes, NodeWalkable playerStartNode, float density, ObstaclePattern pattern, int minPlayerStartClearance)
 {
     for (int i = 0; i < gridNodes.Length; ++i)
     {
         NodeWalkable walkableNode = gridNodes[i] as NodeWalkable;
         if (walkableNode != null && walkableNode != playerStartNode)
         {
             // Don't add obstacles on edges of the cube.
             if (walkableNode.UpVectors != null && walkableNode.UpVectors.Length == 1)
             {
                 if (Random.value <= density)
                 {
                     float nodeDistanceToPlayer = Vector3Int.Distance(playerStartNode.Coordinates, walkableNode.Coordinates);
                     if (nodeDistanceToPlayer > minPlayerStartClearance)
                     {
                         if (CheckIfNodeMatchesObstaclePattern(walkableNode, pattern) == true)
                         {
                             walkableNode.SetAsObstacle();
                         }
                     }
                 }
             }
         }
     }
 }