Added rivers and lakes, fixed generation, fixed map colors, v.1.2.0
This commit is contained in:
@@ -11,6 +11,8 @@ public class Map : MonoBehaviour
|
||||
public Image forest;
|
||||
public Image stone;
|
||||
public Image spawn;
|
||||
public Image lake;
|
||||
public Image river;
|
||||
public Image[] mapTiles;
|
||||
|
||||
public void prepare(Dictionary<Vector3, GameObject> tiles, GameObject currentTile)
|
||||
@@ -62,6 +64,18 @@ public class Map : MonoBehaviour
|
||||
case "TreeTile":
|
||||
color = forest.color;
|
||||
break;
|
||||
case "RiverTile1":
|
||||
color = river.color;
|
||||
break;
|
||||
case "RiverTile2":
|
||||
color = river.color;
|
||||
break;
|
||||
case "RiverTile3":
|
||||
color = river.color;
|
||||
break;
|
||||
case "LakeTile":
|
||||
color = lake.color;
|
||||
break;
|
||||
default:
|
||||
color = spawn.color;
|
||||
break;
|
||||
|
||||
@@ -40,6 +40,30 @@ public class NoiseGenerator
|
||||
applyMesh(tile, vertices, mesh);
|
||||
}
|
||||
|
||||
public void applyRiverTileNoise(GameObject tile)
|
||||
{
|
||||
Mesh mesh = tile.GetComponent<MeshFilter>().mesh;
|
||||
Vector3[] vertices = mesh.vertices;
|
||||
float[] samples = calculateSamples(tile);
|
||||
for (int i = 0; i < samples.Length; i++)
|
||||
{
|
||||
vertices[i].y = samples[i] * 7.5f;
|
||||
}
|
||||
applyMesh(tile, vertices, mesh);
|
||||
}
|
||||
|
||||
public void applyLakeTileNoise(GameObject tile)
|
||||
{
|
||||
Mesh mesh = tile.GetComponent<MeshFilter>().mesh;
|
||||
Vector3[] vertices = mesh.vertices;
|
||||
float[] samples = calculateSamples(tile);
|
||||
for (int i = 0; i < samples.Length; i++)
|
||||
{
|
||||
vertices[i].y = samples[i] * 7.5f;
|
||||
}
|
||||
applyMesh(tile, vertices, mesh);
|
||||
}
|
||||
|
||||
public void applyCityTileNoise(GameObject tile)
|
||||
{
|
||||
//Currently no noise. (Objects floating)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user