public void RecalculateEdges(ContinentSimulation Sim) { foreach (ContinentPoint point in Points.Values) { List <ContinentPoint> neighbors = GetNeighbors(point); WorldPointContinent worldPoint = ContinentPointToWorldPoint(point, Sim); if (worldPoint == null) { continue; } if (neighbors.Count == 8) { point.Edge = false; } //check if edge if (worldPoint.Pos.x == 0 && worldPoint.Pos.y == 0) { if (neighbors.Count() == 3) { point.Edge = false; } } else if (worldPoint.Pos.x == 0 || worldPoint.Pos.y == 0) { if (neighbors.Count() == 5) { point.Edge = false; } } } }
void Update() { WorldPointContinents.Clear(); foreach (GameObject go in gos) { Destroy(go); } for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { WorldPointContinents.Add(new Vector2(x, y), new WorldPointContinent(new Vector2(x, y))); } } CreateContinents(); Dictionary <Vector2, float> md = MantleData.GetData(0, octaves, lac, pers, multi, Height, Width, zoom);; foreach (Continent c in Continents) { foreach (ContinentPoint cp in c.Points.Values) { WorldPointContinent wp = c.ContinentPointToWorldPoint(cp, this); float val = md[wp.Pos]; if (val < 0.12f) { cp.height = 0; } else if (val < 0.25f) { cp.height = 1; } else if (val < 0.37f) { cp.height = 2; } else if (val < 0.5f) { cp.height = 3; } else if (val < 0.62f) { cp.height = 4; } else if (val < 0.75f) { cp.height = 5; } else if (val < 0.87f) { cp.height = 6; } else { cp.height = 8; } } } ColorMap(); }
public ContinentPoint WorldPointContinentToContinentPoint(WorldPointContinent wp, Continent plate) { if (!plate.Points.ContainsKey(wp.Pos - plate.WorldPointCenter.Pos)) { return(null); } return(plate.Points[wp.Pos - plate.WorldPointCenter.Pos]); }
public void CreateContinents() { int Ocean = WorldPointContinents.Count; int Land = 0; //for (int i = 0; i < 7; i++) while (true) { Continent cont = new Continent(new WorldPointContinent(new Vector2(Random.Range(0, Width), Random.Range(0, Height)))); Continents.Add(cont); Dictionary <Vector2, bool> Map = new ZoomLandCreation(5, 5).Create(3); int width = (int)Map.Select(p => p.Key.x).Max() / (int)2; List <Vector2> LandPoints = new List <Vector2>(); foreach (var pair in Map) { if (pair.Value) { LandPoints.Add(pair.Key); } } foreach (var p in LandPoints) { ContinentPoint cp = new ContinentPoint(p - new Vector2(width, width), cont); if (cont.Points.ContainsKey(p - new Vector2(width, width))) { continue; } cont.Points.Add(p - new Vector2(width, width), cp); WorldPointContinent wp = cont.ContinentPointToWorldPoint(cp, this); if (wp != null && wp.contPoint == null) { wp.contPoint = cp; Land++; Ocean--; } } if ((float)Land / (float)(Ocean + Land) > 0.3f) { break; } } foreach (WorldPointContinent wp in WorldPointContinents.Values) { GameObject go = Instantiate(cubePrefab); go.transform.position = wp.Pos; go.GetComponent <MeshRenderer>().material = Resources.Load <Material>("green"); go.GetComponent <MeshRenderer>().material.color = wp.contPoint == null ? Color.blue : Color.green; wp.go = go; } }
public void CreateContinents() { List <Vector2> ContinentPoints = new List <Vector2>() { new Vector2(30, 30), new Vector2(51, 65), new Vector2(106, 53), new Vector2(106, 23), new Vector2(140, 34), new Vector2(138, 74) }; for (int i = 0; i < 6; i++) { Continent cont = new Continent(new WorldPointContinent(new Vector2(ContinentPoints[i].x, Height - ContinentPoints[i].y))); Continents.Add(cont); Dictionary <Vector2, bool> Map = new Dictionary <Vector2, bool>(); while (Map.Count < 2300) { Map = new ZoomLandCreation(5, 5).Create(4); } int width = (int)Map.Select(p => p.Key.x).Max() / (int)2; List <Vector2> LandPoints = new List <Vector2>(); foreach (var pair in Map) { if (pair.Value) { LandPoints.Add(pair.Key); } } foreach (var p in LandPoints) { ContinentPoint cp = new ContinentPoint(p - new Vector2(width, width), cont); if (cont.Points.ContainsKey(p - new Vector2(width, width))) { continue; } cont.Points.Add(p - new Vector2(width, width), cp); WorldPointContinent wp = cont.ContinentPointToWorldPoint(cp, this); if (wp != null && wp.contPoint == null) { wp.contPoint = cp; } } } foreach (WorldPointContinent wp in WorldPointContinents.Values) { GameObject go = Instantiate(cubePrefab); go.transform.position = wp.Pos; go.GetComponent <MeshRenderer>().material = Resources.Load <Material>("green"); go.GetComponent <MeshRenderer>().material.color = wp.contPoint == null ? Color.blue : Color.green; wp.go = go; gos.Add(go); } }
public void AdditionalSubduction(WorldPointContinent origSubductionPoint, Continent subductingContinent, Continent growingContinent) { //if (Random.Range(0, 2) == 0) { if (WorldPointContinents.ContainsKey(origSubductionPoint.Pos + subductingContinent.driftDirection)) { WorldPointContinent AddedHeightPoint = WorldPointContinents[origSubductionPoint.Pos + subductingContinent.driftDirection]; ContinentPoint cp = WorldPointContinentToContinentPoint(AddedHeightPoint, growingContinent); if (cp != null) { cp.height++; } } } }
public Vector2 WorldPointContinentToContinentPointVector2(WorldPointContinent wp, Continent plate) { return(wp.Pos - plate.WorldPointCenter.Pos); }
public void Move(Continent continent) { Vector2 direction = Vector2.zero; int offWorldPoints = 0; int offWorldPointDirection = 0; foreach (ContinentPoint point in continent.Points.Values) { WorldPointContinent wpc = continent.ContinentPointToWorldPoint(point, this); if (wpc == null) { offWorldPoints++; offWorldPointDirection += (point.Pos + continent.WorldPointCenter.Pos).y > 0 ? -1 : 1; continue; } wpc.contPoint = null; } if (offWorldPoints > 10) { continent.driftDuration = Random.Range(5, 15); continent.driftDirection = new Vector2(Random.Range(-1, 2), offWorldPointDirection > 0 ? 1 : -1); } if (continent.driftDuration == 0) { float val = 0; continent.driftDuration = Random.Range(5, 15); val = Random.Range(0f, 100f) / 100f; if (val < 0.12f) { direction = new Vector2(-1, 0); } else if (val < 0.25f) { direction = new Vector2(-1, -1); } else if (val < 0.37f) { direction = new Vector2(0, -1); } else if (val < 0.5f) { direction = new Vector2(1, -1); } else if (val < 0.62f) { direction = new Vector2(1, 0); } else if (val < 0.75f) { direction = new Vector2(1, 1); } else if (val < 0.87f) { direction = new Vector2(0, 1); } else { direction = new Vector2(-1, 1); } continent.driftDirection = direction; } else { continent.driftDuration--; direction = continent.driftDirection; } //float val = MantleData.GetData(age, octaves, lac, pers, multi)[continent.WorldPointCenter.Pos]; Vector2 newPoint = continent.WorldPointCenter.Pos + direction; if (newPoint.x > 99) { newPoint += new Vector2(-Width, 0); } if (newPoint.x < 0) { newPoint += new Vector2(Width, 0); } if (newPoint.y < 0 || newPoint.y > 99) { return;//continue; } continent.WorldPointCenter = WorldPointContinents[newPoint]; }
public void RecalculateWorldPointContinents(Continent Cont) { //foreach (Continent plate in Plates) { Dictionary <ContinentPoint, ContinentPoint> Collisions = new Dictionary <ContinentPoint, ContinentPoint>(); foreach (ContinentPoint point in Cont.Points.Values) { WorldPointContinent wp = Cont.ContinentPointToWorldPoint(point, this); if (wp != null) { if (wp.contPoint != null) { Collisions.Add(wp.contPoint, point); } else { wp.contPoint = point; } } } foreach (Continent collCont in Collisions.Select(p => p.Key.cont).Distinct()) { Dictionary <ContinentPoint, ContinentPoint> ContinentCollisionPoints = Collisions.Where(p => p.Key.cont == collCont).ToDictionary(p => p.Key, p => p.Value); if (ContinentCollisionPoints.Count < 10) //if ((float)ContinentCollisionPoints.Count / (float)collCont.Points.Count < 0.025f) { foreach (var pair in ContinentCollisionPoints) { //not big enough to be collision, smaller one subducts WorldPointContinent wp = collCont.ContinentPointToWorldPoint(pair.Key, this); ContinentPoint theirPoint = pair.Key; ContinentPoint ourPoint = pair.Value; if (Cont.GetNeighbors(ourPoint).Count < 3) { //island or something, we give it to them theirPoint.height += 2; Cont.Points.Remove(ourPoint.Pos); /*Vector2 worldPosition = collCont.WorldPointCenter.Pos + theirPoint.Pos; * ContinentPoint theirNewPoint = new ContinentPoint(worldPosition - Cont.WorldPointCenter.Pos, Cont); * theirNewPoint.height = theirPoint.height; * if (!collCont.Points.ContainsKey(theirNewPoint.Pos)) * { * collCont.Points.Add(theirNewPoint.Pos, theirNewPoint); * WorldPointContinent wp2 = collCont.ContinentPointToWorldPoint(theirNewPoint, this); * if (wp2 != null) * wp2.contPoint = theirNewPoint; * }*/ // if(Random.Range(0,2) == 0) AdditionalSubduction(wp, Cont, collCont); } else if (collCont.GetNeighbors(theirPoint).Count < 3) { //we are colliding with an island ourPoint.height += 2; wp.contPoint = ourPoint; collCont.Points.Remove(theirPoint.Pos); /* Vector2 worldPosition = collCont.WorldPointCenter.Pos + theirPoint.Pos; * ContinentPoint ourNewPoint = new ContinentPoint(worldPosition - Cont.WorldPointCenter.Pos, Cont); * ourNewPoint.height = theirPoint.height; * if (!Cont.Points.ContainsKey(ourNewPoint.Pos)) * { * Cont.Points.Add(ourNewPoint.Pos, ourNewPoint); * WorldPointContinent wp2 = Cont.ContinentPointToWorldPoint(ourNewPoint, this); * if (wp2 != null) * wp2.contPoint = ourNewPoint; * }*/ AdditionalSubduction(wp, collCont, Cont); } else if (ourPoint.height > theirPoint.height) //cont already there subducts { ourPoint.height += 2; wp.contPoint = ourPoint; collCont.Points.Remove(theirPoint.Pos); // if (Random.Range(0, 2) == 0) AdditionalSubduction(wp, collCont, Cont); } else //our cont subducts { theirPoint.height += 2; Cont.Points.Remove(ourPoint.Pos); //if (Random.Range(0, 2) == 0) AdditionalSubduction(wp, Cont, collCont); } } } else { //big enough, the continents become one //first fix collision points foreach (var pair in ContinentCollisionPoints) { WorldPointContinent wp = collCont.ContinentPointToWorldPoint(pair.Key, this); ContinentPoint theirPoint = pair.Key; ContinentPoint ourPoint = pair.Value; wp.contPoint = ourPoint; ourPoint.height++; collCont.Points.Remove(theirPoint.Pos); AdditionalSubduction(wp, collCont, Cont); } //then move their cont points to our continent foreach (ContinentPoint theirPoint in collCont.Points.Values) { Vector2 worldPosition = collCont.WorldPointCenter.Pos + theirPoint.Pos; ContinentPoint ourNewPoint = new ContinentPoint(worldPosition - Cont.WorldPointCenter.Pos, Cont); ourNewPoint.height = theirPoint.height; if (!Cont.Points.ContainsKey(ourNewPoint.Pos)) { Cont.Points.Add(ourNewPoint.Pos, ourNewPoint); WorldPointContinent wp = Cont.ContinentPointToWorldPoint(ourNewPoint, this); if (wp != null) { wp.contPoint = ourNewPoint; } } } DeletedContinents.Add(collCont); } } } }
public Continent(WorldPointContinent center) { WorldPointCenter = center; Points.Add(new Vector2(0, 0), new ContinentPoint(new Vector2(0, 0), this)); }