Exemplo n.º 1
0
 private void DestroyCurrentLevel()
 {
     if (!LevelIsPresent)
     {
         return;
     }
     mazeFrame              = null;
     mazeFrameSplines       = null;
     gravityFrameController = null;
     Destroy(mazeObjects);
     if (player != null)
     {
         player.SetActive(false);
     }
     if (cameraRig != null)
     {
         cameraRig.SetActive(false);
     }
     if (endPortal != null)
     {
         endPortal.SetActive(false);
     }
     if (cubeOfDeath != null)
     {
         Destroy(cubeOfDeath);
     }
     if (mindWarpTriggers != null)
     {
         Destroy(mindWarpTriggers);
     }
     //Destroy(player);
     //Destroy(cameraRig);
     //Destroy(cubeOfDeath);
     //Destroy(endPortal);
 }
 private void OnEnable()
 {
     CODTrans = gameObject.transform;
     playerRB = GameObject.FindWithTag("Player").GetComponent <Rigidbody>();
     gravityFrameController = FindObjectOfType <GameController>().levelController.gravityFrameController;
     currEventHorizon       = eventHorizon * MazeScale.ComponentMax();
 }
Exemplo n.º 3
0
    public void ActivatePlayer()
    {
        playerActive = true;

        // Find gravity frame and re-intialize
        gravityFrameController = FindObjectOfType <LevelController>().gravityFrameController;
        gravityFrameController.Initialize(rb.position);

        // Initialize current surface variable
        currentFramePlaneSurfaceNormal = FindSurfaceNormalTowardsFramePlane();

        // Reset x,y,z axis base
        UpDir      = Vector3.up;
        RightDir   = Vector3.right;
        ForwardDir = Vector3.forward;
    }
Exemplo n.º 4
0
    private IEnumerator BuildNewMaze()
    {
        float mazeFrameElementsBuilt = 0;

        mazeFrameMeshesArePresent = false;
        // Initialize maze creator
        MazeFrameCreator mazeFrameCreator = null;

        switch (mazeShape)
        {
        case 0:
        {
            mazeFrameCreator = new MazeFrameCreatorSquare3D(mazeSize, nQuadrants)
            {
                Scale = mazeScale, Jitter = mazeJitter
            }; break;
        }

        case 1:
        {
            mazeFrameCreator = new MazeFrameCreatorMeshIcosahedron(nDivisions, nQuadrants)
            {
                Scale = mazeScale, Jitter = mazeJitter
            }; break;
        }
        }
        // Set random seed selector
        System.Random randGen = new ConsistentRandom();
        // Randomize order of difficulties
        int[] randomQuadrantIndices = Utilities.RandomIndices(nQuadrants);
        // Generate maze!
        if (nQuadrants != 0 && nQuadrants != difficulties.Length)
        {
            throw new System.ArgumentException("When using quadrants, nQuadrants and nDifficulties should be equal.");
        }
        List <MazeFrame> singleMazeFrames = new List <MazeFrame>(difficulties.Length);

        for (int iDifficulty = 0; iDifficulty < difficulties.Length; iDifficulty++)
        {
            List <MazeFrame> singleFrameSections = new List <MazeFrame>(nSections);
            for (int iSections = 0; iSections < nSections; iSections++)
            {
                // Create sections
                int quadrantInd;
                //if (nQuadrants != 0) { quadrantInd = iDifficulty; }
                if (nQuadrants != 0)
                {
                    quadrantInd = randomQuadrantIndices[iDifficulty];
                }
                else
                {
                    quadrantInd = 0;
                }
                MazeFrame currSection    = null;
                int       currDifficulty = difficulties[iDifficulty];
                int       currSeedInd    = randGen.Next(seedData[quadrantInd].seeds[currDifficulty].Length);
                mazeFrameCreator.RandomSeed = seedData[quadrantInd].seeds[currDifficulty][currSeedInd];
                //mazeFrameCreator.RandomSeed = seedData[quadrantInd].seeds[iDifficulty][iSections];
                if (nQuadrants == 0)
                {
                    currSection = mazeFrameCreator.GenerateMaze();
                }
                else
                {
                    currSection = mazeFrameCreator.GenerateEmptyMazeFrame();
                    mazeFrameCreator.GenerateMaze(ref currSection, quadrantInd);
                    currSection.SetOnShortestPath(currSection.Quadrants[quadrantInd], 0); // HACKY
                }
                //currSection.KeepOnlyShortestPathConnections();
                //currSection.AddPathSegments();
                // DEBUG
                if (nQuadrants != 0)
                {
                    Debug.Log(currSection.GetNIntersectionsOnPath()[0] + "  " + currSection.GetDifficulty(quadrantInd)[0] + " - " + seedData[quadrantInd].difficulties[currDifficulty][currSeedInd]);
                }
                else
                {
                    Debug.Log(currSection.GetNIntersectionsOnPath()[0] + "  " + currSection.GetDifficulty()[0]);
                }
                // DEBUG
                singleFrameSections.Add(currSection);
                mazeFrameElementsBuilt++;
                LevelBuiltProgressPercentage = (mazeFrameElementsBuilt / (difficulties.Length * nSections)) / 2;
                yield return(null);
            }
            MazeFrame currSingleFrame;
            if (singleFrameSections.Count > 1)
            { //MazeFrame currSingleFrame = MazeFrame.Concatenate(singleFrameSections, mazeFrameCreator.Scale, mazeDirection);
                currSingleFrame = MazeFrame.CombineShrink(singleFrameSections, shrinkFactor);
            }
            else
            {
                currSingleFrame = singleFrameSections[0];
            }
            currSingleFrame.AddOffsetStartNode(Vector3.Scale(mazeDirection, mazeScale) * startOffsetFactor, true);
            currSingleFrame.AddOffsetEndNode(Vector3.Scale(mazeDirection, mazeScale) * endOffsetFactor, true);
            for (int iInc = 0; iInc < iDifficulty; iInc++)
            {
                currSingleFrame.IncrementShortestPathIndices();
            }
            singleMazeFrames.Add(currSingleFrame);
        }
        if (singleMazeFrames.Count > 1)
        {
            mazeFrame = MazeFrame.Merge(singleMazeFrames);
        }
        else
        {
            mazeFrame = singleMazeFrames[0];
        }
        //mazeFrame.ConnectUnconnectedNodes();
        mazeFrame.AddPathSegments();
        yield return(null);

        // Populate maze and get return splines and maze objects
        mazePopulator.PopulateWithSplineFittedBars(mazeFrame, ref mazeFrameSplines, ref mazeObjects, objectScaling);
        //mazePopulator.PopulateWithSplineFittedCylinders(mazeFrame, ref mazeFrameSplines, ref mazeObjects, objectScaling);

        // Wait till population is complete
        while (!mazeFrameMeshesArePresent)
        {
            if (mazePopulator.MazeObjectsPlaced == mazeFrameSplines.SplineSegments.Count)
            {
                mazeFrameMeshesArePresent = true;
            }
            yield return(null);
        }

        // Create and Initialize gravity frame
        gravityFrameController = new GravityFrameController(mazeFrame, mazeFrameSplines, gravJunctionDistFactor, gravPlaneWidth);
        yield return(null);


        // Place others
        PlacePlayerAndCamera();
        PlaceEndPortal();
        PlaceCubeOfDeath();
        PlaceMindWarpTriggers();
    }