Exemplo n.º 1
0
	private TunnelSelectionPreferences buildPreferences() {
		TunnelSelectionPreferences prefs = new TunnelSelectionPreferences ();
		LinkedListNode<TunnelPiece> currentNode = tunnel.Last;

		float distanceToEndOfTunnel = 0f;
		float currentTunnelDifficulty = 0f;
		int numPieces = 0;

		while (distanceToEndOfTunnel < maxDistanceToCheckPreferenceModifiers && currentNode != null) {
			TunnelPiece piece = currentNode.Value;
			prefs = piece.updatePreferences(prefs, distanceToEndOfTunnel);
			distanceToEndOfTunnel += piece.length();
			currentTunnelDifficulty += piece.difficultyLevel;
			currentNode = currentNode.Previous;
			numPieces++;
		}

		//set the average difficulty in case anyone cares
		currentAverageDifficulty = currentTunnelDifficulty / numPieces;
		//int bucketLevel = calculateBucketLevel ();
		prefs.maxBucketLevel = (int) Mathf.Lerp(0, maxBucketLevel, ball.position.z / distanceToMaxSettings);
		prefs.maxDifficulty = Mathf.Lerp(baseDifficulty, maxDifficulty, ball.position.z / distanceToMaxSettings) - currentTunnelDifficulty;
		prefs.preferredDifficulty = prefs.maxDifficulty / 2f;
		return prefs;
	}
Exemplo n.º 2
0
    private bool validatePiece(TunnelSelectionPreferences prefs)
    {
        bool isValid = this.bucketLevel <= prefs.maxBucketLevel;

        isValid = isValid && this.difficultyLevel <= prefs.maxDifficulty;
        return(isValid);
    }
Exemplo n.º 3
0
    public virtual void setup(TunnelSelectionPreferences prefs, TunnelPiece parent)
    {
        position = transform.position;
        float flyInTime = Mathf.Lerp(0, maxFlyInTime, 1 / (ball.GetTargetVelocity().magnitude / 30f));

        //Debug.Log ("Fly in time: " + flyInTime + " for ball speed of: " + ball.GetTargetVelocity ().magnitude);
        transform.position = transform.position + (((Vector3.down * Random.Range(-1, 2)) + (Vector3.left * Random.Range(-1, 2))) * maxFlyInDistance);
        transform.DOMove(position, flyInTime).Play();
    }
Exemplo n.º 4
0
    public TunnelPiece spawnChildPiece(TunnelSelectionPreferences prefs)
    {
        TunnelPiece child = TunnelPiecePool.INSTANCE.takeWeightedRandomPieceFromPool(prefs);

        child.transform.position = position + endOffset;
        child.gameObject.SetActive(true);
        child.setup(prefs, this);
        child.choosePotentialCollectableSlot();
        return(child);
    }
Exemplo n.º 5
0
    private float categoryWeightModifier(TunnelSelectionPreferences prefs, TunnelPieceCategory category)
    {
        float weight;

        if (!prefs.categoryWeights.TryGetValue(category, out weight))
        {
            weight = 1f;
        }
        return(weight);
    }
Exemplo n.º 6
0
 public float calculateWeight(TunnelSelectionPreferences prefs)
 {
     if (validatePiece(prefs))
     {
         return((baseWeight + difficultyWeightModifier(prefs)) * categoryWeightModifier(prefs, category));
     }
     else
     {
         return(0f);
     }
 }
Exemplo n.º 7
0
 //Allows this piece to update selection preferences for a child/grandchild piece
 public TunnelSelectionPreferences updatePreferences(TunnelSelectionPreferences basePreferences, float distanceToEndOfTunnel)
 {
     foreach (ChildCategoryWeight ccw in childCategoryWeights)
     {
         if (ccw.distance >= distanceToEndOfTunnel)
         {
             float currentWeight = categoryWeightModifier(basePreferences, ccw.category);
             basePreferences.categoryWeights[ccw.category] = currentWeight * ccw.weightScale;
         }
     }
     return(basePreferences);
 }
Exemplo n.º 8
0
    public override void setup(TunnelSelectionPreferences prefs, TunnelPiece parent)
    {
        base.setup(prefs, parent);
        jumpExtension = Mathf.Clamp(((TunnelSpawnController.INSTANCE.getCurrentClearRun())) / 4, 0, maxJumpExtension);
        float difficultyBasedMaxJumpRise = Mathf.Lerp(0, maxJumpRise, (1 - (2 * TunnelSpawnController.INSTANCE.GetCurrentAverageDifficulty())));

        jumpRise = Mathf.Lerp(0, difficultyBasedMaxJumpRise, jumpExtension / maxJumpExtension);
        Debug.Log("Jump rise = " + jumpRise + ", Jump extension = " + jumpExtension + ", Ave Difficulty = " + TunnelSpawnController.INSTANCE.GetCurrentAverageDifficulty());
        jumpEnd.position = jumpEnd.position + (Vector3.forward * jumpExtension) + (Vector3.up * jumpRise);
        this.endOffset   = this.endOffset + (Vector3.forward * jumpExtension);
        this.endOffset   = this.endOffset + (Vector3.up * jumpRise);
    }
Exemplo n.º 9
0
    private HoleConfig getRandomConfig(TunnelSelectionPreferences prefs)
    {
        int loopBreaker = 0;

        while (true)
        {
            HoleConfig candidate = holeConfigs [Random.Range(0, holeConfigs.Length)];
            if (++loopBreaker > 30 || candidate.difficulty <= prefs.preferredDifficulty)
            {
                return(candidate);
            }
        }
    }
 private int getMaxDifficultyIndex(TunnelSelectionPreferences prefs)
 {
     //return the index one higher than the last allowed obstacleConfig based on difficulty
     //the first element should always be easy enough, otherwise the difficulty for the whole piece is easier than any config, therefore start at index 1
     for (int i = 1; i < difficultyMap.Length; i++)
     {
         if (difficultyMap [i] > prefs.preferredDifficulty)
         {
             return(i - 1);
         }
     }
     return(difficultyMap.Length - 1);        //if nothing too hard is found, any value can be picked
 }
Exemplo n.º 11
0
    private LaserConfig getRandomConfig(TunnelSelectionPreferences prefs)
    {
        int loopBreaker = 0;

        while (true)
        {
            LaserConfig candidate = laserConfigs [Random.Range(0, laserConfigs.Length)];
            if (++loopBreaker > 20 || candidate.difficultyLevel <= prefs.preferredDifficulty)
            {
                return(candidate);
            }
        }
    }
    private ObstacleConfig getRandomConfig(TunnelSelectionPreferences prefs)
    {
        int max = getMaxDifficultyIndex(prefs);
        //Debug.Log (cumulativeSumOfWeights.Length + ", " + max);
        float rand = Random.Range(0, cumulativeSumOfWeights [max]);

        for (int i = 0; i < obstacleConfigs.Length; i++)
        {
            if (cumulativeSumOfWeights[i] >= rand)
            {
                ObstacleConfig chosen = obstacleConfigs[i];
                return(chosen);
            }
        }

        //this also shouldn't happen
        return(obstacleConfigs [0]);
    }
Exemplo n.º 13
0
    public TunnelPiece takeWeightedRandomPieceFromPool(TunnelSelectionPreferences prefs)
    {
        float[] cumulativeSumOfWeights = new float[availablePool.Count];

        //Created a cumulative sum array based on piece weights for the supplied selection preferences
        float  weightSum    = 0;
        string weightedPool = "";

        for (int i = 0; i < availablePool.Count; i++)
        {
            TunnelPiece tp     = availablePool[i];
            float       weight = tp.calculateWeight(prefs);
            weightSum += weight;
            cumulativeSumOfWeights[i] = weightSum;

            if (Debug.isDebugBuild)
            {
                weightedPool = weightedPool + tp.name + ": " + weight + "\n";
            }
        }

        //Randomly select a piece based upon the weights calculated above (note that a zero weight can never be selected so the piece taken here is already guaranteed valid)
        float rand = Random.Range(0f, weightSum);

        for (int i = 0; i < availablePool.Count; i++)
        {
            if (cumulativeSumOfWeights[i] >= rand)
            {
                TunnelPiece chosen = takeFromPool(i);
                if (Debug.isDebugBuild)
                {
                    TunnelSpawnController.INSTANCE.debug.text = weightedPool
                                                                + "Chosen Piece: " + chosen.name + "\n"
                                                                + "Bucket Level: " + prefs.maxBucketLevel + "\n"
                                                                + "Max Difficulty: " + prefs.maxDifficulty;
                }
                return(chosen);
            }
        }

        //This shouldn't ever happen
        return(takeFromPool(0));
    }
Exemplo n.º 14
0
    //Not used
    private void extendDrop(TunnelSelectionPreferences prefs)
    {
        int randExtension = Random.Range(0, 20);

        randExtension = (int)(randExtension * Mathf.Clamp01(prefs.maxDifficulty));

        if (randExtension > 8)
        {
            dropExtension1.SetActive(true);
            dropPipes();
            if (randExtension > 15)
            {
                dropExtension2.SetActive(true);
                dropPipes();
                if (randExtension > 18)
                {
                    dropExtension3.SetActive(true);
                    dropPipes();
                }
            }
        }
    }
Exemplo n.º 15
0
    private void extendBody(TunnelSelectionPreferences prefs)
    {
        bodyConfiguration = Random.Range(0, 23);

        if (TunnelSpawnController.INSTANCE.getCurrentClearRun() > 60f)
        {
            bodyConfiguration = Mathf.Clamp(bodyConfiguration, 5, bodyConfiguration);
        }

        if (prefs.maxBucketLevel <= swerveBucketLevel)
        {
            bodyConfiguration = Mathf.Clamp(bodyConfiguration, 0, 10);
        }

        if (bodyConfiguration >= 5 && bodyConfiguration <= 10)
        {
            extendStraight();
        }
        else if (bodyConfiguration == 11)
        {
            extendSwerveRight();
        }
        else if (bodyConfiguration <= 13)
        {
            extendStraight();
            swerveRightExtensionLeft.transform.position  = swerveRightExtensionLeft.transform.position + (Vector3.forward * STRAIGHT_EXTENSION_DIST);
            swerveRightExtensionRight.transform.position = swerveRightExtensionRight.transform.position + (Vector3.forward * STRAIGHT_EXTENSION_DIST);
            extendSwerveRight();
        }
        else if (bodyConfiguration <= 15)
        {
            extendSwerveRight();
            extendSwerveRightStraight();
        }
        else if (bodyConfiguration == 16)
        {
            extendSwerveLeft();
        }
        else if (bodyConfiguration <= 18)
        {
            extendStraight();
            swerveLeftExtensionLeft.transform.position  = swerveLeftExtensionLeft.transform.position + (Vector3.forward * STRAIGHT_EXTENSION_DIST);
            swerveLeftExtensionRight.transform.position = swerveLeftExtensionRight.transform.position + (Vector3.forward * STRAIGHT_EXTENSION_DIST);
            extendSwerveLeft();
        }
        else if (bodyConfiguration <= 20)
        {
            extendSwerveLeft();
            extendSwerveLeftStraight();
        }
        else if (bodyConfiguration == 21)
        {
            extendSwerveLeft();
            extendSwerveLeftStraight();
            swerveRightExtensionLeft.transform.position  = swerveRightExtensionLeft.transform.position + (Vector3.forward * STRAIGHT_EXTENSION_DIST);
            swerveRightExtensionRight.transform.position = swerveRightExtensionRight.transform.position + (Vector3.forward * STRAIGHT_EXTENSION_DIST);
            swerveRightExtensionLeft.transform.position  = swerveRightExtensionLeft.transform.position + SWERVE_LEFT_EXTENSION_DIST;
            swerveRightExtensionRight.transform.position = swerveRightExtensionRight.transform.position + SWERVE_LEFT_EXTENSION_DIST;
            extendSwerveRight();
            extendSwerveRightStraight();
        }
        else if (bodyConfiguration == 22)
        {
            extendSwerveRight();
            extendSwerveRightStraight();
            swerveLeftExtensionLeft.transform.position  = swerveLeftExtensionLeft.transform.position + (Vector3.forward * STRAIGHT_EXTENSION_DIST);
            swerveLeftExtensionRight.transform.position = swerveLeftExtensionRight.transform.position + (Vector3.forward * STRAIGHT_EXTENSION_DIST);
            swerveLeftExtensionLeft.transform.position  = swerveLeftExtensionLeft.transform.position + SWERVE_RIGHT_EXTENSION_DIST;
            swerveLeftExtensionRight.transform.position = swerveLeftExtensionRight.transform.position + SWERVE_RIGHT_EXTENSION_DIST;
            extendSwerveLeft();
            extendSwerveLeftStraight();
        }
    }
Exemplo n.º 16
0
 public override void setup(TunnelSelectionPreferences prefs, TunnelPiece parent)
 {
     base.setup(prefs, parent);
     //extendDrop (prefs);
     extendBody(prefs);
 }
Exemplo n.º 17
0
    private float difficultyWeightModifier(TunnelSelectionPreferences prefs)
    {
        float difficultyGap = Mathf.Clamp01(Mathf.Abs(this.difficultyLevel - prefs.preferredDifficulty));

        return(1 - difficultyGap);
    }
Exemplo n.º 18
0
 public override void setup(TunnelSelectionPreferences prefs, TunnelPiece parent)
 {
     base.setup(prefs, parent);
     axisRot.enabled = (prefs.maxBucketLevel >= spinBucketLevel && Random.Range(0f, 2f) <= 1f);
 }
Exemplo n.º 19
0
 public override void setup(TunnelSelectionPreferences prefs, TunnelPiece parent)
 {
     base.setup(prefs, parent);
     configInUse = getRandomConfig(prefs);
     applyConfig(configInUse);
 }