void GeneratePlanterBox(int numberOfTiles) { // Create seperate platform for them int plantIndex; if (gameManager.ShouldCreateNextPlantBox(out plantIndex)) { var level = currentLevel + Random.Range(3, 4); var xPos = Random.Range(0, numberOfTiles) + generatorManager.LastBlockX; GameObject nextBlock = RunnerObject.GetRunnerObject(block.gameObject); nextBlock.transform.position = new Vector3(xPos, level - 1, 0); nextBlock.SetActive(true); var newBox = PlanterBox.GetPlanterObject(plantingBox); newBox.SetIndex(plantIndex); newBox.transform.position = new Vector3(xPos + 1, level, 0); newBox.gameObject.SetActive(true); nextBlock = RunnerObject.GetRunnerObject(block.gameObject); nextBlock.transform.position = new Vector3(xPos + 2, level - 1, 0); nextBlock.SetActive(true); nextBlock = RunnerObject.GetRunnerObject(block.gameObject); nextBlock.transform.position = new Vector3(xPos + 1, level - 1, 0); nextBlock.SetActive(true); } }
private void OnTriggerExit2D(Collider2D other) { RunnerObject obstacle = other.GetComponent <RunnerObject>(); if (!obstacle) { return; } overlappingObjects.Remove(obstacle); }
public void Generate() { foreach (var runner in FindObjectsOfType <RunnerObject>()) { runner.Remove(); } for (int i = -manager.ScreenAmountX; i < manager.ScreenAmountX / 2; i++) { GameObject nextBlock = RunnerObject.GetRunnerObject(startingBlock.gameObject); nextBlock.transform.position = new Vector3(i, 0, 0); nextBlock.SetActive(true); } generatorManager.LastBlockX = manager.ScreenAmountX / 2 - 1; }
void GenerateNextBlock() { int currentIntDifficulty = (int)gameManager.Difficulty; if (lastDifficulty != currentIntDifficulty) { lastDifficulty = currentIntDifficulty; float change = Random.Range(-1, 2); if (Mathf.Abs(change) != 0) { change *= Random.Range(0.5f, 1.0f); currentLevel = Mathf.Clamp(currentLevel + change, minLevel, maxLevel); } } holes.Clear(); rises.Clear(); int amountToGenerate = (int)(generatorManager.ScreenAmountX * 2); int numberOfHoles = Random.Range(0, Mathf.Max(generatorManager.ScreenAmountX / 2, (int)(gameManager.Difficulty * 2))); int tries = 0; while (tries++ < maxTries && numberOfHoles > 0) { var index = Random.Range(1, amountToGenerate); if (canHaveDrop(index, amountToGenerate)) { numberOfHoles--; holes.Add(index); } } int numberOfRises = Random.Range(1, Mathf.Min(generatorManager.ScreenAmountX, (int)(gameManager.Difficulty))); tries = 0; while (tries++ < maxTries && numberOfRises > 0) { var index = Random.Range(0, amountToGenerate); if (!holes.Contains(index)) { numberOfRises--; rises.Add(index); } } GeneratePlanterBox(amountToGenerate); GenerateCoins(amountToGenerate); // Generate for (int i = 0; i < amountToGenerate; i++) { var xPosition = generatorManager.LastBlockX + 1; generatorManager.LastBlockX = xPosition; if (holes.Contains(i)) { generatorManager.LastBlockX += 1; continue; } GameObject nextBlock = RunnerObject.GetRunnerObject(block.gameObject); if (rises.Contains(i)) { int change = Random.Range(0, 1) == 1 ? 1 : -1; currentLevel = Mathf.Clamp(currentLevel + change, minLevel, maxLevel); } nextBlock.transform.position = new Vector3(xPosition, currentLevel, 0); nextBlock.SetActive(true); } }