Ejemplo n.º 1
0
    LevelChunkData PickNextChunk()
    {
        List <LevelChunkData> allowedChunkList = new List <LevelChunkData>();
        LevelChunkData        nextChunk        = null;

        UpdateSpawnPoint();


        //spawnPosition = spawnPosition + previousChunk.levelChunks[0].transform.TransformPoint(previousChunk.levelChunks[0].transform.Find("OutputPoint").position);


        for (int i = 0; i < levelChunkData.Length; i++)
        {
            if (levelChunkData[i].entryDirection == nextRequiredDirection)
            {
                if (previousChunk.RequireLargeCurve)
                {
                    if (levelChunkData[i].chunkSize.magnitude > 10)
                    {
                        allowedChunkList.Add(levelChunkData[i]);
                    }
                }

                else
                {
                    allowedChunkList.Add(levelChunkData[i]);
                }
            }
        }
        var aloo = Random.Range(0, allowedChunkList.Count);

        nextChunk = allowedChunkList[aloo];

        return(nextChunk);
    }
Ejemplo n.º 2
0
    void PickAndSpawnChunk()
    {
        LevelChunkData chunkToSpawn = PickNextChunk();

        Quaternion trackRotation = chunkToSpawn.trackRoation;



        GameObject objectFromChunk = chunkToSpawn.levelChunks[Random.Range(0, chunkToSpawn.levelChunks.Length)];

        //if(objectFr

        // var chinkInputPoint = objectFromChunk.transform.Find("InputPoint").position;

        tracksTillCheckpoint += (int)chunkToSpawn.chunkSize.y / 10;

        //Debug.Log(chunkToSpawn.name + tracksTillCheckpoint);

        if (tracksTillCheckpoint >= CheckpointEveryNSegments)
        {
            CreateCheckpoint();
            tracksTillCheckpoint = 0;
        }



        previousChunk = chunkToSpawn;
        var trackPiece = Instantiate(objectFromChunk, spawnPosition + spawnOrigin, trackRotation);

        trackPiece.transform.parent = gameObject.transform;
    }
    void Start()
    {
        // pooling stuff
        trackPieces   = new List <GameObject>();                // initilize the list
        previousChunk = firstChunk;                             // indicator of previous track piece used



        for (int i = 0; i < PooledAmount; i++)              // create 20 track pieces in the list
        {
            LevelChunkData chunkToSpawn = PickNextChunk_nopos();

            GameObject objectFromChunk = chunkToSpawn.levelChunks[Random.Range(0, chunkToSpawn.levelChunks.Length)];
            previousChunk = chunkToSpawn;


            GameObject obj = (GameObject)Instantiate(objectFromChunk);
            obj.SetActive(false);                                   // set as false as only want small amount to start
            trackPieces.Add(obj);                                   // add track pieces to List
        }

        for (int i = 0; i < chunksToSpawn; i++)                     // Create 10 initial section of the track and mark active
        {
            GetPoolobject();
        }
    }
Ejemplo n.º 4
0
    void Start()
    {
        previousChunk = firstChunk;

        for (int i = 0; i < chunksToSpawn; i++)
        {
            PickAndSpawnChunk();
        }
    }
    void PickAndSpawnChunk()
    {
        LevelChunkData chunkToSpawn = PickNextChunk();

        GameObject objectFromChunk = chunkToSpawn.levelChunks[Random.Range(0, chunkToSpawn.levelChunks.Length)];

        previousChunk = chunkToSpawn;
        Instantiate(objectFromChunk, spawnPosition + spawnOrigin, Quaternion.identity);
    }
Ejemplo n.º 6
0
    void PickAndSpawnChunk()
    {
        LevelChunkData chunkToSpawn = PickNextChunk();

        // In case there are multiple chunks with the same entry and exit points
        GameObject objectFromChunk = chunkToSpawn.levelChunk[0];

        previousChunk = chunkToSpawn;
        Instantiate(objectFromChunk, spawnPosition + spawnOrigin, Quaternion.identity);
    }
Ejemplo n.º 7
0
    LevelChunkData PickNextChunk()
    {
        List <LevelChunkData> allowedChunkList = new List <LevelChunkData>();
        LevelChunkData        nextChunk        = null;

        LevelChunkData.Direction nextRequiredDirection = LevelChunkData.Direction.North;

        switch (previousChunk.exitDirection)
        {
        case LevelChunkData.Direction.North:
            nextRequiredDirection = LevelChunkData.Direction.South;
            spawnPosition         = spawnPosition + new Vector3(0f, 0, previousChunk.chunkSize.y);
            break;

        case LevelChunkData.Direction.East:
            nextRequiredDirection = LevelChunkData.Direction.West;
            spawnPosition         = spawnPosition + new Vector3(previousChunk.chunkSize.x, 0, 0);
            break;

        case LevelChunkData.Direction.South:
            nextRequiredDirection = LevelChunkData.Direction.North;
            spawnPosition         = spawnPosition + new Vector3(0, 0, -previousChunk.chunkSize.y);
            break;

        case LevelChunkData.Direction.West:
            nextRequiredDirection = LevelChunkData.Direction.East;
            spawnPosition         = spawnPosition + new Vector3(-previousChunk.chunkSize.x, 0, 0);
            break;

        default:
            break;
        }

        for (int i = 0; i < levelChunkData.Length; i++)
        {
            if (levelChunkData[i].entryDirection == nextRequiredDirection)
            {
                allowedChunkList.Add(levelChunkData[i]);
            }
        }
        if (firstChunkCreated == false)
        {
            firstChunkCreated = true;
            nextChunk         = allowedChunkList[1];
            return(nextChunk);
        }
        else
        {
            nextChunk = allowedChunkList[Random.Range(0, allowedChunkList.Count)];
            return(nextChunk);
        }
    }
Ejemplo n.º 8
0
    void HillDownGeneration(LevelChunkData nextChunk)
    {
        switch (previousChunk.upAndDown)
        {
        case LevelChunkData.GetUpAndDown.Up:

            if (previousChunk.heightDifference == LevelChunkData.DifferenceInHeight.One)
            {
                MoveUpOrDown(nextChunk, 0f, 2.8f, -2.8f, 2.8f);
            }

            else if (previousChunk.heightDifference == LevelChunkData.DifferenceInHeight.Two)
            {
                MoveUpOrDown(nextChunk, 3.35f, 5.8f, 0f, 5.8f);
            }
            break;

        case LevelChunkData.GetUpAndDown.Down:

            if (previousChunk.heightDifference == LevelChunkData.DifferenceInHeight.One)
            {
                MoveUpOrDown(nextChunk, -2.8f, 0f, -5.8f, 0f);
            }

            else if (previousChunk.heightDifference == LevelChunkData.DifferenceInHeight.Two)
            {
                MoveUpOrDown(nextChunk, -2.8f, 0f, -5.8f, 0f);
            }
            break;

        case LevelChunkData.GetUpAndDown.Nothing:
            if (nextChunk.heightDifference == LevelChunkData.DifferenceInHeight.One && nextChunk.upAndDown == LevelChunkData.GetUpAndDown.Down)
            {
                spawnPosition += new Vector3(0f, -2.8f, 0f);
            }
            else if (nextChunk.heightDifference == LevelChunkData.DifferenceInHeight.Two && nextChunk.upAndDown == LevelChunkData.GetUpAndDown.Down)
            {
                spawnPosition += new Vector3(0f, -5.8f, 0f);
            }
            else if (nextChunk.heightDifference == LevelChunkData.DifferenceInHeight.Zero && nextChunk.upAndDown == LevelChunkData.GetUpAndDown.Down)
            {
                spawnPosition += new Vector3(0f, -2.8f, 0f);
            }
            break;

        default:
            break;
        }
    }
Ejemplo n.º 9
0
 void Start()
 {
     previousChunk = firstChunk;
     for (int i = 0; i < chunksToSpawn; i++)
     {
         PickAndSpawnChunk();
     }
     timeTrack     = 0;
     userTracker   = GameObject.Find("HoverCar");
     yellowTracker = GameObject.Find("Yellow - AI HoverCar");
     blackTracker  = GameObject.Find("Black - AI HoverCar");
     purpleTracker = GameObject.Find("Purple - AI HoverCar");
     AI_DeathText  = userTracker.transform.GetChild(0).transform.GetChild(3).transform.GetChild(0).gameObject.GetComponent <TextMeshProUGUI>();
     AI_DeathText.SetText("");
 }
Ejemplo n.º 10
0
    void PickAndSpawnChunk()
    {
        LevelChunkData chunkToSpawn = PickNextChunk();

        GameObject objectFromChunk = chunkToSpawn.levelChunks[Random.Range(0, chunkToSpawn.levelChunks.Length)];

        previousChunk = chunkToSpawn;
        GameObject instantiatedObj = Instantiate(objectFromChunk, spawnPosition + spawnOrigin, Quaternion.identity);

        targetObjectList.Add(instantiatedObj.transform.Find("Target (4)").gameObject);
        targetObjectList.Add(instantiatedObj.transform.Find("Target (3)").gameObject);
        targetObjectList.Add(instantiatedObj.transform.Find("Target (2)").gameObject);
        targetObjectList.Add(instantiatedObj.transform.Find("Target (1)").gameObject);
        targetObjectList.Add(instantiatedObj.transform.Find("Target").gameObject);
    }
Ejemplo n.º 11
0
    LevelChunkData PickNextChunk()
    {
        List <LevelChunkData> allowedChunkList = new List <LevelChunkData>();
        LevelChunkData        nextChunk        = null;

        LevelChunkData.Direction nextRequiredDirection = LevelChunkData.Direction.North;

        //Determine next chunk based on the exit direction of previous chunk and the entry direction of the next
        switch (previousChunk.exitDirection)
        {
        case LevelChunkData.Direction.North:
            nextRequiredDirection = LevelChunkData.Direction.South;
            spawnPosition         = spawnPosition + new Vector3(0, 0, previousChunk.chunkSize.y);

            break;

        case LevelChunkData.Direction.East:
            nextRequiredDirection = LevelChunkData.Direction.West;
            spawnPosition         = spawnPosition + new Vector3(previousChunk.chunkSize.x, 0, 0);

            break;

        case LevelChunkData.Direction.South:
            nextRequiredDirection = LevelChunkData.Direction.North;
            spawnPosition         = spawnPosition + new Vector3(0, 0, -previousChunk.chunkSize.y);

            break;

        case LevelChunkData.Direction.West:
            nextRequiredDirection = LevelChunkData.Direction.East;
            spawnPosition         = spawnPosition + new Vector3(-previousChunk.chunkSize.x, 0, 0);

            break;
        }

        //Take all chunks with determined entry point and add them to allowed list
        for (int i = 0; i < levelChunkData.Length; i++)
        {
            if (levelChunkData[i].entryDirection == nextRequiredDirection)
            {
                allowedChunkList.Add(levelChunkData[i]);
            }
        }

        nextChunk = allowedChunkList[Random.Range(0, allowedChunkList.Count)];

        return(nextChunk);
    }
Ejemplo n.º 12
0
        LevelChunkData PickNextChunk()
        {
            List <LevelChunkData> allowedChunkList = new List <LevelChunkData>();
            LevelChunkData        nextChunk        = null;

            LevelChunkData.Direction nextRequiredDirection = LevelChunkData.Direction.North;

            switch (_previousChunk.exitDirection)
            {
            case LevelChunkData.Direction.North:
                nextRequiredDirection = LevelChunkData.Direction.South;
                _spawnPosition        = _spawnPosition + new Vector3(0f, 0, _previousChunk.chunkSize.y);

                break;

            case LevelChunkData.Direction.East:
                nextRequiredDirection = LevelChunkData.Direction.East;
                _spawnPosition        = _spawnPosition + new Vector3(0f, 0, _previousChunk.chunkSize.y);
                break;

            case LevelChunkData.Direction.South:
                nextRequiredDirection = LevelChunkData.Direction.South;
                _spawnPosition        = _spawnPosition + new Vector3(0, 0, -_previousChunk.chunkSize.y);
                break;

            case LevelChunkData.Direction.West:
                nextRequiredDirection = LevelChunkData.Direction.West;
                _spawnPosition        = _spawnPosition + new Vector3(0f, 0, _previousChunk.chunkSize.y);

                break;

            default:
                break;
            }

            foreach (var t in levelChunkData)
            {
                if (t.entryDirection == nextRequiredDirection)
                {
                    allowedChunkList.Add(t);
                }
            }

            nextChunk = allowedChunkList[Random.Range(0, allowedChunkList.Count)];

            return(nextChunk);
        }
Ejemplo n.º 13
0
    void PickAndSpawnChunk()
    {
        LevelChunkData chunkToSpawn = PickNextChunk();

        GameObject objectFromChunk = null;

        objectFromChunk = chunkToSpawn.levelChunks[Random.Range(0, desertChunckSizeIndex)];

        previousChunk = chunkToSpawn;
        var element = Instantiate(objectFromChunk, spawnPosition + spawnOrigin, Quaternion.identity);

        if (animate)
        {
            element.AddComponent <DropTween>();
            DropTween.IncreaseDropTime();
        }
    }
Ejemplo n.º 14
0
    public void GenerateTrack()
    {
        SavedCheckpoints.Clear();
        previousChunk = firstChunk;

        spawnPosition = gameObject.transform.position;

        for (int i = 0; i < trackLength; i++)
        {
            PickAndSpawnChunk();

            /*            if (tracksTillCheckpoint == CheckpointEveryNSegments && i != trackLength - 1)
             *          {
             *              CreateCheckpoint();
             *              tracksTillCheckpoint = 0;
             *          }*/
            CreateFinishGate(spawnPosition, i);
        }
    }
Ejemplo n.º 15
0
 void MoveUpOrDown(LevelChunkData nextChunk, float oneDown, float oneUp, float twoDown, float straightUp)
 {
     if (nextChunk.heightDifference == LevelChunkData.DifferenceInHeight.One && nextChunk.upAndDown == LevelChunkData.GetUpAndDown.Down)
     {
         spawnPosition += new Vector3(0f, oneDown, 0f);
     }
     else if (nextChunk.heightDifference == LevelChunkData.DifferenceInHeight.One && nextChunk.upAndDown == LevelChunkData.GetUpAndDown.Up)
     {
         spawnPosition += new Vector3(0f, oneUp, 0f);
     }
     else if (nextChunk.heightDifference == LevelChunkData.DifferenceInHeight.Two && nextChunk.upAndDown == LevelChunkData.GetUpAndDown.Down)
     {
         spawnPosition += new Vector3(0f, twoDown, 0f);
     }
     else
     {
         spawnPosition += new Vector3(0f, straightUp, 0f);
     }
 }
Ejemplo n.º 16
0
    private void OnEnable()
    {
        targetChunkData       = target as LevelChunkData;
        numberOfLinesProperty = serializedObject.FindProperty("numberOfLines");
        numberOfColumns       = targetChunkData.GetNumberOfColumn;
        prefabLibrary         = targetChunkData.GetPrefabLibrary;
        ComposePrefabsDictionary();

        if (prefabsDictionnary.ContainsKey(100))
        {
            currentBrushType = LevelChunkBrushType.Obstacle;
            SetCurrentBrushIndex(100);
        }
        else if (prefabsDictionnary.ContainsKey(200))
        {
            currentBrushType = LevelChunkBrushType.Enemy;
            SetCurrentBrushIndex(200);
        }
    }
    LevelChunkData PickNextChunk_nopos()                            // Function to determine which trackpiece to used based on entry direction
    {
        List <LevelChunkData> allowedChunkList = new List <LevelChunkData>();
        LevelChunkData        nextChunk        = null;

        LevelChunkData.Direction nextRequiredDirection = LevelChunkData.Direction.North;

        switch (previousChunk.exitDirection)
        {
        case LevelChunkData.Direction.North:
            nextRequiredDirection = LevelChunkData.Direction.South;
            break;

        case LevelChunkData.Direction.East:
            nextRequiredDirection = LevelChunkData.Direction.West;
            break;

        case LevelChunkData.Direction.South:
            nextRequiredDirection = LevelChunkData.Direction.North;
            break;

        case LevelChunkData.Direction.West:
            nextRequiredDirection = LevelChunkData.Direction.East;
            break;

        default:
            break;
        }

        for (int i = 0; i < levelChunkData.Length; i++)
        {
            if (levelChunkData[i].entryDirection == nextRequiredDirection)
            {
                allowedChunkList.Add(levelChunkData[i]);
            }
        }

        nextChunk = allowedChunkList[Random.Range(0, allowedChunkList.Count)];

        return(nextChunk);
    }
Ejemplo n.º 18
0
        void PickAndSpawnChunk()
        {
            LevelChunkData chunkToSpawn = PickNextChunk();

            GameObject objectFromChunk = chunkToSpawn.levelChunks[Random.Range(0, chunkToSpawn.levelChunks.Length)];

            _previousChunk = chunkToSpawn;
            if (spawnDynamite)
            {
                if (chunkToSpawn.entryDirection == LevelChunkData.Direction.South)
                {
                    if (Random.Range(0.0f, 50.0f) < 5.0f)
                    {
                        var pos = _spawnPosition + spawnOrigin + new Vector3(0.0f, 0.5f, -1.0f);
                        Instantiate(dynamitePrefab, pos, dynamitePrefab.transform.rotation);
                    }
                }
            }

            Instantiate(objectFromChunk, _spawnPosition + spawnOrigin, objectFromChunk.transform.rotation);
        }
Ejemplo n.º 19
0
    LevelChunkDataVariable PickNextChunk()
    {
        List <LevelChunkDataVariable> allowedChunkList = new List <LevelChunkDataVariable>();
        LevelChunkDataVariable        nextChunk        = null;

        // Pick Next Chunk by looking at the previous chunks allowed directions
        LevelChunkData.Direction nextRequiredEntryDirection = LevelChunkData.Direction.North;


        // if previous chunk is a U road, we want to adjust spawn position
        if (previousChunk.Value.entryDirection == previousChunk.Value.exitDirection)
        {
            spawnPosition += new Vector3(0f, 0f, previousChunk.Value.chunkSize.y / 2f);
        }


        switch (previousChunk.Value.exitDirection)
        {
        case LevelChunkData.Direction.North:
            nextRequiredEntryDirection = LevelChunkData.Direction.South;
            spawnPosition += new Vector3(0f, 0f, previousChunk.Value.chunkSize.y);
            break;

        case LevelChunkData.Direction.East:
            nextRequiredEntryDirection = LevelChunkData.Direction.West;
            spawnPosition += new Vector3(previousChunk.Value.chunkSize.x, 0f, 0f);
            break;

        case LevelChunkData.Direction.South:
            nextRequiredEntryDirection = LevelChunkData.Direction.North;
            spawnPosition += new Vector3(0f, 0f, -previousChunk.Value.chunkSize.y);
            break;

        case LevelChunkData.Direction.West:
            nextRequiredEntryDirection = LevelChunkData.Direction.East;
            spawnPosition += new Vector3(-previousChunk.Value.chunkSize.x, 0f, 0f);
            break;

        default:
            break;
        }

        // if previous chunk is a corner chunk then we want straight road next time
        LevelChunkData.Direction nextRequiredExitDirection;
        if (previousChunk.Value.turningDirection != 0)
        {
            nextRequiredExitDirection = LevelChunkData.GetOppositeDirection(nextRequiredEntryDirection);

            foreach (var item in levelChunkDatas)
            {
                if (item.Value.entryDirection == nextRequiredEntryDirection && item.Value.exitDirection == nextRequiredExitDirection)
                {
                    allowedChunkList.Add(item);
                }
            }
        }
        else
        {
            foreach (var item in levelChunkDatas)
            {
                if (item.Value.entryDirection == nextRequiredEntryDirection)
                {
                    allowedChunkList.Add(item);
                }
            }
        }


        nextChunk = allowedChunkList[Random.Range(0, allowedChunkList.Count)];

        return(nextChunk);
    }