Skip to content
Snippets Groups Projects
Commit 5d80c58c authored by Julian Thijssen's avatar Julian Thijssen
Browse files

Make beach agent a little more normal

parent a99668f2
No related branches found
No related tags found
No related merge requests found
......@@ -126,30 +126,56 @@ public class BeachAgent : MonoBehaviour
}
}
void SmoothBeaches(Heightmap heightmap, Texture2D colormap, List<Vector2Int> beaches)
void MoveToAdjacentLand(Heightmap heightmap)
{
List<Vector2Int> adjacency = new List<Vector2Int>();
adjacency.Add(new Vector2Int(-1, 0));
adjacency.Add(new Vector2Int(1, 0));
adjacency.Add(new Vector2Int(0, -1));
adjacency.Add(new Vector2Int(0, 1));
Shuffle(adjacency);
for (int i = 0; i < 4; i++)
{
Vector2Int newPos = pos + adjacency[i];
if (heightmap.isLand(newPos))
{
pos = newPos;
return;
}
}
}
void ExpandBeaches(Heightmap heightmap, Texture2D colormap, List<Vector2Int> beaches)
{
foreach (Vector2Int beach in beaches)
{
pos = beach;
float height = beachHeight;
for (int x = 0; x < heightmap.getSize(); x++)
for (int i = 0; i < 100; i++)
{
for (int y = 0; y < heightmap.getSize(); y++)
{
Vector2Int p = new Vector2Int(x, y);
float dist = (Vector2Int.Distance(pos, p) / heightmap.getSize()) * Random.Range(8, 12);
if (isLand(heightmap, p) && dist < 0.4f)
{
float pixelHeight = heightmap.GetPixel(p.x, p.y);
float newHeight = height;
heightmap.SetPixel(p.x, p.y, newHeight);
colormap.SetPixel(p.x, p.y, new Color(0.8f, 0.8f, 0.4f, 1.0f));
}
}
MoveToAdjacentLand(heightmap);
heightmap.SetPixel(pos.x, pos.y, beachHeight);
colormap.SetPixel((int) pos.x, (int) pos.y, new Color(0.8f, 0.8f, 0.4f, 1.0f));
}
// for (int x = 0; x < heightmap.getSize(); x++)
// {
// for (int y = 0; y < heightmap.getSize(); y++)
// {
// Vector2Int p = new Vector2Int(x, y);
// float dist = (Vector2Int.Distance(pos, p) / heightmap.getSize()) * Random.Range(8, 12);
// if (isLand(heightmap, p) && dist < 0.4f)
// {
// float pixelHeight = heightmap.GetPixel(p.x, p.y);
// float newHeight = height;
// heightmap.SetPixel(p.x, p.y, newHeight);
// colormap.SetPixel(p.x, p.y, new Color(0.8f, 0.8f, 0.4f, 1.0f));
// }
// }
// }
}
}
......@@ -166,13 +192,13 @@ public class BeachAgent : MonoBehaviour
heightmap.SetPixel(pos.x, pos.y, beachHeight);
List<Vector2Int> beaches = new List<Vector2Int>();
for (int i = 0; i < 25; i++)
for (int i = 0; i < 200; i++)
{
MoveAlongCoast(heightmap);
heightmap.SetPixel(pos.x, pos.y, beachHeight);
beaches.Add(pos);
}
SmoothBeaches(heightmap, colormap, beaches);
ExpandBeaches(heightmap, colormap, beaches);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment