public void GenerateMap() { if(holder != null) { GameObject.Destroy(holder); } holder = new GameObject("Holder"); spawner.holder = holder; GameManager.Instance.holder = holder; powerupBag = new Utils.GrabBag<Effect>(); powerupBag.AddItems(possibleEffects, possibleEffectWeights); undermap.ClearAllTiles(); tilemap.ClearAllTiles(); bad.ClearAllTiles(); int colorIndex = (int) (GameManager.Instance.depth / 200f); colorIndex = Mathf.Min(colorIndex, colorsPer200.Length - 1); var color = colorsPer200[colorIndex]; tilemap.color = color; undermap.color = color; player = GameManager.Instance.player; var genPerlinMoss = new GeneratorPerlin(System.DateTime.Now.Millisecond + 12, 1, 0.3f, 0.05f, 2, 2); var genPerlinDecorger = new GeneratorPerlin(System.DateTime.Now.Millisecond + 12, 1, 0.3f, 0.05f, 2, 2); var depth = GameManager.Instance.depth; float perlinFreq = 0.05f * perlinFreqSc.Evaluate(depth); var pr = perlinRoughness.Evaluate(depth); float perlinFreqMulti = 2f * pr; float perlinPersistence = 0.5f * pr; float ridgedFreq = 0.05f * ridgedFreqSc.Evaluate(depth); var rr = ridgedRoughness.Evaluate(depth); float ridgedFreqMulti = 2f * rr; float ridgedPersistence = 0.5f * rr; float bpFreq = 0.05f * bpFreqSc.Evaluate(depth); var bpr = bpRoughness.Evaluate(depth); float bpFreqMulti = 2f * bpr; float bpPersistence = 0.5f * bpr; float blend1Freq = 0.02f * blend1FreqSc.Evaluate(depth); float blend2Freq = 0.03f * blend2FreqSc.Evaluate(depth); var genPerlin = new GeneratorPerlin(System.DateTime.Now.Millisecond, 1, perlinPersistence, perlinFreq, perlinFreqMulti, 4); var genRidged = new GeneratorRidged(System.DateTime.Now.Millisecond + 1, 1, ridgedPersistence, ridgedFreq, ridgedFreqMulti, 4); var genBPBil = new GeneratorBillowed(System.DateTime.Now.Millisecond + 2, 1, bpPersistence, bpFreq, bpFreqMulti, 4); var genBPRidge = new GeneratorRidged(System.DateTime.Now.Millisecond + 3, 1, bpPersistence, bpFreq, bpFreqMulti, 4); var genBP = new GeneratorDivide(new GeneratorAdd(genBPBil, genBPRidge), new GeneratorConstant(2f)); var genBlend1 = new GeneratorAdd(new GeneratorPerlin(System.DateTime.Now.Millisecond + 4, 0.5f, 0.5f, 0.02f, 2, 1), new GeneratorConstant(1)); var genBlend2 = new GeneratorAdd(new GeneratorPerlin(System.DateTime.Now.Millisecond + 5, 0.5f, 0.5f, 0.03f, 2, 1), new GeneratorConstant(1)); var genBlended1 = new GeneratorBlend(genRidged, genBP, genBlend2); var generator = new GeneratorBlend(genBlended1, genPerlin, genBlend1); hardness.hardness = new int[width * height]; hardness.width = width; hardness.height = height; TileBase[] tilesCollision = new TileBase[width * height]; TileBase[] tilesUnder = new TileBase[width * height]; for(int i = 0; i < width - 1; i++) { for(int j = 0; j < height - 1; j++) { var circleFunction = ((i - width / 2) / (float) width) * ((i - width / 2) / (float) width) + ((j - height / 2) / (float) height) * ((j - height / 2) / (float) height); circleFunction *= circleFunctionStrength; var pos = new Vector2(i, j); var signal = generator.GetNoise2D(pos) - circleFunction; var index = i + j * width; if(genPerlinMoss.GetNoise2D(pos) < -0.22f) { if(hardness.hardness[index] == 0) undermap.SetTile(new Vector3Int(i, j, 1), moss); if(hardness.hardness[index + 1] == 0) undermap.SetTile(new Vector3Int(i + 1, j, 1), moss); if(hardness.hardness[index + width] == 0) undermap.SetTile(new Vector3Int(i, j + 1, 1), moss); if(hardness.hardness[index + width + 1] == 0) undermap.SetTile(new Vector3Int(i + 1, j + 1, 1), moss); } if(signal < stoneThreshhold) { tilesCollision[i + j * width] = stone; tilesCollision[(i + 1) + j * width] = stone; tilesCollision[i + (j + 1) * width] = stone; tilesCollision[(i + 1) + (j + 1) * width] = stone; undermap.SetTile(new Vector3Int(i, j, 1), null); undermap.SetTile(new Vector3Int(i + 1, j, 1), null); undermap.SetTile(new Vector3Int(i, j + 1, 1), null); undermap.SetTile(new Vector3Int(i + 1, j + 1, 1), null); hardness.hardness[index] = 1; hardness.hardness[index + 1] = 1; hardness.hardness[index + width] = 1; hardness.hardness[index + width + 1] = 1; } tilesUnder[i + j * width] = grass; var decorChance = genPerlinDecorger.GetNoise2D(pos); if(decorChance < 0f) { if(rand.RandomChance(Mathf.Abs(decorChance) * 0.1f) && hardness.hardness[index] == 0) { undermap.SetTile(new Vector3Int(i, j, 2), decor[rand.RandomIntLessThan(decor.Length)]); } } if(decorChance > 0f) { if(rand.RandomChance(Mathf.Abs(decorChance) * 0.05f) && hardness.hardness[index] == 0) { bad.SetTile(new Vector3Int(i, j, 0), deadly[rand.RandomIntLessThan(deadly.Length)]); undermap.SetTile(new Vector3Int(i, j, 1), null); } } } } tilemap.SetTilesBlock(new BoundsInt(0, 0, 0, width, height, 1), tilesCollision); undermap.SetTilesBlock(new BoundsInt(0, 0, 0, width, height, 1), tilesUnder); var chosenX = 100; var chosenY = 100; for(int i = 0; i < 20; i++) { for(int j = 0; j < 20; j++) { int x = 100 + i; int y = 100 + j; int col = 0; for(int ii = -1; ii <= 1; ii++) { for(int jj = -1; jj <= 1; jj++) { col += hardness.hardness[x + ii + (y + jj) * width]; } } if(bad.GetTile(new Vector3Int(x, y, 0)) == null && col == 0) { player.transform.position = new Vector3(x + 0.5f, y + 0.5f, -5f); chosenX = x; chosenY = y; break; } } } var playerPos = new Vector2Int(chosenX, chosenY); var walkPos = new Vector2Int(chosenX, chosenY); Walk(playerPos, walkPos); player.tilemap = tilemap; player.hardness = hardness; var numDepth = numUpgradeShrinesPerDepth.Evaluate(GameManager.Instance.depth); for(int i = 0; i < numDepth; i++) { TryPlaceShrine(); } var numBomb = rand.RandomIntInRange(numBombPickup.x, numBombPickup.y); for(int i = 0; i < numBomb; i++) { TryPlaceBomb(); } var numWater = Mathf.CeilToInt(numWaterPickups.Evaluate(GameManager.Instance.depth)); for(int i = 0; i < numWater; i++) { if(rand.RandomChance(chanceWaterPickup.Evaluate(GameManager.Instance.depth))) { TryPlaceWater(); } } }
protected void Start() { rand = new SRandom((uint)System.DateTime.Now.Millisecond); enemyBag = new GrabBag <int>(); enemyBag.AddItems(enemyIndex, enemyWeights); }