// ---- scrGenerator ---- protected override void Generate() { if (PlayerController.Instance.LightScore == 0) { return; // Do not generate if player has no light. } // Check for a free position. Vector2 position; for (int i = 0; i < Mathf.Min(GENERATIONS_MIN + GENERATION_INCREASE_PER_LIGHT, GENERATIONS_MAX); ++i) { --generationsUntilLargeTree; --generationsUntilLog; if (generationsUntilLargeTree <= 0) { if (GetFreePosition(out position, scrLandscape.Instance.HighestPoint.y - (scrLandscape.Instance.HighestPoint.y - scrLandscape.Instance.LowestPoint.y) * 0.2f, scrLandscape.Instance.MaxHeight, 200)) { pools["Large Trees"].Create(position.x, position.y); generationsUntilLargeTree = Random.Range(GENERATIONS_UNTIL_LARGE_TREE_MIN, GENERATIONS_UNTIL_LARGE_TREE_MAX + 1); continue; } } if (generationsUntilLog <= 0) { // Create logs from the bottom of the hill to half way up. if (GetFreePosition(out position, (scrLandscape.Instance.HighestPoint.y - scrLandscape.Instance.LowestPoint.y) * 0.6f)) { pools["Logs"].Create(position.x, position.y); generationsUntilLog = Random.Range(GENERATIONS_UNTIL_LOG_MIN, GENERATIONS_UNTIL_LOG_MAX + 1); continue; } } // Anything else. if (GetFreePosition(out position, maxHeight: scrLandscape.Instance.HighestPoint.y - (scrLandscape.Instance.HighestPoint.y - scrLandscape.Instance.LowestPoint.y) * 0.2f)) { // Choose an obstacle to generate. scrPoolable obstacle = null; switch (Random.Range(0, 3)) { case 0: obstacle = pools["Plant Clusters"].Create(position.x, position.y, 16); break; case 1: obstacle = pools["Trees and Shrubs"].Create(position.x, position.y); break; case 2: obstacle = pools["Pillars and Rocks"].Create(position.x, position.y); break; } } } distanceRequired = Mathf.Max(DISTANCE_MAX - DISTANCE_REDUCTION_PER_LIGHT * PlayerController.Instance.LightScore, DISTANCE_MIN); // Reduce the distance required by the amount of light the player has. }
public scrPoolable Create(params object[] initParams) { if (index != Capacity) { // Activate and initialise the item. scrPoolable item = pool[index]; item.gameObject.SetActive(true); item.Init(initParams); // Shift the index to the next available item. index = links[index]; --Remaining; return(item); } return(null); }
// ---- scrGenerator ---- protected override void Generate() { if (PlayerController.Instance.LightScore == 0) { return; // Do not generate if player has no light. } // Check for a free position. Vector2 position; if (GetFreePosition(out position)) { // Choose an powerup to generate. scrPowerup.Powerup effect = (scrPowerup.Powerup)Random.Range(0, 4); // Generate the powerup. scrPoolable powerup = pool.Create(position.x, position.y, effect); } distanceRequired = Mathf.Max(DISTANCE_MAX - DISTANCE_REDUCTION_PER_LIGHT * PlayerController.Instance.LightScore, DISTANCE_MIN); // Reduce the distance required by the amount of light the player has. }