Added rivers and lakes, fixed generation, fixed map colors, v.1.2.0

This commit is contained in:
Nicola Sovic
2022-03-16 19:57:26 +01:00
parent 5c35760f70
commit 4fa95617c2
57 changed files with 2361 additions and 67 deletions

View File

@@ -7,7 +7,10 @@ using UnityEngine.UI;
public class WorldGenerator : MonoBehaviour
{
public GameObject player;
public GameObject[] prefabs;
public GameObject[] prefabsHighProbability; // 50%
public GameObject[] prefabsMiddleProbability; // 35%
public GameObject[] prefabsLowProbability; // 10%
public GameObject[] prefabsLowestProbability; // 5%
Dictionary<Vector3, GameObject> tiles;
GameObject currentTile;
List<GameObject> renderedTiles;
@@ -81,48 +84,30 @@ public class WorldGenerator : MonoBehaviour
Vector3 pos = currentTile.GetComponent<Tile>().needConnectedTile(playerX, playerZ);
if (!tiles.ContainsKey(pos) && pos.y == 0)
{
int index;
int chance = rand.Next(1,101);
while (true)
GameObject[] usedArray;
if (chance > 50)
{
if (chance < 50)
{
index = 0;
}
else if (chance >= 50 && chance < 70)
{
index = 1;
}
else if (chance >= 70 && chance < 90)
{
index = 2;
}
else
{
index = 3;
}
if (index == 3)
{
if (cityAmount > 0)
{
cityAmount--;
break;
}
else
{
chance = rand.Next(1, 101);
}
}
else
{
break;
}
usedArray = prefabsHighProbability;
}
else if (chance > 15 && chance <= 50)
{
usedArray = prefabsMiddleProbability;
}
else if (chance > 5 && chance <= 15)
{
usedArray = prefabsLowProbability;
}
else
{
usedArray = prefabsLowestProbability;
}
int index = rand.Next(0, usedArray.Length);
Vector3 mapPos = new Vector3(pos.x * 100, 0, pos.z * 100);
GameObject newTile = Instantiate(prefabs[index], mapPos, Quaternion.identity);
string name = prefabs[index].name;
GameObject newTile = Instantiate(usedArray[index], mapPos, Quaternion.identity);
string name = usedArray[index].name;
if (name.Contains("_"))
{
name = name.Split('_')[0];
@@ -162,6 +147,18 @@ public class WorldGenerator : MonoBehaviour
case "citytile":
noise.applyCityTileNoise(tile);
break;
case "rivertile1":
noise.applyRiverTileNoise(tile);
break;
case "rivertile2":
noise.applyRiverTileNoise(tile);
break;
case "rivertile3":
noise.applyRiverTileNoise(tile);
break;
case "laketile":
noise.applyLakeTileNoise(tile);
break;
}
}