public void Update(Node node) { if (node.Type.Type == NodeTypes.Cloud) { if (node.Updated > 0) node.Updated--; else UpdateCloud(node); } }
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; } }
public void Init(Node[,] foreGround, int X, int Y) { ForeGround = foreGround; this.X = X; this.Y = Y; rand = new Random(); for (int i1 = 0; i1 < X; i1++) for (int i2 = Y / 2; i2 < Y; i2++) { double x = (double)i1 / X; double y = (double)i2 / Y; int oct = 5; double noise = Math.Sin(Noise.NextOctave2D(oct, x, y) / oct - 0.2)*2; if (noise > 0.0f) { NodeType cloud = NodeFactory.Get(NodeTypes.Cloud); cloud.Opacity = (float)noise / 5; //cloud.Opacity ForeGround[i1, i2].SetType(cloud); } } }
public void Init(Node[,] foreGround, int x, int y) { ForeGround = foreGround; X = x; Y = y; for (int i1 = 0; i1 < X; i1++) { for (int i2 = Y - 1; i2 >= 0; i2--) { var node = ForeGround[i1, i2]; node.TypeChanged += new Node.NodeEventHandler(UpdateNodeNeighboursTexture); if (ForeGround[i1, i2].Type.Type == NodeTypes.Earth || ForeGround[i1, i2].Type.Type == NodeTypes.Water || ForeGround[i1, i2].Type.Type == NodeTypes.Soil) UpdateNodeTexure(ForeGround[i1, i2]); } } }
private void lightUp(Node node) { Vector3 sum = new Vector3(); Vector3 eSum = new Vector3(); float count = 1; float ecount = 1; sum += LightField[0][(int)(node.Postion.X), (int)(node.Postion.Y)]; eSum += LightField[1][(int)(node.Postion.X), (int)(node.Postion.Y)]; for (int i2 = 0; i2 < Utils.Rays.Length; i2++) { int x = (int)(node.Postion.X + Utils.Rays[i2].X); int y = (int)(node.Postion.Y + Utils.Rays[i2].Y); if (MyMath.IsBetween(x, 0, X) && MyMath.IsBetween(y, 0, Y)) { Node hit = ForeGround[x, y]; if ((hit.LType & LightType.Direct) == LightType.Direct) { sum += LightField[0][x, y] * hit.LightDirection[i2]; } else if (hit.Type.Opacity != 1 || node.Type.Opacity != 1) { sum += LightField[0][x, y]; eSum += LightField[1][x, y]; } count += 1; } else { //if (node.Type == NodeType.Air) // sum += Sky; //count++; } } node.Incident = (sum / count); node.Emmision = eSum / count; }
public static Vector3 DiffuseAmbientLight(Node node) { return (node.Incident); }
public void Init(Node[,] foreGround, int X, int Y) { ForeGround = foreGround; this.X = X; this.Y = Y; int[] kd = new int[15]; Vector3 min = new Vector3(20, 0, 0); Vector3 max = new Vector3(70, 50, 0); addPoint(min, max, 0); }
public void Update(Node node) { if (node.Type.Type == NodeTypes.Water || node.Type.Type == NodeTypes.Lava) { if (node.Updated > 0) node.Updated--; else UpdateWater(node); } }
public static void Water(Node node, Entity player, Vector3 speed) { }
public static void Slowdown(Node node, Entity player, Vector3 speed) { player.Speed = speed / 2; }
public static void RightSlope(Node node, Entity player, Vector3 speed) { BoundingBox b = new BoundingBox(player.CollisionBox.Min + speed, player.CollisionBox.Max + speed); Ray r = new Ray(node.Postion - new Vector3(0.5f, 0.5f, 0), new Vector3(0.5f, 0.5f, 0)); float? dist = r.Intersects(b); if (dist == null) return; if (b.Max.X > node.CollisionBox.Max.X || b.Max.Y <= node.CollisionBox.Min.Y + 0.1f) { HardCollision(node, player, speed); return; } Ray r2 = new Ray(new Vector3(b.Max.X, b.Min.Y, 0), new Vector3(-0.5f, 0.5f, 0)); var c1 = r.Position.Y - r.Position.X; var c2 = r2.Position.X; var dir = new Vector3(r2.Position.X, (c1 + c2), 0) - r2.Position; // (c1 + c2) / 2 - c1, var finalSpeed = speed + dir; player.Speed = finalSpeed; player.Force.Y = -finalSpeed.Y + player.Gravity; }
public static void HardCollision(Node node, Entity player, Vector3 speed) { /* var delta = (player.Postion + speed - node.Postion); var dir = new Vector3(Math.Abs(delta.X)> Math.Abs(delta.Y) * player.Size.Y ? Math.Sign(delta.X) : 0, Math.Abs(delta.X)> Math.Abs(delta.Y) * player.Size.Y ? 0 : Math.Sign(delta.Y), 0); var dist = new Vector3(delta.X - dir.X * (node.Size.X + player.Size.X) / 2, delta.Y - dir.Y * (node.Size.Y + player.Size.Y) / 2, 0); var nDir = Vector3.Dot(dir, dist); var finalSpeed = speed - nDir * dir; player.Speed = finalSpeed; if (dir.Y == 1) player.Force.Y = player.Gravity;*/ var delta = (player.Postion + speed - node.Postion); delta = new Vector3(Math.Abs(delta.X) > Math.Abs(delta.Y) ? Math.Sign(delta.X) : 0, Math.Abs(delta.X) > Math.Abs(delta.Y) ? 0 : Math.Sign(delta.Y), 0); var nV = Vector3.Dot(delta, speed); player.Speed = speed - MathHelper.Min(nV, 0) * delta; }
public static void FreeMotion(Node node, Entity player, Vector3 speed) { player.Force.Y = player.Gravity; }
public static Vector3 DiffuseLight(Node node) { return node.Incident; }
public void UpdateNodeNeighboursTexture(Node node) { int nodeX = (int)node.Postion.X; int nodeY = (int)node.Postion.Y; if (node.Type.Type == NodeTypes.Earth || node.Type.Type == NodeTypes.Water || node.Type.Type == NodeTypes.Soil) UpdateNodeTexure(node); for (int i = 0; i < Utils.Rays.Length; i += 2) { int x = (nodeX + (int)Utils.Rays[i].X); int y = (nodeY + (int)Utils.Rays[i].Y); if (MyMath.IsBetween(x, 0, X) && MyMath.IsBetween(y, 0, Y)) { Node neighbour = ForeGround[x, y]; if (neighbour.Type.Type == NodeTypes.Earth || neighbour.Type.Type == NodeTypes.Water || neighbour.Type.Type == NodeTypes.Soil) UpdateNodeTexure(neighbour); } } if (node.Type.Type == NodeTypes.Earth) { int i = 1; bool cont = true; do { if (MyMath.IsBetween(nodeX, 0, X) && MyMath.IsBetween(nodeY - i, 0, Y)) { var n2 = ForeGround[nodeX, nodeY - i]; if (n2.Type.CanRender == false ) { n2.Type.CanRender = true; i++; } else if (n2.Type.OldNodeType != null && n2.Type.OldNodeType.CanRender == false) { n2.Type.OldNodeType.CanRender = true; i++; } else cont = false; } else cont = false; } while (cont); } }
public void UpdateNodeTexure(Node node) { int nodeX = (int)node.Postion.X; int nodeY = (int)node.Postion.Y; string texture = ""; for (int i = 0; i < Rays2.Length; i++) { int x = (nodeX + (int)Rays2[i].X); int y = (nodeY + (int)Rays2[i].Y); if (MyMath.IsBetween(x, 0, X) && MyMath.IsBetween(y, 0, Y)) { Node neighbour = ForeGround[x, y]; if (neighbour.Type.Type == node.Type.Type) texture += "0"; else texture += "1"; } else texture += "1"; } node.Type.SetTexture(texture); if (node.Type.Type == NodeTypes.Soil) { node.Type.Decals.Clear(); if (texture == "0011") { node.Type.ResolveCollision = NodeFactory.LeftSlope; node.Type.Decals.Clear(); } else if (texture == "1001") { node.Type.ResolveCollision = NodeFactory.RightSlope; } else { node.Type.ResolveCollision = NodeFactory.HardCollision; if (texture[3] == '1') { var grass = DecalFactory.Get(DecalType.Grass); grass.Init(node); node.Type.AddDecals(grass); } } } }
public void Init(Node node) { foreach (var dec in Decals) dec.Init(node); }
public void Init(Node[,] foreGround, int x, int y) { ForeGround = foreGround; X = x; Y = y; waterSource = new Vector3(50, 50, 0); V = new Vector3[X, Y]; D = new int[X, Y]; }
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); }
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(Node[,] foreGround, int x, int y) { ForeGround = foreGround; X = x; Y = y; LightField = new Vector3[2][,]; LightField[0] = new Vector3[X, Y]; LightField[1] = new Vector3[X, Y]; Relief = new int[x]; sun = new DirectionalLight { Direction = new Vector3(-0.5f, -0.5f, 0), ForeGround = foreGround, X = x, Y = y, Relief = Relief }; sky = new SkyLight { ForeGround = foreGround, X = x, Y = y, Relief = Relief}; for (int i1 = 0; i1 < X; i1++) { bool set = false; for (int i2 = Y - 1; i2 >= 0; i2--) { var node = ForeGround[i1, i2]; node.TypeChanged += UpdateRelief; if (!set && node.Type.Opacity > 0) { Relief[i1] = i2; set = true; } } } }
public void Update(Node node) { }
public void Update(Node node) { lightUp(node); }
public void UpdateRelief(Node node) { int nodeX = (int)node.Postion.X; int nodeY = (int)node.Postion.Y; if (node.Type.Opacity > 0) { if (Relief[nodeX] < nodeY) Relief[nodeX] = nodeY; } else { if (Relief[nodeX] == nodeY) { } } sun.Update(node); foreach (var light in lights) { light.Update(node); } }
public void Init(Node node) { Node = node; SetPosition(node.Postion + RelativePosition); }