static void Main(string[] args) { // Create a rectangle centered at (5,5) with length and width of 1 and 4 Shapes.Rectangle r = new Shapes.Rectangle(1, 4, 5, 5); // Create a square centered at (4,4) with length of 2 in both dimension Shapes.Square s = new Shapes.Square(2, 4, 4); // Create a circle centered at (0,0) with a radius of 4 Shapes.Circle c = new Shapes.Circle(4, 0, 0); Console.WriteLine("The height of the rectangle is " + r.xLength + " and the width is " + r.yLength + " at (" + r.centerX + ", " + r.centerY + ")"); r.scale(6, 2); Console.WriteLine("The height of the rectangle is " + r.xLength + " and the width is " + r.yLength + " at (" + r.centerX + ", " + r.centerY + ")"); r.move(2, 2); Console.WriteLine("The height of the rectangle is " + r.xLength + " and the width is " + r.yLength + " at (" + r.centerX + ", " + r.centerY + ")\n"); Console.WriteLine("The height of the square is " + s.xLength + " and the width is " + s.yLength + " at (" + s.centerX + ", " + s.centerY + ")"); s.scale(6, 2); Console.WriteLine("The height of the square is " + s.xLength + " and the width is " + s.yLength + " at (" + s.centerX + ", " + s.centerY + ")"); s.move(2, 2); Console.WriteLine("The height of the square is " + s.xLength + " and the width is " + s.yLength + " at (" + s.centerX + ", " + s.centerY + ")\n"); Console.WriteLine("The radius of the circle is " + c.radius + " at (" + c.centerX + ", " + c.centerY + ")"); c.scale(6); Console.WriteLine("The radius of the circle is " + c.radius + " at (" + c.centerX + ", " + c.centerY + ")"); c.move(2, 2); Console.WriteLine("The radius of the circle is " + c.radius + " at (" + c.centerX + ", " + c.centerY + ")"); // Wait for user input to close the console Console.WriteLine("Press ENTER to close the window"); Console.ReadLine(); }
internal void ResolveCircleCircleSimple() { Shapes.Circle BA = BodyA.shape as Shapes.Circle; Shapes.Circle BB = BodyB.shape as Shapes.Circle; Vector3 dN = Vector3.Normalize(BA.lastOverlap_delta); float dR = BA.lastOverlap_radius; float tM = BodyA.Mass + BodyB.Mass; // Calculate a new center of mass for the system, and offset them both their radius away from this center of mass, along the normal, based on their mass percentage of the system float mA = BodyA.Mass / tM; float mB = BodyB.Mass / tM; Vector3 newCOM = BodyA.transform.Position * mA + BodyB.transform.Position * mB; BodyA.transform.parent.Position = newCOM - (dN * dR * (1 - mA)); BodyB.transform.parent.Position = newCOM + (dN * dR * (1 - mB)); // Calculate the resulting velocities based on the restitution scalars for both bodies if (BodyA.Velocity.LengthSquared() + BodyB.Velocity.LengthSquared() > 0) { float projection = (2 * (Vector3.Dot(BodyA.Velocity * BodyA.Restitution, dN) - Vector3.Dot(BodyB.Velocity * BodyB.Restitution, dN))) / (tM); BodyA.Velocity = BodyA.Velocity - projection * BodyA.Mass * dN; BodyB.Velocity = BodyB.Velocity + projection * BodyB.Mass * dN; } }
internal void ResolveCircleAABBSimple() { // TODO Circle AABB Shapes.Circle BA = (BodyA.shape is Shapes.Circle) ? BodyA.shape as Shapes.Circle : BodyB.shape as Shapes.Circle; Shapes.AABB BB = (BodyA.shape is Shapes.Circle) ? BodyB.shape as Shapes.AABB : BodyA.shape as Shapes.AABB; Vector3 dN = Vector3.Normalize(BA.lastOverlap_delta); float theta = (float)Math.Atan(dN.Z / dN.X); float length = BB.LengthAtAngle(theta); // Time to move the circle and the aabb away from each other along the normal // Calculate a new center of mass for the system, and offset them both their radii away from this center of mass, along the normal, based on their mass percentage of the system float dR = length + BA.Radius; float tM = BodyA.Mass + BodyB.Mass; float mA = BodyA.Mass / tM; float mB = BodyB.Mass / tM; Vector3 newCOM = BodyA.transform.Position * mA + BodyB.transform.Position * mB; BodyA.transform.parent.Position = newCOM - (dN * dR * (1 - mA)); BodyB.transform.parent.Position = newCOM + (dN * dR * (1 - mB)); // Calculate the resulting velocities based on the restitution scalars for both bodies if (BodyA.Velocity.LengthSquared() + BodyB.Velocity.LengthSquared() > 0) { float projection = (2 * (Vector3.Dot(BodyA.Velocity * BodyA.Restitution, dN) - Vector3.Dot(BodyB.Velocity * BodyB.Restitution, dN))) / (tM); if (BodyA.shape is Shapes.AABB) { BodyA.Velocity = BodyA.Velocity - projection * BodyA.Mass * dN; if (Math.Abs(dN.X) > Math.Abs(dN.Y)) { BodyB.Velocity = new Vector3(-BodyB.Velocity.X, BodyB.Velocity.Y, BodyB.Velocity.Z); } else { BodyB.Velocity = new Vector3(BodyB.Velocity.X, BodyB.Velocity.Y, -BodyB.Velocity.Z); } } else { BodyB.Velocity = BodyB.Velocity + projection * BodyB.Mass * dN; if (Math.Abs(dN.X) > Math.Abs(dN.Y)) { BodyA.Velocity = new Vector3(-BodyA.Velocity.X, BodyA.Velocity.Y, BodyA.Velocity.Z); } else { BodyA.Velocity = new Vector3(BodyA.Velocity.X, BodyA.Velocity.Y, -BodyA.Velocity.Z); } } } }
// TODO fix Circle vs Circle Static collision resolution internal void ResolveCircleCircleStatic(PhysicsBody2D BodyS, PhysicsBody2D BodyD) { Shapes.Circle BA = BodyS.shape as Shapes.Circle; Shapes.Circle BB = BodyD.shape as Shapes.Circle; Vector3 dN = Vector3.Normalize(BA.lastOverlap_delta); float dR = BA.lastOverlap_radius; BodyD.transform.parent.Position = BodyS.transform.Position + dN * dR; if (BodyD.Velocity.LengthSquared() > 0) { float projection = 2 * -Vector3.Dot(BodyD.Velocity * Math.Min(BodyD.Restitution, BodyS.Restitution), dN); BodyD.Velocity = BodyD.Velocity + projection * dN; } }
public override bool Place(Point origin, StructureMap structures) { Point y; if (GenBase._tiles[origin.X, origin.Y].active() && WorldGen.SolidTile(origin.X, origin.Y)) { return(false); } Searches.Down down = new Searches.Down(80); GenCondition[] isSolid = new GenCondition[] { new Conditions.IsSolid() }; if (!WorldUtils.Find(origin, Searches.Chain(down, isSolid), out y)) { return(false); } y.Y = y.Y + 2; Ref <int> @ref = new Ref <int>(0); Shapes.Circle circle = new Shapes.Circle(8); GenAction[] genActionArray = new GenAction[] { new Modifiers.IsSolid(), new Actions.Scanner(@ref) }; WorldUtils.Gen(y, circle, Actions.Chain(genActionArray)); if (@ref.Value < 20) { return(false); } if (!structures.CanPlace(new Rectangle(y.X - 8, y.Y - 8, 16, 16), 0)) { return(false); } Shapes.Circle circle1 = new Shapes.Circle(8); GenAction[] radialDither = new GenAction[] { new Modifiers.RadialDither(0f, 10f), new Modifiers.IsSolid(), new Actions.SetTile(229, true, true) }; WorldUtils.Gen(y, circle1, Actions.Chain(radialDither)); ShapeData shapeDatum = new ShapeData(); Shapes.Circle circle2 = new Shapes.Circle(4, 3); GenAction[] blotch = new GenAction[] { new Modifiers.Blotches(2, 0.3), new Modifiers.IsSolid(), new Actions.ClearTile(true), (new Modifiers.RectangleMask(-6, 6, 0, 3)).Output(shapeDatum), new Actions.SetLiquid(2, 255) }; WorldUtils.Gen(y, circle2, Actions.Chain(blotch)); Point point = new Point(y.X, y.Y + 1); ModShapes.InnerOutline innerOutline = new ModShapes.InnerOutline(shapeDatum, true); GenAction[] isEmpty = new GenAction[] { new Modifiers.IsEmpty(), new Modifiers.RectangleMask(-6, 6, 1, 3), new Actions.SetTile(59, true, true) }; WorldUtils.Gen(point, innerOutline, Actions.Chain(isEmpty)); structures.AddStructure(new Rectangle(y.X - 8, y.Y - 8, 16, 16), 0); return(true); }
internal void ResolveCircleAABBStatic(PhysicsBody2D BodyS, PhysicsBody2D BodyD) { // TODO Circle AABB Shapes.Circle BA = (BodyS.shape is Shapes.Circle) ? BodyS.shape as Shapes.Circle : BodyD.shape as Shapes.Circle; Shapes.AABB BB = (BodyS.shape is Shapes.Circle) ? BodyD.shape as Shapes.AABB : BodyS.shape as Shapes.AABB; // Might as well normalize the delta while we are at it Vector3 dN = Vector3.Normalize(BA.lastOverlap_delta); float theta = (float)Math.Atan(dN.Z / dN.X); float length = BB.LengthAtAngle(theta); // Time to move the circle and the aabb away from each other along the normal // Calculate a new center of mass for the system, and offset them both their radii away from this center of mass, along the normal, based on their mass percentage of the system float dR = length + BA.Radius; BodyD.transform.parent.Position = BodyS.transform.Position + (dN * dR); if (BodyB.Velocity.LengthSquared() > 0 && Vector3.Dot(Vector3.Normalize(BodyB.Velocity), dN) > 0) { float projection = 2 * -Vector3.Dot(BodyB.Velocity * MathHelper.Min(BodyB.Restitution, BodyA.Restitution), dN); if (BodyA.shape is Shapes.AABB) { if (Math.Abs(dN.X) > Math.Abs(dN.Y)) { BodyB.Velocity = new Vector3(-BodyB.Velocity.X, BodyB.Velocity.Y, BodyB.Velocity.Z); } else { BodyB.Velocity = new Vector3(BodyB.Velocity.X, BodyB.Velocity.Y, -BodyB.Velocity.Z); } } else { BodyB.Velocity = BodyB.Velocity + projection * BodyB.Mass * dN; } } }
public override bool Place(Point origin, StructureMap structures) { Dictionary <ushort, int> nums = new Dictionary <ushort, int>(); Point point = new Point(origin.X - 25, origin.Y - 25); Shapes.Rectangle rectangle = new Shapes.Rectangle(50, 50); ushort[] numArray = new ushort[] { 0, 59, 147, 1 }; WorldUtils.Gen(point, rectangle, (new Actions.TileScanner(numArray)).Output(nums)); int item = nums[0] + nums[1]; int num = nums[59]; int item1 = nums[147]; if (item1 <= num || item1 <= item) { return(false); } int num1 = 0; for (int i = GenBase._random.Next(10, 15); i > 5; i--) { int num2 = GenBase._random.Next(-5, 5); Point point1 = new Point(origin.X + num2, origin.Y + num1); Shapes.Circle circle = new Shapes.Circle(i); GenAction[] blotch = new GenAction[] { new Modifiers.Blotches(4, 0.3), null, null }; ushort[] numArray1 = new ushort[] { 147, 161, 224, 0, 1 }; blotch[1] = new Modifiers.OnlyTiles(numArray1); blotch[2] = new Actions.SetTile(162, true, true); WorldUtils.Gen(point1, circle, Actions.Chain(blotch)); Point point2 = new Point(origin.X + num2, origin.Y + num1); Shapes.Circle circle1 = new Shapes.Circle(i); GenAction[] genActionArray = new GenAction[] { new Modifiers.Blotches(4, 0.3), new Modifiers.HasLiquid(-1, -1), new Actions.SetTile(162, true, true), new Actions.SetLiquid(0, 0) }; WorldUtils.Gen(point2, circle1, Actions.Chain(genActionArray)); num1 = num1 + (i - 2); } return(true); }
public override void initialize() { updateFrames = new Queue<int>(); drawFrames = new Queue<int>(); MediaPlayer.IsRepeating = true; MediaPlayer.Play(song); netParticles = new NetParticleFactory(); netParticles.initialize(gd.Viewport, 100, 50, -50, glowParticle, new Color(10, 13, 225, 128)); circle = new Shapes.Circle(new Vector2(gd.Viewport.Width, gd.Viewport.Height), 250); circlePosition = 0; buttonSizeX = 250; buttonSizeY = 60; buttonBufferX = 200; buttonBufferY = 600; Rectangle buttonPosition = new Rectangle(gd.Viewport.Width/2-button.Width/4,400,button.Width/2, button.Height/2); Color[] textColors = { new Color(255,0,0), new Color(0,255,0), new Color(0,0,255), new Color(0,255,0) }; buttons = new List<Button>(); buttons.Add(new Button(button, Color.White, buttonPosition, ocrFont, "Play", textColors)); buttons.Add(new Button(button, Color.White, buttonPosition, ocrFont, "Options", textColors)); buttons.Add(new Button(button, Color.White, buttonPosition, ocrFont, "Quit", textColors)); placeButtonsHorizontal(); }
public override bool Place(Point origin, StructureMap structures) { Point point; if (WorldGen.SolidTile(origin.X, origin.Y) && GenBase._tiles[origin.X, origin.Y].wall == 3) { return(false); } Searches.Down down = new Searches.Down(100); GenCondition[] isSolid = new GenCondition[] { new Conditions.IsSolid() }; if (!WorldUtils.Find(origin, Searches.Chain(down, isSolid), out origin)) { return(false); } Point point1 = new Point(origin.X - 4, origin.Y); Searches.Down down1 = new Searches.Down(5); GenCondition[] genConditionArray = new GenCondition[1]; ushort[] numArray = new ushort[] { 25 }; genConditionArray[0] = (new Conditions.IsTile(numArray)).AreaAnd(8, 1); if (!WorldUtils.Find(point1, Searches.Chain(down1, genConditionArray), out point)) { return(false); } ShapeData shapeDatum = new ShapeData(); ShapeData shapeDatum1 = new ShapeData(); ShapeData shapeDatum2 = new ShapeData(); for (int i = 0; i < 6; i++) { Shapes.Circle circle = new Shapes.Circle(GenBase._random.Next(10, 12) + i); GenAction[] offset = new GenAction[] { new Modifiers.Offset(0, 5 * i + 5), (new Modifiers.Blotches(3, 0.3)).Output(shapeDatum) }; WorldUtils.Gen(origin, circle, Actions.Chain(offset)); } for (int j = 0; j < 6; j++) { Shapes.Circle circle1 = new Shapes.Circle(GenBase._random.Next(5, 7) + j); GenAction[] genActionArray = new GenAction[] { new Modifiers.Offset(0, 2 * j + 18), (new Modifiers.Blotches(3, 0.3)).Output(shapeDatum1) }; WorldUtils.Gen(origin, circle1, Actions.Chain(genActionArray)); } for (int k = 0; k < 6; k++) { Shapes.Circle circle2 = new Shapes.Circle(GenBase._random.Next(4, 6) + k / 2); GenAction[] offset1 = new GenAction[] { new Modifiers.Offset(0, (int)(7.5f * (float)k) - 10), (new Modifiers.Blotches(3, 0.3)).Output(shapeDatum2) }; WorldUtils.Gen(origin, circle2, Actions.Chain(offset1)); } ShapeData shapeDatum3 = new ShapeData(shapeDatum1); shapeDatum1.Subtract(shapeDatum2, origin, origin); shapeDatum3.Subtract(shapeDatum1, origin, origin); ShapeData[] shapeDataArray = new ShapeData[] { shapeDatum, shapeDatum2 }; Rectangle bounds = ShapeData.GetBounds(origin, shapeDataArray); if (!structures.CanPlace(bounds, CorruptionPitBiome.ValidTiles, 2)) { return(false); } ModShapes.All all = new ModShapes.All(shapeDatum); GenAction[] setTile = new GenAction[] { new Actions.SetTile(25, true, true), new Actions.PlaceWall(3, true) }; WorldUtils.Gen(origin, all, Actions.Chain(setTile)); WorldUtils.Gen(origin, new ModShapes.All(shapeDatum1), new Actions.SetTile(0, true, true)); WorldUtils.Gen(origin, new ModShapes.All(shapeDatum2), new Actions.ClearTile(true)); ModShapes.All all1 = new ModShapes.All(shapeDatum1); GenAction[] isTouchingAir = new GenAction[] { new Modifiers.IsTouchingAir(true), null, null }; ushort[] numArray1 = new ushort[] { 25 }; isTouchingAir[1] = new Modifiers.NotTouching(false, numArray1); isTouchingAir[2] = new Actions.SetTile(23, true, true); WorldUtils.Gen(origin, all1, Actions.Chain(isTouchingAir)); WorldUtils.Gen(origin, new ModShapes.All(shapeDatum3), new Actions.PlaceWall(69, true)); structures.AddStructure(bounds, 2); return(true); }
public override bool Place(Point origin, StructureMap structures) { Point result1; if (!WorldUtils.Find(new Point(origin.X - 3, origin.Y), Searches.Chain((GenSearch) new Searches.Down(200), new Conditions.IsSolid().AreaAnd(6, 1)), out result1)) { return(false); } Point result2; if (!WorldUtils.Find(new Point(result1.X, result1.Y - 5), Searches.Chain((GenSearch) new Searches.Up(120), new Conditions.IsSolid().AreaOr(6, 1)), out result2) || result1.Y - 5 - result2.Y > 60 || (result1.Y - result2.Y < 30 || !structures.CanPlace(new Microsoft.Xna.Framework.Rectangle(result1.X - 30, result1.Y - 60, 60, 90), 0))) { return(false); } Dictionary <ushort, int> resultsOutput = new Dictionary <ushort, int>(); WorldUtils.Gen(new Point(result1.X - 25, result1.Y - 25), (GenShape) new Shapes.Rectangle(50, 50), (GenAction) new Actions.TileScanner(new ushort[4] { (ushort)0, (ushort)59, (ushort)147, (ushort)1 }).Output(resultsOutput)); int num1 = resultsOutput[(ushort)0] + resultsOutput[(ushort)1]; int num2 = resultsOutput[(ushort)59]; if (resultsOutput[(ushort)147] > num2 || num1 > num2 || num2 < 50) { return(false); } int num3 = (result1.Y - result2.Y - 9) / 5; int num4 = num3 * 5; int num5 = 0; double num6 = GenBase._random.NextDouble() + 1.0; double num7 = GenBase._random.NextDouble() + 2.0; if (GenBase._random.Next(2) == 0) { num7 = -num7; } for (int index = 0; index < num3; ++index) { int num8 = (int)(Math.Sin((double)(index + 1) / 12.0 * num6 * 3.14159274101257) * num7); int num9 = num8 < num5 ? num8 - num5 : 0; WorldUtils.Gen(new Point(result1.X + num5 + num9, result1.Y - (index + 1) * 5), (GenShape) new Shapes.Rectangle(6 + Math.Abs(num8 - num5), 7), Actions.Chain((GenAction) new Actions.RemoveWall(), (GenAction) new Actions.SetTile((ushort)383, false, true), (GenAction) new Actions.SetFrames(false))); WorldUtils.Gen(new Point(result1.X + num5 + num9 + 2, result1.Y - (index + 1) * 5), (GenShape) new Shapes.Rectangle(2 + Math.Abs(num8 - num5), 5), Actions.Chain((GenAction) new Actions.ClearTile(true), (GenAction) new Actions.PlaceWall((byte)78, true))); WorldUtils.Gen(new Point(result1.X + num5 + 2, result1.Y - index * 5), (GenShape) new Shapes.Rectangle(2, 2), Actions.Chain((GenAction) new Actions.ClearTile(true), (GenAction) new Actions.PlaceWall((byte)78, true))); num5 = num8; } int num10 = 6; if (num7 < 0.0) { num10 = 0; } List <Point> endpoints = new List <Point>(); for (int index = 0; index < 2; ++index) { double num8 = ((double)index + 1.0) / 3.0; int num9 = num10 + (int)(Math.Sin((double)num3 * num8 / 12.0 * num6 * 3.14159274101257) * num7); double angle = GenBase._random.NextDouble() * 0.785398185253143 - 0.785398185253143 - 0.200000002980232; if (num10 == 0) { angle -= 1.57079637050629; } WorldUtils.Gen(new Point(result1.X + num9, result1.Y - (int)((double)(num3 * 5) * num8)), (GenShape) new ShapeBranch(angle, (double)GenBase._random.Next(12, 16)).OutputEndpoints(endpoints), Actions.Chain((GenAction) new Actions.SetTile((ushort)383, false, true), (GenAction) new Actions.SetFrames(true))); num10 = 6 - num10; } int num11 = (int)(Math.Sin((double)num3 / 12.0 * num6 * 3.14159274101257) * num7); WorldUtils.Gen(new Point(result1.X + 6 + num11, result1.Y - num4), (GenShape) new ShapeBranch(-0.685398185253143, (double)GenBase._random.Next(16, 22)).OutputEndpoints(endpoints), Actions.Chain((GenAction) new Actions.SetTile((ushort)383, false, true), (GenAction) new Actions.SetFrames(true))); WorldUtils.Gen(new Point(result1.X + num11, result1.Y - num4), (GenShape) new ShapeBranch(-2.45619455575943, (double)GenBase._random.Next(16, 22)).OutputEndpoints(endpoints), Actions.Chain((GenAction) new Actions.SetTile((ushort)383, false, true), (GenAction) new Actions.SetFrames(true))); foreach (Point origin1 in endpoints) { Shapes.Circle circle = new Shapes.Circle(4); GenAction action = Actions.Chain((GenAction) new Modifiers.Blotches(4, 2, 0.3), (GenAction) new Modifiers.SkipTiles(new ushort[1] { (ushort)383 }), (GenAction) new Modifiers.SkipWalls(new byte[1] { (byte)78 }), (GenAction) new Actions.SetTile((ushort)384, false, true), (GenAction) new Actions.SetFrames(true)); WorldUtils.Gen(origin1, (GenShape)circle, action); } for (int index = 0; index < 4; ++index) { float angle = (float)((double)index / 3.0 * 2.0 + 0.570749998092651); WorldUtils.Gen(result1, (GenShape) new ShapeRoot(angle, (float)GenBase._random.Next(40, 60), 4f, 1f), (GenAction) new Actions.SetTile((ushort)383, true, true)); } WorldGen.AddBuriedChest(result1.X + 3, result1.Y - 1, GenBase._random.Next(4) == 0 ? 0 : WorldGen.GetNextJungleChestItem(), false, 10); structures.AddStructure(new Microsoft.Xna.Framework.Rectangle(result1.X - 30, result1.Y - 30, 60, 60), 0); return(true); }
public override bool Place(Point origin, StructureMap structures) { Ref <int> @ref = new Ref <int>(0); Ref <int> ref1 = new Ref <int>(0); Ref <int> ref2 = new Ref <int>(0); Ref <int> ref3 = new Ref <int>(0); Shapes.Circle circle = new Shapes.Circle(15); GenAction[] scanner = new GenAction[] { new Actions.Scanner(ref2), new Modifiers.IsSolid(), new Actions.Scanner(@ref), null, null, null, null }; ushort[] numArray = new ushort[] { 60, 59 }; scanner[3] = new Modifiers.OnlyTiles(numArray); scanner[4] = new Actions.Scanner(ref1); ushort[] numArray1 = new ushort[] { 60 }; scanner[5] = new Modifiers.OnlyTiles(numArray1); scanner[6] = new Actions.Scanner(ref3); WorldUtils.Gen(origin, circle, Actions.Chain(scanner)); if ((float)ref1.Value / (float)@ref.Value < 0.75f || ref3.Value < 2) { return(false); } if (!structures.CanPlace(new Rectangle(origin.X - 50, origin.Y - 50, 100, 100), 0)) { return(false); } int x = origin.X; int y = origin.Y; int num = 150; for (int i = x - num; i < x + num; i = i + 10) { if (i > 0 && i <= Main.maxTilesX - 1) { for (int j = y - num; j < y + num; j = j + 10) { if (j > 0 && j <= Main.maxTilesY - 1) { if (Main.tile[i, j].active() && Main.tile[i, j].type == 226) { return(false); } if (Main.tile[i, j].wall == 87 || Main.tile[i, j].wall == 3 || Main.tile[i, j].wall == 83) { return(false); } } } } } int x1 = origin.X; int y1 = origin.Y; int num1 = 0; int[] x2 = new int[10]; int[] y2 = new int[10]; Vector2 vector2 = new Vector2((float)x1, (float)y1); Vector2 vector21 = vector2; int num2 = WorldGen.genRand.Next(2, 5); for (int k = 0; k < num2; k++) { int num3 = WorldGen.genRand.Next(2, 5); for (int l = 0; l < num3; l++) { vector21 = WorldGen.Hive((int)vector2.X, (int)vector2.Y); } vector2 = vector21; x2[num1] = (int)vector2.X; y2[num1] = (int)vector2.Y; num1++; } for (int m = 0; m < num1; m++) { int num4 = x2[m]; int num5 = y2[m]; bool flag = false; int num6 = 1; if (WorldGen.genRand.Next(2) == 0) { num6 = -1; } while (num4 > 10 && num4 < Main.maxTilesX - 10 && num5 > 10 && num5 < Main.maxTilesY - 10 && (!Main.tile[num4, num5].active() || !Main.tile[num4, num5 + 1].active() || !Main.tile[num4 + 1, num5].active() || !Main.tile[num4 + 1, num5 + 1].active())) { num4 = num4 + num6; if (Math.Abs(num4 - x2[m]) <= 50) { continue; } flag = true; break; } if (!flag) { num4 = num4 + num6; for (int n = num4 - 1; n <= num4 + 2; n++) { for (int o = num5 - 1; o <= num5 + 2; o++) { if (n < 10 || n > Main.maxTilesX - 10) { flag = true; } else if (Main.tile[n, o].active() && Main.tile[n, o].type != 225) { flag = true; break; } } } if (!flag) { for (int p = num4 - 1; p <= num4 + 2; p++) { for (int q = num5 - 1; q <= num5 + 2; q++) { if (p < num4 || p > num4 + 1 || q < num5 || q > num5 + 1) { Main.tile[p, q].active(true); Main.tile[p, q].type = 225; } else { Main.tile[p, q].active(false); Main.tile[p, q].liquid = 255; Main.tile[p, q].honey(true); } } } num6 = num6 * -1; num5++; int num7 = 0; while ((num7 < 4 || WorldGen.SolidTile(num4, num5)) && num4 > 10 && num4 < Main.maxTilesX - 10) { num7++; num4 = num4 + num6; if (!WorldGen.SolidTile(num4, num5)) { continue; } WorldGen.PoundTile(num4, num5); if (Main.tile[num4, num5 + 1].active()) { continue; } Main.tile[num4, num5 + 1].active(true); Main.tile[num4, num5 + 1].type = 225; } } } } WorldGen.larvaX[WorldGen.numLarva] = Utils.Clamp <int>((int)vector2.X, 5, Main.maxTilesX - 5); WorldGen.larvaY[WorldGen.numLarva] = Utils.Clamp <int>((int)vector2.Y, 5, Main.maxTilesY - 5); WorldGen.numLarva = WorldGen.numLarva + 1; int x3 = (int)vector2.X; int y3 = (int)vector2.Y; for (int r = x3 - 1; r <= x3 + 1 && r > 0 && r < Main.maxTilesX; r++) { for (int s = y3 - 2; s <= y3 + 1 && s > 0 && s < Main.maxTilesY; s++) { if (s == y3 + 1) { Main.tile[r, s].active(true); Main.tile[r, s].type = 225; Main.tile[r, s].slope(0); Main.tile[r, s].halfBrick(false); } else { Main.tile[r, s].active(false); } } } structures.AddStructure(new Rectangle(origin.X - 50, origin.Y - 50, 100, 100), 5); return(true); }
public override bool Place(Point origin, StructureMap structures) { Point point; Ref <int> @ref = new Ref <int>(0); Ref <int> ref1 = new Ref <int>(0); Shapes.Circle circle = new Shapes.Circle(10); GenAction[] scanner = new GenAction[] { new Actions.Scanner(ref1), new Modifiers.IsSolid(), new Actions.Scanner(@ref) }; WorldUtils.Gen(origin, circle, Actions.Chain(scanner)); if (@ref.Value < ref1.Value - 5) { return(false); } int num = GenBase._random.Next(6, 10); int num1 = GenBase._random.Next(5); if (!structures.CanPlace(new Rectangle(origin.X - num, origin.Y - num, num * 2, num * 2), 0)) { return(false); } ShapeData shapeDatum = new ShapeData(); Shapes.Slime slime = new Shapes.Slime(num); GenAction[] onlyTile = new GenAction[] { (new Modifiers.Blotches(num1, num1, num1, 1, 0.3)).Output(shapeDatum), new Modifiers.Offset(0, -2), null, null, null, null }; ushort[] numArray = new ushort[] { 53 }; onlyTile[2] = new Modifiers.OnlyTiles(numArray); onlyTile[3] = new Actions.SetTile(397, true, true); onlyTile[4] = new Modifiers.OnlyWalls(new byte[1]); onlyTile[5] = new Actions.PlaceWall(16, true); WorldUtils.Gen(origin, slime, Actions.Chain(onlyTile)); ModShapes.All all = new ModShapes.All(shapeDatum); GenAction[] clearTile = new GenAction[] { new Actions.ClearTile(false), new Actions.SetLiquid(0, 0), new Actions.SetFrames(true), new Modifiers.OnlyWalls(new byte[1]), new Actions.PlaceWall(16, true) }; WorldUtils.Gen(origin, all, Actions.Chain(clearTile)); Searches.Down down = new Searches.Down(10); GenCondition[] isSolid = new GenCondition[] { new Conditions.IsSolid() }; if (!WorldUtils.Find(origin, Searches.Chain(down, isSolid), out point)) { return(false); } int y = point.Y - 1; bool flag = GenBase._random.Next() % 2 == 0; if (GenBase._random.Next() % 10 != 0) { int num2 = GenBase._random.Next(1, 4); int num3 = (flag ? 4 : -(num >> 1)); for (int i = 0; i < num2; i++) { int num4 = GenBase._random.Next(1, 3); for (int j = 0; j < num4; j++) { WorldGen.PlaceTile(origin.X + num3 - i, y - j, 331, false, false, -1, 0); } } } int num5 = (num - 3) * (flag ? -1 : 1); if (GenBase._random.Next() % 10 != 0) { WorldGen.PlaceTile(origin.X + num5, y, 186, false, false, -1, 0); } if (GenBase._random.Next() % 10 != 0) { WorldGen.PlaceTile(origin.X, y, 215, true, false, -1, 0); if (GenBase._tiles[origin.X, y].active() && GenBase._tiles[origin.X, y].type == 215) { Tile tile = GenBase._tiles[origin.X, y]; tile.frameY = (short)(tile.frameY + 36); Tile tile1 = GenBase._tiles[origin.X - 1, y]; tile1.frameY = (short)(tile1.frameY + 36); Tile tile2 = GenBase._tiles[origin.X + 1, y]; tile2.frameY = (short)(tile2.frameY + 36); Tile tile3 = GenBase._tiles[origin.X, y - 1]; tile3.frameY = (short)(tile3.frameY + 36); Tile tile4 = GenBase._tiles[origin.X - 1, y - 1]; tile4.frameY = (short)(tile4.frameY + 36); Tile tile5 = GenBase._tiles[origin.X + 1, y - 1]; tile5.frameY = (short)(tile5.frameY + 36); } } structures.AddStructure(new Rectangle(origin.X - num, origin.Y - num, num * 2, num * 2), 4); return(true); }
public override bool Place(Point origin, StructureMap structures) { Point point; Point point1; Point point2 = new Point(origin.X - 3, origin.Y); Searches.Down down = new Searches.Down(200); GenCondition[] genConditionArray = new GenCondition[] { (new Conditions.IsSolid()).AreaAnd(6, 1) }; if (!WorldUtils.Find(point2, Searches.Chain(down, genConditionArray), out point)) { return(false); } Point point3 = new Point(point.X, point.Y - 5); Searches.Up up = new Searches.Up(120); GenCondition[] genConditionArray1 = new GenCondition[] { (new Conditions.IsSolid()).AreaOr(6, 1) }; if (!WorldUtils.Find(point3, Searches.Chain(up, genConditionArray1), out point1) || point.Y - 5 - point1.Y > 60) { return(false); } if (point.Y - point1.Y < 30) { return(false); } if (!structures.CanPlace(new Rectangle(point.X - 30, point.Y - 60, 60, 90), 0)) { return(false); } Dictionary <ushort, int> nums = new Dictionary <ushort, int>(); Point point4 = new Point(point.X - 25, point.Y - 25); Shapes.Rectangle rectangle = new Shapes.Rectangle(50, 50); ushort[] numArray = new ushort[] { 0, 59, 147, 1 }; WorldUtils.Gen(point4, rectangle, (new Actions.TileScanner(numArray)).Output(nums)); int item = nums[0] + nums[1]; int num = nums[59]; if (nums[147] > num || item > num || num < 50) { return(false); } int y = (point.Y - point1.Y - 9) / 5; int num1 = y * 5; int num2 = 0; double num3 = GenBase._random.NextDouble() + 1; double num4 = GenBase._random.NextDouble() + 2; if (GenBase._random.Next(2) == 0) { num4 = -num4; } for (int i = 0; i < y; i++) { double num5 = (double)(i + 1) / 12; int num6 = (int)(Math.Sin(num5 * num3 * 3.14159274101257) * num4); int num7 = (num6 < num2 ? num6 - num2 : 0); Point point5 = new Point(point.X + num2 + num7, point.Y - (i + 1) * 5); Shapes.Rectangle rectangle1 = new Shapes.Rectangle(6 + Math.Abs(num6 - num2), 7); GenAction[] removeWall = new GenAction[] { new Actions.RemoveWall(), new Actions.SetTile(383, false, true), new Actions.SetFrames(false) }; WorldUtils.Gen(point5, rectangle1, Actions.Chain(removeWall)); Point point6 = new Point(point.X + num2 + num7 + 2, point.Y - (i + 1) * 5); Shapes.Rectangle rectangle2 = new Shapes.Rectangle(2 + Math.Abs(num6 - num2), 5); GenAction[] clearTile = new GenAction[] { new Actions.ClearTile(true), new Actions.PlaceWall(78, true) }; WorldUtils.Gen(point6, rectangle2, Actions.Chain(clearTile)); Point point7 = new Point(point.X + num2 + 2, point.Y - i * 5); Shapes.Rectangle rectangle3 = new Shapes.Rectangle(2, 2); GenAction[] genActionArray = new GenAction[] { new Actions.ClearTile(true), new Actions.PlaceWall(78, true) }; WorldUtils.Gen(point7, rectangle3, Actions.Chain(genActionArray)); num2 = num6; } int num8 = 6; if (num4 < 0) { num8 = 0; } List <Point> points = new List <Point>(); for (int j = 0; j < 2; j++) { double num9 = ((double)j + 1) / 3; int num10 = num8 + (int)(Math.Sin((double)y * num9 / 12 * num3 * 3.14159274101257) * num4); double num11 = GenBase._random.NextDouble() * 0.785398185253143 - 0.785398185253143 - 0.200000002980232; if (num8 == 0) { num11 = num11 - 1.57079637050629; } Point point8 = new Point(point.X + num10, point.Y - (int)((double)(y * 5) * num9)); ShapeBranch shapeBranch = (new ShapeBranch(num11, (double)GenBase._random.Next(12, 16))).OutputEndpoints(points); GenAction[] setTile = new GenAction[] { new Actions.SetTile(383, false, true), new Actions.SetFrames(true) }; WorldUtils.Gen(point8, shapeBranch, Actions.Chain(setTile)); num8 = 6 - num8; } int num12 = (int)(Math.Sin((double)y / 12 * num3 * 3.14159274101257) * num4); Point point9 = new Point(point.X + 6 + num12, point.Y - num1); ShapeBranch shapeBranch1 = (new ShapeBranch(-0.685398185253143, (double)GenBase._random.Next(16, 22))).OutputEndpoints(points); GenAction[] setTile1 = new GenAction[] { new Actions.SetTile(383, false, true), new Actions.SetFrames(true) }; WorldUtils.Gen(point9, shapeBranch1, Actions.Chain(setTile1)); Point point10 = new Point(point.X + num12, point.Y - num1); ShapeBranch shapeBranch2 = (new ShapeBranch(-2.45619455575943, (double)GenBase._random.Next(16, 22))).OutputEndpoints(points); GenAction[] genActionArray1 = new GenAction[] { new Actions.SetTile(383, false, true), new Actions.SetFrames(true) }; WorldUtils.Gen(point10, shapeBranch2, Actions.Chain(genActionArray1)); foreach (Point point11 in points) { Shapes.Circle circle = new Shapes.Circle(4); GenAction[] blotch = new GenAction[] { new Modifiers.Blotches(4, 2, 0.3), null, null, null, null }; ushort[] numArray1 = new ushort[] { 383 }; blotch[1] = new Modifiers.SkipTiles(numArray1); byte[] numArray2 = new byte[] { 78 }; blotch[2] = new Modifiers.SkipWalls(numArray2); blotch[3] = new Actions.SetTile(384, false, true); blotch[4] = new Actions.SetFrames(true); WorldUtils.Gen(point11, circle, Actions.Chain(blotch)); } for (int k = 0; k < 4; k++) { float single = (float)k / 3f * 2f + 0.57075f; WorldUtils.Gen(point, new ShapeRoot(single, (float)GenBase._random.Next(40, 60), 4f, 1f), new Actions.SetTile(383, true, true)); } WorldGen.AddBuriedChest(point.X + 3, point.Y - 1, (GenBase._random.Next(4) == 0 ? 0 : WorldGen.GetNextJungleChestItem()), false, 10); structures.AddStructure(new Rectangle(point.X - 30, point.Y - 30, 60, 60), 0); return(true); }