protected override void Open() { dispose += DemoHelper.BasicDemoSetup(DemoInfo); dispose += DemoHelper.CreateTank(DemoInfo, new Vector2D(50, 0)); List <Body> bodies = new List <Body>(); dispose += DemoHelper.CreateTank(DemoInfo, new Vector2D(250, 0), bodies); Scene.Engine.AddLogic(new GravityField(new Vector2D(0, 1000), new Lifespan())); DemoHelper.AddFloor(DemoInfo, new ALVector2D(0, new Vector2D(700, 750))); IShape shape = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("fighter.png"), 3, 16, 4); for (int i = 128 * 3; i > -128; i -= 128) { Body b = DemoHelper.AddShape(DemoInfo, shape, 40, new ALVector2D(1, new Vector2D(700, 272 + i))); //b.Transformation *= Matrix2x3.FromScale(new Vector2D(1, .5f)); } Body line = DemoHelper.AddLine(DemoInfo, new Vector2D(300, 400), new Vector2D(600, 400), 20, Scalar.PositiveInfinity); line.IgnoresGravity = true; GroupedOneWayPlatformIgnorer ignorer = new GroupedOneWayPlatformIgnorer(-Vector2D.YAxis, 10); ignorer.AddGroup(bodies.ToArray()); line.CollisionIgnorer = ignorer; Body ball = DemoHelper.AddCircle(DemoInfo, 80, 20, 4000, new ALVector2D(0, 1028, 272)); ball.Transformation *= Matrix2x3.FromRotationZ(1) * Matrix2x3.FromScale(new Vector2D(.9f, .5f)) * Matrix2x3.FromRotationZ(-1); }
protected override void Open() { Coefficients coefficients = DemoHelper.Coefficients; DemoHelper.Coefficients.Restitution = 0; dispose += DemoHelper.CreateTank(DemoInfo, new Vector2D(50, 0)); dispose += DemoHelper.BasicDemoSetup(DemoInfo); Scene.Engine.AddLogic(new GravityField(new Vector2D(0, 1000), new Lifespan())); DemoHelper.AddFloor(DemoInfo, new ALVector2D(0, new Vector2D(700, 750))); IShape piston = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("piston.png"), 0, 16, 1); IShape socket = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("socket.png"), 0, 16, 1); DemoHelper.AddShape(DemoInfo, piston, 10, new ALVector2D(0, 300, 300)); DemoHelper.AddShape(DemoInfo, socket, 10, new ALVector2D(0, 300, 300)); IShape fighter = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("fighter.png"), 3, 16, 3); DemoHelper.AddShape(DemoInfo, fighter, 50, new ALVector2D(0, 500, 300)); DemoHelper.AddShape(DemoInfo, fighter, 50, new ALVector2D(0, 500, 100)); IShape starfury = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("Starfury.png"), 3, 16, 3); DemoHelper.AddShape(DemoInfo, starfury, 50, new ALVector2D(0, 700, 300)); DemoHelper.AddShape(DemoInfo, starfury, 50, new ALVector2D(0, 700, 100)); Body ball = DemoHelper.AddCircle(DemoInfo, 80, 20, 4000, new ALVector2D(0, 1028, 272));// //AddShape(new CircleShape(80, 20), 4000, new ALVector2D(0, new Vector2D(1028, 272))); DemoHelper.Coefficients = coefficients; }
protected override void Open() { dispose += DemoHelper.BasicDemoSetup(DemoInfo); Scene.Engine.AddLogic(new LineFluidLogic(new Line(0, -1, -400), 1.95f, .02f, new Vector2D(0, 0), new Lifespan())); Scene.Engine.AddLogic(new GravityField(new Vector2D(0, 1000), new Lifespan())); Rectangle rect1 = Viewport.Rectangle; BoundingRectangle rect = new BoundingRectangle(rect1.Left, rect1.Top, rect1.Right, rect1.Bottom); rect.Min.X -= 75; rect.Min.Y -= 75; rect.Max.X += 75; rect.Max.Y += 75; DemoHelper.AddShell(DemoInfo, rect, 100, Scalar.PositiveInfinity).ForEach(delegate(Body b) { b.IgnoresGravity = true; }); DemoHelper.AddRagDoll(DemoInfo, new Vector2D(340, 300)); DemoHelper.AddRagDoll(DemoInfo, new Vector2D(640, 300)); IShape shape = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("fighter.png"), 3, 16, 4); DemoHelper.AddShape(DemoInfo, shape, 200, new ALVector2D(0, new Vector2D(200, 300))); DemoHelper.AddShape(DemoInfo, shape, 100, new ALVector2D(0, new Vector2D(500, 300))); DemoHelper.AddRectangle(DemoInfo, 20, 200, 25 / 5, new ALVector2D(0, 600, 600)); DemoHelper.AddRectangle(DemoInfo, 20, 200, 25 / 5, new ALVector2D(0, 600, 620)); DemoHelper.AddRectangle(DemoInfo, 50, 100, 50, new ALVector2D(0, 200, 400)); DemoHelper.AddRectangle(DemoInfo, 50, 100, 50, new ALVector2D(0, 400, 200)); Vector2D[] waterVertexes = new Vector2D[4] { new Vector2D(-10, 400), new Vector2D(10000, 400), new Vector2D(10000, 1000), new Vector2D(-10, 1000) }; ScalarColor3[] waterColor = new ScalarColor3[4] { new ScalarColor3(0, 0, 1), new ScalarColor3(0, 0, 1), new ScalarColor3(0, 0, 1), new ScalarColor3(0, 0, 1) }; Colored3VertexesDrawable drawable = new Colored3VertexesDrawable(Gl.GL_QUADS, waterVertexes, waterColor); Graphic graphic = new Graphic(drawable, Matrix2x3.Identity, new Lifespan()); graphic.ZOrder = -1; Scene.AddGraphic(graphic); }
protected override void Open() { dispose += DemoHelper.BasicDemoSetup(DemoInfo); Vector2D gravityCenter = new Vector2D(500, 500); Scalar gravityPower = 200; Scene.Engine.AddLogic(new GravityPointField(gravityCenter, gravityPower, new Lifespan())); DemoHelper.AddRagDoll(DemoInfo, gravityCenter + new Vector2D(0, -20)); Scalar length = 41; Scalar size = 8 ; bool reverse = false; for (Scalar distance = 250; distance < 650; length += 10, size *= 2, distance += 60 + length) { Scalar da = MathHelper.TwoPi / size;// ((MathHelper.TWO_PI * distance) / size); Scalar l2 = length / 2; // da /= 2; Vector2D[] vertexes = new Vector2D[] { Vector2D.FromLengthAndAngle(distance - l2, da / 2), Vector2D.FromLengthAndAngle(distance - l2, -da / 2), Vector2D.FromLengthAndAngle(distance + l2, -da / 2), Vector2D.FromLengthAndAngle(distance + l2, da / 2), }; //da *= 2; Vector2D[] vertexes2 = VertexHelper.CenterVertexes(vertexes); vertexes = VertexHelper.Subdivide(vertexes2, 5); PolygonShape shape = ShapeFactory.CreateColoredPolygon(vertexes, 1.5f); for (Scalar angle = 0; angle < MathHelper.TwoPi; angle += da) { Vector2D position = Vector2D.FromLengthAndAngle(distance, angle) + gravityCenter; Body body = DemoHelper.AddShape(DemoInfo, shape, (size * length) / 10, new ALVector2D(angle, position)); body.State.Velocity.Linear = DemoHelper.GetOrbitVelocity(gravityCenter, Vector2D.FromLengthAndAngle(distance - length, angle) + gravityCenter, gravityPower); body.State.Velocity.Linear *= .5f; body.State.Velocity.Angular = -(body.State.Velocity.Linear.Magnitude) / (distance);// *(1 / MathHelper.TWO_PI); if (reverse) { body.State.Velocity.Linear = -body.State.Velocity.Linear; body.State.Velocity.Angular = -body.State.Velocity.Angular; } } reverse = !reverse; } }
protected override void Open() { dispose += DemoHelper.BasicDemoSetup(DemoInfo); Scene.Engine.AddLogic(new GravityField(new Vector2D(0, 1000), new Lifespan())); SurfacePolygons surfacePolygons = Cache <SurfacePolygons> .GetItem("physicsplayGround.png"); foreach (Vector2D[] vertexes in surfacePolygons.Polygons) { Vector2D[] processed = vertexes; for (int index = 1; index < 4; index++) { processed = VertexHelper.Reduce(processed, index); } processed = VertexHelper.Subdivide(processed, 16); IShape shape = ShapeFactory.CreateColoredPolygon(processed, 10); DemoHelper.AddShape(DemoInfo, shape, Scalar.PositiveInfinity, new ALVector2D(0, surfacePolygons.Offset)).IgnoresGravity = true; } for (int x = 440; x < 480; x += 10) { for (int y = -2000; y < 0; y += 12) { Body body = DemoHelper.AddCircle(DemoInfo, 5, 7, 3, new ALVector2D(0, x + DemoHelper.NextScalar(-400, 400), y)); body.Updated += delegate(object sender, UpdatedEventArgs e) { if (body.State.Position.Linear.Y > 900) { body.State.Position.Linear.Y = -100; } }; } } for (int x = 490; x < 510; x += 10) { for (int y = -550; y < -500; y += 12) { Body body = DemoHelper.AddRectangle(DemoInfo, 10, 20, 10, new ALVector2D(0, x + DemoHelper.NextScalar(-400, 400), y)); body.Updated += delegate(object sender, UpdatedEventArgs e) { if (body.State.Position.Linear.Y > 900) { body.State.Position.Linear.Y = -100; } }; } } }
protected override void Open() { Scene.IsPaused = true; List <Body> bodies = new List <Body>(); Body b = DemoHelper.AddLine(DemoInfo, new Vector2D(300, 200), new Vector2D(400, 200), 40, Scalar.PositiveInfinity); b.IgnoresPhysicsLogics = true; bodies.Add(b); Body b2 = DemoHelper.AddCircle(DemoInfo, 20, 40, Scalar.PositiveInfinity, new ALVector2D(0, 300, 100)); b2.IgnoresPhysicsLogics = true; bodies.Add(b2); Body b3 = DemoHelper.AddCircle(DemoInfo, 20, 40, 50, new ALVector2D(0, 100, 100)); bodies.Add(b3); Body b4 = DemoHelper.AddRectangle(DemoInfo, 20, 20, 20, new ALVector2D(0, 150, 150)); bodies.Add(b4); dispose += RegisterDup(DemoInfo, bodies); DemoHelper.AddShell(DemoInfo, new BoundingRectangle(0, 0, 200, 200), 10, Scalar.PositiveInfinity).ForEach(delegate(Body sb) { sb.IgnoresPhysicsLogics = true; }); Body bStart = DemoHelper.AddShape(DemoInfo, ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("start.png"), 2, 16, 3), Scalar.PositiveInfinity, new ALVector2D(0, 100, 650)); // Body bStart = DemoHelper.AddLine(DemoInfo, new Vector2D(10, 600), new Vector2D(100, 600), 40, Scalar.PositiveInfinity); bStart.IgnoresPhysicsLogics = true; Body bStop = DemoHelper.AddShape(DemoInfo, ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("stop.png"), 2, 16, 3), Scalar.PositiveInfinity, new ALVector2D(0, 100, 700)); //Body bEnd = DemoHelper.AddLine(DemoInfo, new Vector2D(10, 700), new Vector2D(100, 700), 40, Scalar.PositiveInfinity); bStop.IgnoresPhysicsLogics = true; Scene.Engine.AddLogic(new GravityField(new Vector2D(0, 1000), new Lifespan())); dispose += DemoHelper.RegisterClick(DemoInfo, bStart, MouseButton.PrimaryButton, delegate(object sender, EventArgs e) { Scene.IsPaused = false; }); dispose += DemoHelper.RegisterClick(DemoInfo, bStop, MouseButton.PrimaryButton, delegate(object sender, EventArgs e) { Scene.IsPaused = true; }); }
protected override void Open() { dispose += DemoHelper.BasicDemoSetup(DemoInfo); dispose += DemoHelper.CreateTank(DemoInfo, new Vector2D(50, 0)); Scene.Engine.AddLogic(new GravityField(new Vector2D(0, 1000), new Lifespan())); DemoHelper.AddFloor(DemoInfo, new ALVector2D(0, new Vector2D(700, 750))); IShape shape = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("block.png"), 3, 7, 4); DemoHelper.AddGrid( DemoInfo, shape, 20, new BoundingRectangle(440, 450, 500, 730), 1, 1); Body ball = DemoHelper.AddCircle(DemoInfo, 80, 20, 4000, new ALVector2D(0, 1028, 272)); Vector2D[][] polygons1 = new Vector2D[2][]; polygons1[0] = VertexHelper.Subdivide(VertexHelper.CreateRectangle(50, 50), 16); polygons1[1] = VertexHelper.CreateCircle(30, 20); Matrix2x3 matrix = Matrix2x3.FromTransformation(1, new Vector2D(30, 50)); polygons1[0] = VertexHelper.ApplyMatrix(ref matrix, polygons1[0]); IShape shape1 = ShapeFactory.CreateColoredMultiPolygon(polygons1, 3); DemoHelper.AddShape(DemoInfo, shape1, 50, new ALVector2D(0, 300, 300)); Vector2D[][] polygons = new Vector2D[3][]; polygons[0] = VertexHelper.Subdivide(VertexHelper.CreateRectangle(30, 50), 16); polygons[1] = VertexHelper.Subdivide(VertexHelper.CreateRectangle(50, 70), 16); polygons[2] = VertexHelper.CreateCircle(30, 20); matrix = Matrix2x3.FromTransformation(6, new Vector2D(36, 50)); polygons[2] = VertexHelper.ApplyMatrix(ref matrix, polygons[2]); matrix = Matrix2x3.FromTransformation(-6, new Vector2D(-36, 50)); polygons[1] = VertexHelper.ApplyMatrix(ref matrix, polygons[1]); IShape shape2 = ShapeFactory.CreateColoredMultiPolygon(polygons, 3); DemoHelper.AddShape(DemoInfo, shape2, 50, new ALVector2D(0, 400, 300)); }
protected override void Open() { IShape shape = ShapeFactory.CreateColoredCircle(8, 15); DemoHelper.AddGrid(DemoInfo, shape, 40, new BoundingRectangle(-500, 200, 800, 800), 50, 50); Viewport viewport2 = new Viewport(new Rectangle(Window.Size.Width / 2, 0, Window.Size.Width / 2, Window.Size.Height), Matrix2x3.Identity, Scene, new Lifespan()); Window.AddViewport(viewport2); Viewport.Rectangle = new Rectangle(0, 0, Window.Size.Width / 2, Window.Size.Height); IShape furyShape = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("starfury.png"), 2, 16, 3); Body b1 = DemoHelper.AddShape(DemoInfo, furyShape, 400, new ALVector2D(0, 0, 0)); Body b2 = DemoHelper.AddShape(DemoInfo, furyShape, 400, new ALVector2D(0, 0, 0)); dispose += DemoHelper.RegisterBodyTracking(DemoInfo, b1, Matrix2x3.FromRotationZ(-MathHelper.PiOver2) * Matrix2x3.FromScale(new Vector2D(.5f, .5f))); dispose += DemoHelper.RegisterBodyMovement(DemoInfo, b1, new ALVector2D(1000000, 100000, 0), Key.W, Key.S, Key.A, Key.D); DoGuns(b1, b2, Key.Q); dispose += DemoHelper.RegisterBodyTracking( new DemoOpenInfo(Window, viewport2, Scene) , b2, Matrix2x3.FromRotationZ(-MathHelper.PiOver2) * Matrix2x3.FromScale(new Vector2D(.5f, .5f))); dispose += DemoHelper.RegisterBodyMovement( DemoInfo, b2, new ALVector2D(1000000, 100000, 0)); DoGuns(b2, b1, Key.Return); b1.State.Position.Linear = new Vector2D(200, 0); b2.State.Position = new ALVector2D(MathHelper.Pi, 1, 0); b1.ApplyPosition(); b2.ApplyPosition(); DemoHelper.AddShell(DemoInfo, new BoundingRectangle(-700, -700, 1000, 1000), 90, Scalar.PositiveInfinity); dispose += delegate() { viewport2.Lifetime.IsExpired = true; Viewport.Rectangle = new Rectangle(0, 0, Window.Size.Width, Window.Size.Height); }; DemoHelper.AddStarField(DemoInfo, 1000, new BoundingRectangle(-1000, -1000, 1300, 1300)); }
protected override void Open() { IShape bombShape = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("rocket.png"), 2, 16, 3); dispose += DemoHelper.RegisterBombLaunching(DemoInfo, bombShape, 120); dispose += DemoHelper.RegisterMousePicking(DemoInfo); IShape shape = ShapeFactory.CreateColoredCircle(8, 15); DemoHelper.AddGrid(DemoInfo, shape, 40, new BoundingRectangle(200, 200, 1100, 1100), 5, 5); Body b = DemoHelper.AddShape(DemoInfo, bombShape, 400, new ALVector2D(0, 0, 0)); DemoHelper.RegisterBodyTracking(DemoInfo, b, Matrix2x3.FromRotationZ(-MathHelper.PiOver2)); DemoHelper.RegisterBodyMovement(DemoInfo, b, new ALVector2D(50000, 50000, 0)); DemoHelper.AddStarField(DemoInfo, 1000, new BoundingRectangle(-1000, -1000, 2300, 2300)); }
protected override void Open() { dispose += DemoHelper.BasicDemoSetup(DemoInfo); // dispose += DemoHelper.CreateTank(DemoInfo, new Vector2D(50, 0)); Scene.Engine.AddLogic(new GravityField(new Vector2D(0, 1000), new Lifespan())); DemoHelper.AddFloor(DemoInfo, new ALVector2D(0, new Vector2D(700, 750))); IShape shape = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("block.png"), 3, 7, 4); DemoHelper.AddShape(DemoInfo, shape, 20, new ALVector2D(0, 300, 700)); DemoHelper.AddGrid( DemoInfo, shape, 20, new BoundingRectangle(440, 450, 500, 730), 1, 1); // Body ball = DemoHelper.AddCircle(DemoInfo, 80, 20, 4000, new ALVector2D(0, 1028, 272)); }
protected override void Open() { Coefficients coefficients = DemoHelper.Coefficients; DemoHelper.Coefficients.Restitution = 0; Scene.Engine.AddLogic(new GravityField(new Vector2D(0, 1000), new Lifespan())); DemoHelper.AddFloor(DemoInfo, new ALVector2D(0, new Vector2D(700, 750))); int canJump = 0; IShape fighter = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("fighter.png"), 3, 16, 3); Body body = DemoHelper.AddShape(DemoInfo, fighter, 50, new ALVector2D(0, 500, 300)); body.Mass.MomentOfInertia = Scalar.PositiveInfinity; Scalar desiredVelocity = 0; Scalar maxVelocity = 150; body.Collided += delegate(object sender, CollisionEventArgs e) { canJump++; e.Contact.Ended += delegate(object sender2, EventArgs e2) { canJump--; }; }; EventHandler <KeyboardEventArgs> keyDownHandler = delegate(object sender, KeyboardEventArgs e) { if (canJump > 0 && e.Key == Key.UpArrow) { body.State.ForceAccumulator.Linear.Y -= 50 * 60000; } if (e.Key == Key.RightArrow) { desiredVelocity += maxVelocity; } else if (e.Key == Key.LeftArrow) { desiredVelocity -= maxVelocity; } }; EventHandler <KeyboardEventArgs> keyUpHandler = delegate(object sender, KeyboardEventArgs e) { if (e.Key == Key.RightArrow) { desiredVelocity -= maxVelocity; } else if (e.Key == Key.LeftArrow) { desiredVelocity += maxVelocity; } }; body.Updated += delegate(object sender, UpdatedEventArgs e) { if (canJump > 0) { if (desiredVelocity < 0) { if (desiredVelocity < body.State.Velocity.Linear.X) { body.State.ForceAccumulator.Linear.X -= 50 * 6000; } } if (desiredVelocity > 0) { if (desiredVelocity > body.State.Velocity.Linear.X) { body.State.ForceAccumulator.Linear.X += 50 * 6000; } } } }; DemoHelper.AddRectangle(DemoInfo, 40, 300, 200, new ALVector2D(0, 200, 600)); DemoHelper.AddRectangle(DemoInfo, 40, 300, 200, new ALVector2D(0, 400, 400)); DemoHelper.AddRectangle(DemoInfo, 40, 40, 20, new ALVector2D(0, 100, 100)); DemoHelper.AddRectangle(DemoInfo, 40, 40, 20, new ALVector2D(0, 200, 200)); DemoHelper.AddRectangle(DemoInfo, 40, 40, 20, new ALVector2D(0, 300, 300)); DemoHelper.AddRagDoll(DemoInfo, new Vector2D(700, 300)); Events.KeyboardDown += keyDownHandler; Events.KeyboardUp += keyUpHandler; dispose += delegate() { Events.KeyboardDown -= keyDownHandler; Events.KeyboardUp -= keyUpHandler; }; DemoHelper.Coefficients = coefficients; }