//checks if the user has gone through the tutorial for how to use powerUps public void CheckForPowerUpTutorial() { if (ActivatePowerUp.PowerUpsUnlocked() && PlayerPrefs.GetInt(GlobalVars.GATHERING_TUTORIAL_WATCHED_POWER_UP) == 0 && PlayerPrefs.GetInt(GlobalVars.GATHERING_TUTORIAL_WATCHED_SWIPE) == 1 && !GlobalVars.PAUSED) { // Stops the game from starting normally. spawning = false; this.GetComponent <CollectionTimer>().SetIsCountingDown(false); CreatePowerUpTutorial(); } }
public static void UnlockAllPowerups() { ActivatePowerUp.UnlockAllPowerups(); }
// Generate 2 random numbers which relate to the lane and element both ranging from 1 - 4 -- doesn't allow generation of an element into its respective lane -- tries to limit the same element spawning repeatitly private void generateLaneAndElem() { randomSpawnedLane = Random.Range(0, 4); if (spawnOneTypeOnly) //disables random generation if the generation is set to one element only (from powerup) { if (Random.Range(0, GlobalVars.NUMBER_OF_LANES + 1) == GlobalVars.NUMBER_OF_LANES) //retains the one in five chance that the element is a powerup { randomSpawnedElement = GlobalVars.NUMBER_OF_LANES; } else //otherwise, that element spawns as the set element { randomSpawnedElement = oneTypeSpawnIndex; } return; } else //continues through the script to generate elements pseudorandomely otherwise //sets whether or not you can spawn powerups, based on whether you have any unlocked and whether the tutorials have ended { int spawnMaxIndex = (hasTutorialElementSpawned || Utility.PlayerPrefIntToBool(GlobalVars.GATHERING_TUTORIAL_WATCHED_SWIPE) || Utility.PlayerPrefIntToBool(GlobalVars.GATHERING_TUTORIAL_WATCHED_POWER_UP)) && ActivatePowerUp.PowerUpsUnlocked() ? GlobalVars.NUMBER_OF_LANES + 1 : GlobalVars.NUMBER_OF_LANES; //determines the randomely spawned element randomSpawnedElement = Random.Range(0, spawnMaxIndex); } if (spawnedElements != null && spawnedElements.Count >= 5) { spawnedElements.Dequeue(); } if (lanesUsed != null && lanesUsed.Count >= 5) { lanesUsed.Dequeue(); } if (spawnedElements != null && spawnedElements.Contains(randomSpawnedElement)) { foreach (int i in spawnedElements) { if (i == randomSpawnedElement) { duplicateElementCounter++; if (duplicateElementCounter >= 2) { duplicationRandomSpawnedElement = randomSpawnedElement; duplicateElementCounter = 0; break; } } } if (randomSpawnedElement == duplicationRandomSpawnedElement) { while (randomSpawnedElement == duplicationRandomSpawnedElement) { randomSpawnedElement = Random.Range(0, GlobalVars.NUMBER_OF_LANES); } } //spawnedElements.Clear(); } if (lanesUsed != null && lanesUsed.Contains(randomSpawnedLane)) { foreach (int i in lanesUsed) { if (i == randomSpawnedLane) { duplicateElementCounter++; if (duplicateElementCounter >= 2) { duplicationRandomSpawnedLane = randomSpawnedLane; duplicateElementCounter = 0; break; } } } if (randomSpawnedLane == duplicationRandomSpawnedLane) { while (randomSpawnedLane == duplicationRandomSpawnedLane) { randomSpawnedLane = Random.Range(0, GlobalVars.NUMBER_OF_LANES); } } //lanesUsed.Clear(); } if (randomSpawnedElement == randomSpawnedLane) { while (randomSpawnedElement == randomSpawnedLane) { randomSpawnedLane = Random.Range(0, GlobalVars.NUMBER_OF_LANES); } } spawnedElements.Enqueue(randomSpawnedElement); lanesUsed.Enqueue(randomSpawnedLane); //if a powerUp was spawned, increment the counter if (randomSpawnedElement == GlobalVars.NUMBER_OF_LANES) { if (powerUpCounter < powerUpsPerRound) { powerUpCounter++; } else //spawn something that isn't a powerUp { randomSpawnedElement = Random.Range(0, GlobalVars.NUMBER_OF_LANES); } } }
// Use this for initialization void Start() { // ----- CHEATS ----- \\ //ActivatePowerUp.UnlockAllPowerups (); //Cheats.UnlockAllElements(); // ----- CHEATS ----- \\ animators[0] = animators[0].GetComponent <Animator>(); animators [1] = animators [1].GetComponent <Animator> (); animators [2] = animators [2].GetComponent <Animator> (); animators [3] = animators [3].GetComponent <Animator> (); animators [0].SetTrigger("finishedLoading"); arrayOfPlayerPrefs = new string[4]; arrayOfPlayerPrefs [0] = PlayerPrefs.GetString("ELEMENT1", "fire"); arrayOfPlayerPrefs [1] = PlayerPrefs.GetString("ELEMENT2", "water"); arrayOfPlayerPrefs [3] = PlayerPrefs.GetString("ELEMENT3", "earth"); arrayOfPlayerPrefs [2] = PlayerPrefs.GetString("ELEMENT4", "air"); //sets player prefs if they have not been set PlayerPrefs.SetString("ELEMENT1", PlayerPrefs.GetString("ELEMENT1", "fire")); PlayerPrefs.SetString("ELEMENT2", PlayerPrefs.GetString("ELEMENT2", "water")); PlayerPrefs.SetString("ELEMENT3", PlayerPrefs.GetString("ELEMENT3", "earth")); PlayerPrefs.SetString("ELEMENT4", PlayerPrefs.GetString("ELEMENT4", "air")); // Setting the player given sprites element1.transform.GetChild(0).GetComponent <SpriteRenderer> ().sprite = Resources.Load <Sprite> (GlobalVars.FILE_PATH + arrayOfPlayerPrefs [0]); collectionPot1.transform.GetChild(1).GetChild(0).GetComponent <SpriteRenderer> ().sprite = (elementSprites[0] = Resources.Load <Sprite> (GlobalVars.FILE_PATH + arrayOfPlayerPrefs [0])); element2.transform.GetChild(0).GetComponent <SpriteRenderer> ().sprite = Resources.Load <Sprite> (GlobalVars.FILE_PATH + arrayOfPlayerPrefs [1]); collectionPot2.transform.GetChild(1).GetChild(0).GetComponent <SpriteRenderer> ().sprite = (elementSprites[1] = Resources.Load <Sprite> (GlobalVars.FILE_PATH + arrayOfPlayerPrefs [1])); element3.transform.GetChild(0).GetComponent <SpriteRenderer> ().sprite = Resources.Load <Sprite> (GlobalVars.FILE_PATH + arrayOfPlayerPrefs [3]); collectionPot3.transform.GetChild(1).GetChild(0).GetComponent <SpriteRenderer> ().sprite = (elementSprites[3] = Resources.Load <Sprite> (GlobalVars.FILE_PATH + arrayOfPlayerPrefs [2])); element4.transform.GetChild(0).GetComponent <SpriteRenderer> ().sprite = Resources.Load <Sprite> (GlobalVars.FILE_PATH + arrayOfPlayerPrefs [2]); collectionPot4.transform.GetChild(1).GetChild(0).GetComponent <SpriteRenderer> ().sprite = (elementSprites[2] = Resources.Load <Sprite> (GlobalVars.FILE_PATH + arrayOfPlayerPrefs [3])); // End of setting player given sprites elements[0] = element1; elements[1] = element2; elements[2] = element3; elements[3] = element4; if (elements.Length > 4) { elements [4] = powerUp; } // At the start assign the lanes but create a method to change the lanes positions lanes [0] = LanePositions.GetLanePositions(9f, -1)[0]; lanes [1] = LanePositions.GetLanePositions(9f, -1)[1]; lanes [2] = LanePositions.GetLanePositions(9f, -1)[2]; lanes [3] = LanePositions.GetLanePositions(9f, -1)[3]; scoreTexts[0] = elementText1; scoreTexts[1] = elementText2; scoreTexts[2] = elementText3; scoreTexts[3] = elementText4; //reset powerUpCounter (number of powerUps seen in a given round) powerUpCounter = 0; powerUpsPerRound = 3; //difficulty setting defaultSpawnModifier = defaultFallSpeedModifier = 1; //0.6f + (0.9f * GlobalVars.NUMBER_ELEMENTS_UNLOCKED / ((float)GlobalVars.ELEMENTS.Count)); creationFrequency = 60f + (140f * GlobalVars.NUMBER_ELEMENTS_UNLOCKED / ((float)GlobalVars.ELEMENTS.Count)); elementMovementSpeed = 2 + (0.3f * GlobalVars.NUMBER_ELEMENTS_UNLOCKED / ((float)GlobalVars.ELEMENTS.Count)); // 0.6f + (0.9f * GlobalVars.NUMBER_ELEMENTS_UNLOCKED / ((float)GlobalVars.ELEMENTS.Count)); CollectionTimer.instance.setBaseCreationFrequency(creationFrequency); CollectionTimer.instance.setBaseMovementSpeed(elementMovementSpeed); fallSpeedModifiers = new float [GlobalVars.NUMBER_OF_LANES]; //sets the fallSpeedModifiers to default for (int i = 0; i < fallSpeedModifiers.Length; i++) { fallSpeedModifiers[i] = defaultFallSpeedModifier; } //sets the spawnRateModifiers to default values spawnRateModifier = defaultSpawnModifier; //saves the starting values of fall speed and spawn rate initialCreationFrequency = creationFrequency; initialElementMovementSpeed = elementMovementSpeed; #if DEBUG powerUp1 = new BucketShield(2); PowerUp.ResetPowerUpLevel(powerUp1); #endif // Bools for tutorial checks isElementGiven = false; isSecondElementGiven = false; hasTutorialElementSpawned = false; timeToPowerUp = false; GlobalVars.SWIPE_TUTORIAL_FIRST_SPAWNED = false; //generates the powerups ActivatePowerUp.GenerateAllPowerups(); ActivatePowerUp.GenerateUnlockedPowerups(); // Instantiating the arrays for the power up tutorial tutorialElements = new GameObject[6]; powerUpTutorialPosition = new Vector3[6]; elementNumbers = new int[6]; CheckForPowerUpTutorial(); }