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

Shorten GetNextBorderPoint code

parent 70a9adb1
No related branches found
No related tags found
No related merge requests found
......@@ -351,54 +351,22 @@ public class CoastlineGenerator : MonoBehaviour
private Vector2 GetNextBorderPoint(Vector2 pos, List<Vector2> newOrderedBorderPoints)
{
// check n-w-s-e
Vector2 north = pos + new Vector2(0, 1);
if (CheckIsNextOnBorder(north, newOrderedBorderPoints))
Vector2[] neighbourhood =
{
return north;
}
Vector2 west = pos + new Vector2(-1, 0);
if (CheckIsNextOnBorder(west, newOrderedBorderPoints))
{
return west;
}
Vector2 south = pos + new Vector2(0, -1);
if (CheckIsNextOnBorder(south, newOrderedBorderPoints))
{
return south;
}
Vector2 east = pos + new Vector2(1, 0);
if (CheckIsNextOnBorder(east, newOrderedBorderPoints))
{
return east;
}
// check diagonals
Vector2 northwest = pos + new Vector2(-1, 1);
if (CheckIsNextOnBorder(northwest, newOrderedBorderPoints))
{
return northwest;
}
Vector2 southwest = pos + new Vector2(-1, -1);
if (CheckIsNextOnBorder(southwest, newOrderedBorderPoints))
{
return southwest;
}
Vector2 southeast = pos + new Vector2(1, -1);
if (CheckIsNextOnBorder(southeast, newOrderedBorderPoints))
{
return southeast;
}
Vector2 northeast = pos + new Vector2(1, 1);
if (CheckIsNextOnBorder(northeast, newOrderedBorderPoints))
new Vector2(0, 1),
new Vector2(-1, 0),
new Vector2(0, -1),
new Vector2(1, 0),
new Vector2(-1, 1),
new Vector2(-1, -1),
new Vector2(1, -1),
new Vector2(1, 1)
};
foreach (Vector2 dir in neighbourhood)
{
return northeast;
if (CheckIsNextOnBorder(pos + dir, newOrderedBorderPoints))
return pos + dir;
}
return new Vector2(-1, -1);
......
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