void renderLevel() { //generate the map for the game to read makeMap(); tileHolder = new GameObject("Map").transform; //bx = gameObject.AddComponent<BoxCollider2D>(); //tileHolder.gameObject.AddComponent(bx); defaultLayer = new GameObject("Plains").transform; defaultLayer.transform.SetParent(tileHolder); waterLayer = new GameObject("Water").transform; waterLayer.transform.SetParent(tileHolder); //get and show the actual tree TileWeight int[] treeTileWeight = new int[treeTiles.Length]; for (int i = 0; i < treeTileWeight.Length; i++) { treeTileWeight[i] = 100 / (i + 1); } //initalize the mountain rendering list Group[] mountainGroups = groupTiles(currentMap, new Mountain()); //debugging line to determine mountain groups /*for(int mtnCnt = 0; mtnCnt < mountainGroups.Length; mtnCnt++) * Debug.Log(mountainGroups[mtnCnt].getLoc().getX() + " " + mountainGroups[mtnCnt].getLoc().getY() + " " + mountainGroups[mtnCnt].getX() + " " + mountainGroups[mtnCnt].getY() + " ");*/ //make all locations of the specific tile type for (int xPos = 0; xPos < currentMap.getX(); xPos++) { for (int yPos = 0; yPos < currentMap.getY(); yPos++) { GameObject toInitialize = nullTile; GameObject aesthetic = null; GameObject mountain = null; GameObject smoothingLayer = null; GameObject[] gradientLayer = new GameObject[4]; switch (currentMap.get(xPos, yPos).getType()) { //initialize plains here case '*': toInitialize = plainsTiles [rng.nextInt(plainsTiles.Length)]; aesthetic = plainsSprites[rng.nextInt(plainsSprites.Length)]; //now determine what is next to the plainsTiles if (hasNeighbor(xPos, yPos, new Trees())) { /*bool[] surroundingForests = neighborDirection(xPos, yPos, new Trees()); * for(int i = 0; i < gradientLayer.Length; i++) * { * if(surroundingForests[2 * i] && surroundingForests[2 * i + 2]) * gradientLayer[i] = insideEdgeGradient[rng.nextInt(insideEdgeGradient.Length)]; * else if(surroundingForests[2 * i]) * gradientLayer[i] = rightEdgeGradient[rng.nextInt(insideEdgeGradient.Length)]; * else if(surroundingForests[2 * i + 2]) * gradientLayer[i] = leftEdgeGradient[rng.nextInt(insideEdgeGradient.Length)]; * else if(surroundingForests[2 * i + 1]) * gradientLayer[i] = outsideEdgeGradient[rng.nextInt(insideEdgeGradient.Length)]; * else * gradientLayer[i] = null; * }*/ } break; //initialize forests case '^': toInitialize = treeTiles[rng.weightedInt(treeTileWeight)]; if (hasNeighbor(xPos, yPos, new River())) { aesthetic = treeSpritesNearWater[rng.nextInt(treeSpritesNearWater.Length)]; } else { aesthetic = treeSprites[rng.nextInt(treeSprites.Length)]; } bool[] surroundingForests = neighborDirection(xPos, yPos, new Trees()); for (int i = 0; i < gradientLayer.Length; i++) { if (surroundingForests[2 * i] && surroundingForests[2 * i + 1] && surroundingForests[2 * i + 2]) { gradientLayer[i] = fullGradient[rng.nextInt(insideEdgeGradient.Length)]; } else if (surroundingForests[2 * i] && surroundingForests[2 * i + 2]) { gradientLayer[i] = insideEdgeGradient[rng.nextInt(insideEdgeGradient.Length)]; } else if (surroundingForests[2 * i]) { gradientLayer[i] = leftEdgeGradient[rng.nextInt(insideEdgeGradient.Length)]; } else if (surroundingForests[2 * i + 2]) { gradientLayer[i] = rightEdgeGradient[rng.nextInt(insideEdgeGradient.Length)]; } else { gradientLayer[i] = outsideEdgeGradient[rng.nextInt(insideEdgeGradient.Length)]; } } break; //here be mountains case 'A': for (int mtnCnt = 0; mtnCnt < mountainGroups.Length; mtnCnt++) { if (xPos == mountainGroups[mtnCnt].getLoc().getX() && yPos == mountainGroups[mtnCnt].getLoc().getY()) { if (mountainGroups[mtnCnt].getX() == 1 && mountainGroups[mtnCnt].getY() == 1) { mountain = mountainTops1_1[rng.nextInt(mountainTops1_1.Length)]; } else if (mountainGroups[mtnCnt].getY() >= 2) //implies large volumus mountains { mountain = mountainTops2_2[rng.nextInt(mountainTops2_2.Length)]; //now add mountains spaced 16px -or- .5 units apart untill cannot anymore /*for(int mtnI = 0; mtnI < mountainGroups[mtnCnt].getY(); mtnI++) * for(int mtnL = 1; mtnL < (mountainGroups[mtnCnt].getX() - 1)* (1 / mountainScale); mtnL++) * { * GameObject newMountain; * newMountain = Instantiate (mountain, new Vector3 (xPos + mtnL * 1f * mountainScale, yPos + mtnI, 8 + (.0078125f * mtnL) + (.03125f * mtnI * 2)), Quaternion.identity) as GameObject; * }//*/ } else if (mountainGroups[mtnCnt].getX() >= 2) //implies long straight mountains { mountain = mountainTops2_1[rng.nextInt(mountainTops2_1.Length)]; //now add mountains spaced 16px -or- .5 units apart untill cannot anymore /*for(int mtnL = 1; mtnL < (mountainGroups[mtnCnt].getX() - 1)* (1 / mountainScale); mtnL++) * { * GameObject newMountain; * newMountain = Instantiate (mountain, new Vector3 (xPos + mtnL * 1f * mountainScale, yPos, 8 + (.03125f * mtnL)), Quaternion.identity) as GameObject; * }//*/ } else { mountain = mountainTops1_1[rng.nextInt(mountainTops1_1.Length)]; } mtnCnt++; } } if (!(new Mountain()).equals(getNeighbor(xPos, yPos, (int)directions.Down))) { aesthetic = footHills[rng.nextInt(footHills.Length)]; } toInitialize = mountainTiles [rng.nextInt(mountainTiles.Length)]; break; //initialize hills case 'n': toInitialize = hillTiles [rng.nextInt(hillTiles.Length)]; aesthetic = hillSprites [rng.nextInt(hillSprites.Length)]; break; //initialize water case '_': toInitialize = nullTile; //riverTiles [rng.Range (0, riverTiles.Length)]; if (hasNeighbor(xPos, yPos, new Trees(), new Plains(), new Mountain(), new House(), new Hill())) { bool[] surroundingTiles = neighborDirection(xPos, yPos, new Trees(), new Plains(), new Mountain(), new House(), new Hill()); for (int i = 0; i < gradientLayer.Length; i++) { if (surroundingTiles[2 * i] && surroundingTiles[2 * i + 2]) { gradientLayer[i] = insideEdgeGradient[rng.nextInt(insideEdgeGradient.Length)]; } else if (surroundingTiles[2 * i]) { gradientLayer[i] = leftEdgeGradient[rng.nextInt(insideEdgeGradient.Length)]; } else if (surroundingTiles[2 * i + 2]) { gradientLayer[i] = rightEdgeGradient[rng.nextInt(insideEdgeGradient.Length)]; } else if (surroundingTiles[2 * i + 1]) { gradientLayer[i] = outsideEdgeGradient[rng.nextInt(insideEdgeGradient.Length)]; } else { gradientLayer[i] = null; } } } break; //initialize a house case 'H': toInitialize = houseTiles [rng.nextInt(houseTiles.Length)]; break; //initialize road tiles case '-': toInitialize = roadTiles [rng.nextInt(roadTiles.Length)]; break; //initialize a bridge case 'B': toInitialize = bridgeTiles [rng.nextInt(bridgeTiles.Length)]; break; default: toInitialize = nullTile; break; } GameObject newInstance = null; //floor layer if (toInitialize != null) { newInstance = Instantiate(toInitialize, new Vector3(xPos, yPos, 9), Quaternion.identity) as GameObject; newInstance.transform.SetParent(tileHolder); } //water layer GameObject water = Instantiate(waterTile, new Vector3(xPos, yPos, 10), Quaternion.identity) as GameObject; water.transform.SetParent(newInstance.GetComponent <Transform>()); //mountain layer if (mountain != null) { GameObject mountainInitialize = Instantiate(mountain, new Vector3(xPos, yPos, 8), Quaternion.identity) as GameObject; if (newInstance != null) { mountainInitialize.transform.SetParent(newInstance.GetComponent <Transform>()); } } //gradients layer for (int i = 0; i < gradientLayer.Length; i++) { if (gradientLayer[i] != null) { GameObject gradientInitialize = Instantiate(gradientLayer[i], new Vector3(xPos, yPos, 7), Quaternion.identity) as GameObject; gradientInitialize.transform.Rotate(Vector3.back * 90 * (i)); Color transparent = gradientInitialize.GetComponent <SpriteRenderer>().color; transparent.a = 2f; gradientInitialize.GetComponent <SpriteRenderer>().color = transparent; if (newInstance != null) { gradientInitialize.transform.SetParent(newInstance.GetComponent <Transform>()); } } } //aesthetic layer if (aesthetic != null) { float xError = (float)(((int)Random.Range(-6, 6)) / 32.0); float yError = (float)(((int)Random.Range(-6, 6)) / 32.0); GameObject aestheticInstance = Instantiate(aesthetic, new Vector3(xPos + xError, yPos + yError, 6), Quaternion.identity) as GameObject; aestheticInstance.transform.SetParent(newInstance.GetComponent <Transform>()); } } } }