public void RecalculateWorldPoints(TectonicPlate plate) { //foreach (TectonicPlate plate in Plates) { List <TectonicPoint> badPoints = new List <TectonicPoint>(); foreach (TectonicPoint point in plate.Points.Values) { WorldPoint wp = plate.TectonicPointToWorldPoint(point); if (wp != null) { bool continueAfter = true; if (wp.TecPoint != null) { //one plate subducts TectonicPoint otherPlatePoint = wp.TecPoint; if (otherPlatePoint.age > point.age) { //the other plate is older and more dense, and that one subducts otherPlatePoint.plate.Points.Remove(otherPlatePoint.Pos); List <TectonicPoint> neighbors = otherPlatePoint.plate.GetNeighbors(otherPlatePoint); foreach (TectonicPoint n in neighbors) { otherPlatePoint.plate.SubductionForce += n.Pos - otherPlatePoint.Pos; } } else { //this plate is older and more dense, this one subducts badPoints.Add(point); continueAfter = false; List <TectonicPoint> neighbors = plate.GetNeighbors(point); foreach (TectonicPoint n in neighbors) { plate.SubductionForce += n.Pos - point.Pos; } } } if (continueAfter) { wp.TecPoint = point; } } } foreach (TectonicPoint badPoint in badPoints) { plate.Points.Remove(badPoint.Pos); } } foreach (TectonicPoint point in plate.Points.Values) { WorldPoint wp = plate.TectonicPointToWorldPoint(point); if (wp != null) { wp.go.GetComponent <MeshRenderer>().material.color = point.plate.c; } } plate.WorldPointCenter.go.GetComponent <MeshRenderer>().material.color = Color.black; }
public void Move(TectonicPlate plate) { foreach (TectonicPoint tp in plate.Points.Values) { WorldPoint wp = plate.TectonicPointToWorldPoint(tp); if (wp == null) { continue; } wp.OldTectonicPoint = tp; wp.TecPoint = null; } Vector2 plateDirection = plate.SubductionForce.normalized; foreach (TectonicPoint point in plate.Points.Values.Where(p => p.Edge)) { WorldPoint wp = plate.TectonicPointToWorldPoint(point); if (wp == null) { continue; } // if (md.MantleHeat[wp.Pos]) //if the mantle is hot, move plates away { List <TectonicPoint> neighbors = plate.GetNeighbors(point); foreach (TectonicPoint n in neighbors) { plateDirection += (n.Pos - point.Pos) / 10f; } } } float maxVal = Mathf.Max(Mathf.Abs(plateDirection.normalized.x), Mathf.Abs(plateDirection.normalized.y)); if (maxVal == 0) { return; } Vector2 direction = plateDirection.normalized * 1 / maxVal;//new Vector2(Random.Range(-1, 2), Random.Range(-1, 2)); direction = new Vector2((int)direction.x, (int)direction.y); Vector2 newPoint = plate.WorldPointCenter.Pos + direction; if (newPoint.x > 99) { newPoint += new Vector2(-100, 0); } if (newPoint.x < 0) { newPoint += new Vector2(100, 0); } if (newPoint.y < 0 || newPoint.y > 99) { return;//continue; } plate.WorldPointCenter = WorldPoints[newPoint]; plate.SubductionForce = Vector2.zero; }