private void UpdateCloud(Node node) { var nextnode = ForeGround[(int)MathHelper.Clamp(node.Postion.X - 1, 0, X - 1), (int)node.Postion.Y]; if (nextnode.Type.Type != NodeTypes.Cloud) { var temp = node.Type; node.SetType(temp.OldNodeType); nextnode.SetType(temp); nextnode.Updated = 20; return; } }
private void UpdateWater(Node node) { Node downNode = null; var x = (int)node.Postion.X; var y = (int)node.Postion.Y; if (V[x,y].Z == 0) { } for (int i = 0; i < dirs.Length; i++) { if (MyMath.IsBetween(x + (int)dirs[i].X, 0, X) && MyMath.IsBetween(y + (int)dirs[i].Y, 0, Y)) { downNode = ForeGround[x + (int)dirs[i].X, y + (int)dirs[i].Y]; if ((i == 0 && !downNode.Type.CanCollide) && downNode.Type.Type != node.Type.Type) { var temp = node.Type; node.SetType(temp.OldNodeType); downNode.SetType(temp); downNode.Updated = 10; return; } } } }
public void Init() { Data = new Node[2][,]; Data[0] = new Node[X, Y]; Data[1] = new Node[X, Y]; ForeGround = Data[0]; int i3 = 50; for (int i1 = 0; i1 < X; i1++) { double x = i1 / Size.X; double noise = Noise.NextOctave1D(1, x, 2.5f) / 5 + 0.5f; double noise3 = Math.Abs(Noise.NextOctave1D(2, x, 2.5f)); double noise2 = Math.Abs(Noise.NextOctave1D(3, x, noise3)) / 10; noise = MathHelper.Clamp((float)(noise + noise2* noise3), 0, 1); i3 = (int)(noise * (Y - 1)); if (i3 < 3) i3 = 3; var node = new Node { Value = noise, }; node.SetPosition(new Vector3(i1, i3, 0)); node.SetType( NodeFactory.Get(NodeTypes.Soil)); ForeGround[i1, i3] = node; for (int i2 = 0; i2< i3 - 3; i2++) { double y = i2 * 1.0 / i3; noise = 1 - Noise.NextOctave2DAbs(4, x, y) / 4; node = new Node { Value = noise, }; node.SetPosition(new Vector3(i1, i2, 0)); if (noise > 0.6f && noise < 0.7f && i2 < 20) { node.SetType(NodeFactory.Get(NodeTypes.EarthBack)); node.SetType(NodeFactory.Get(NodeTypes.Lava)); } else node.SetType(NodeFactory.Get(noise < 0.7f ? NodeTypes.Earth : NodeTypes.EarthBack)); ForeGround[i1, i2] = node; } for (int i2 = i3 - 3; i2 < i3; i2++) { node = new Node { Value = noise, }; node.SetPosition(new Vector3(i1, i2, 0)); node.SetType(NodeFactory.Get(NodeTypes.EarthBack)); node.SetType(NodeFactory.Get(NodeTypes.Soil)); ForeGround[i1, i2] = node; } for (int i2 = i3 + 1; i2 < Y; i2++) { double y = i2 / Size.Y; noise = Noise.NextOctave2DAbs(2, -x, -y); node = new Node { Value = noise, }; node.SetPosition(new Vector3(i1, i2, 0)); node.SetType(NodeFactory.Get(NodeTypes.Air, false)); ForeGround[i1, i2] = node; } } components = new List<IMapComponent> {lighting, /*new Clouds(),*/ new WaterSimulator(), new TextureModifier() }; foreach (var component in components) component.Init(ForeGround, X, Y); new StructureGen().Init(ForeGround, X, Y); }