public float[] GetChance() { DevController.MeasureElapsedTimeStart(); previousLevelChances = (float[])currentLevelChances.Clone(); // TODO: how to make it scalable if (GenerateFirstChances()) { return(currentLevelChances); } else if (GenerateSecondChances()) { return(currentLevelChances); } else if (GenerateThirdChances()) { return(currentLevelChances); } else { GenerateFourthChances(); } DevController.MeasureElapsedTimeEnd("Generate chance"); return(currentLevelChances); }
public static void UpdateSprites() { DevController.MeasureElapsedTimeStart(); RemoveExtraChances(); GenerateNewSprites(); DevController.MeasureElapsedTimeEnd("Ore cracking"); void RemoveExtraChances() { for (int ore = 0; ore < Constants.oresAmount; ore++) { if (crackedOres[ore, 0, 0] != null && ChancesGenerator.currentLevelChances[ore] == 0) { Debug.Log("remove " + ore); for (int i = 0; i < crackedOres.GetLength(1); i++) { for (int j = 0; j < crackedOres.GetLength(2); j++) { crackedOres[ore, i, j] = null; } } } } Resources.UnloadUnusedAssets(); } void GenerateNewSprites() { for (int ore = 0; ore < Constants.oresAmount; ore++) { if (crackedOres[ore, 0, 0] == null && ChancesGenerator.currentLevelChances[ore] != 0) { for (int i = 0; i < crackedOres.GetLength(1); i++) { for (int j = 0; j < crackedOres.GetLength(2); j++) { GenerateOre(ore, i, j); } } } } } void GenerateOre(int ore, int texture, int crackingStage) { _mainTexture = Resources.Load <Sprite>($"OresSprites/{ore + 1}/{texture + 1}"); Merge(_crackingSprites[crackingStage], texture); crackedOres[ore, texture, crackingStage] = _finalSprite; } }
private void GenerateLevelPrefab(bool newLevel, string seed = null) { DevController.MeasureElapsedTimeStart(); if (newLevel) { _randomCaveGenerator.GenerateRandom(); player.transform.position = _randomCaveGenerator.playerSpawnPoint; } else { _randomCaveGenerator.LoadLevel(seed); } DevController.MeasureElapsedTimeEnd("Generate level"); }
public void GenerateOres(bool newOres) { DevController.MeasureElapsedTimeStart(); _emptyPoints = GenerateLevel.GetEmptyPoints(); _emptyPointsIndex = 0; values = chancesGenerator.GetChance(); if (values.Sum() != 100) { Debug.LogError("ERROR"); } if (newOres) // generate new ores { randNumbers = new float[GridBehavior.WIDTH, GridBehavior.HEIGHT]; var spawnPointIndex = _gridBehaviour.GetArrayIndex(player.transform.position); for (int x = 0; x < GridBehavior.WIDTH; x++) { for (int y = 0; y < GridBehavior.HEIGHT; y++) { if (Math.Abs(spawnPointIndex.x - x) > 9 || Math.Abs(spawnPointIndex.y - y) > 6) { randNumbers[x, y] = -1; continue; } if (new Vector3Int(x, y, 0) == _gridBehaviour.GetArrayIndex(_emptyPoints[_emptyPointsIndex])) { _gridBehaviour.InstantiateNewGridPrefab(_emptyPoints[_emptyPointsIndex]); randNumbers[x, y] = -1; if (_emptyPointsIndex < _emptyPoints.Length - 1) { _emptyPointsIndex++; } } else { GenerateOre(x, y); } } } } else // load old ores { Debug.Log("load ores"); for (int x = 0; x < GridBehavior.WIDTH; x++) { for (int y = 0; y < GridBehavior.HEIGHT; y++) { if (_gridBehaviour.gridArray[x, y] == null && _gridBehaviour.descentPos != new Vector2(x, y) && randNumbers[x, y] != -1) { GenerateOre(x, y, randNumbers[x, y]); } } } NextLevelLoadController.needsToLoadNextLevel = false; } DevController.MeasureElapsedTimeEnd("Ore generation"); }