public WaterRipples(Game Game, Vector2f Size, int Gap = 90, int LineThickness = 8, Color Colour = default(Color)) { this.Game = Game; //Colour = new Color(94, 190, 255, 255); // Generate Points int GAP_HALF = Gap / 2; int yc = 0; for (int py = -GAP_HALF; py < Size.Y + Gap; py += Gap) { Points.Add(new List <WaterRipplePoint>()); for (int px = -GAP_HALF; px < Size.X + Gap; px += Gap) { WaterRipplePoint p = new WaterRipplePoint(px, py); if (Points[yc].Count != 0) { p.PointLeft = Points[yc][Points[yc].Count - 1]; } if (yc != 0) { p.PointAbove = Points[yc - 1][Points[yc].Count]; } Points[yc].Add(p); } yc++; } // add random additional points int yCount = Points.Count; for (int py = 1; py < yCount; py++) { int xCount = Points[py].Count; int px; for (px = 1; px < xCount; px++) { // add random additional points along the y axis (just add them at the end of the current x List) if (Utils.RandomInt(0, 3) == 0) { continue; } WaterRipplePoint pointY = new WaterRipplePoint(Points[py][px].X + (Utils.RandomInt((int)(Gap * 0.1), (int)(Gap * 0.4)) * (Utils.RandomInt() == 1 ? 1 : -1)), Points[py][px].Y + GAP_HALF); pointY.PointAbove = Points[py][px]; Points[py].Add(pointY); if (py < Points.Count - 1) { Points[py + 1][px].PointAbove = pointY; } } for (px = 1; px < xCount; px++) { // add random additional points along the x axis if (Utils.RandomInt(0, 3) == 0) { continue; } WaterRipplePoint pointX = new WaterRipplePoint(Points[py][px - 1].X + GAP_HALF, Points[py][px].Y + (Utils.RandomInt((int)(Gap * 0.1), (int)(Gap * 0.4)) * (Utils.RandomInt() == 1 ? 1 : -1))); pointX.PointLeft = Points[py][px - 1]; pointX.MoveDirection.X = Utils.RandomInt() == 1 || px == Points[py].Count - 1 ? Points[py][px - 1].MoveDirection.X : Points[py][px + 1].MoveDirection.X; Points[py].Insert(px, pointX); Points[py][px + 1].PointLeft = Points[py][px]; px++; xCount++; } } Displace(); // Draw for (int py = 1; py < Points.Count; py++) { for (int px = 1; px < Points[py].Count; px++) { RectangleShape l; if (Points[py][px].PointLeft != null) { l = new RectangleShape(new Vector2f(Utils.Distance(Points[py][px].PointLeft.Position, Points[py][px].Position), LineThickness)); l.FillColor = Colour; l.Origin = new Vector2f(0, LineThickness / 2); l.Position = Points[py][px].Position; l.Rotation = (float)Utils.GetAngle(Points[py][px].Position, Points[py][px].PointLeft.Position); AddChild(l); Lines.Add(l); } if (Points[py][px].PointAbove != null) { l = new RectangleShape(new Vector2f(Utils.Distance(Points[py][px].PointAbove.Position, Points[py][px].Position), LineThickness)); l.FillColor = Colour; l.Origin = new Vector2f(0, LineThickness / 2); l.Position = Points[py][px].Position; l.Rotation = (float)Utils.GetAngle(Points[py][px].Position, Points[py][px].PointAbove.Position); AddChild(l); Lines.Add(l); } CircleShape corner = new CircleShape(LineThickness / 2); corner.FillColor = Colour; corner.Origin = new Vector2f(corner.Radius, corner.Radius); corner.Position = Points[py][px].Position; AddChild(corner); Corners.Add(corner); } } }