protected override void Open() { Scene.Engine.AddLogic(new GravityField(new Vector2D(0, 1000), new Lifespan())); IShape bombShape = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("rocket.png"), 2, 16, 3); dispose += DemoHelper.BasicDemoSetup(DemoInfo); Coefficients o = DemoHelper.Coefficients; DemoHelper.Coefficients = new Coefficients(1, .5f); DemoHelper.AddFloor(DemoInfo, new ALVector2D(0, new Vector2D(700, 750))); Body b1 = DemoHelper.AddRectangle(DemoInfo, 750, 100, Scalar.PositiveInfinity, new ALVector2D(0, 0, 750 / 2)); b1.IgnoresGravity = true; Body b2 = DemoHelper.AddRectangle(DemoInfo, 750, 100, Scalar.PositiveInfinity, new ALVector2D(0, 1024, 750 / 2)); b2.IgnoresGravity = true; DemoHelper.Coefficients = new Coefficients(.7f, .05f); for (int x = 60; x < 80; x += 10) { for (int y = -2000; y < 700; y += 12) { Body g = DemoHelper.AddCircle(DemoInfo, 5, 7, 3, new ALVector2D(0, x, y)); g.State.Velocity.Angular = 1; // g.State.Velocity.Linear = new Vector2D(0, 500); } } DemoHelper.Coefficients = o; }
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); 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); Scene.Engine.AddLogic(new GravityField(new Vector2D(0, 1000), new Lifespan())); for (int x = 0; x < 400; x += 45) { DemoHelper.AddRectangle(DemoInfo, 80, 15, 90, new ALVector2D(0, x, 145)); } DemoHelper.AddLine(DemoInfo, new Vector2D(-40, 200), new Vector2D(400, 200), 30, Scalar.PositiveInfinity).IgnoresGravity = true; DemoHelper.AddLine(DemoInfo, new Vector2D(400, 150), new Vector2D(430, 150), 30, Scalar.PositiveInfinity).IgnoresGravity = true; DemoHelper.AddLine(DemoInfo, new Vector2D(430, 150), new Vector2D(600, 200), 30, Scalar.PositiveInfinity).IgnoresGravity = true; DemoHelper.AddLine(DemoInfo, new Vector2D(600, 200), new Vector2D(700, 300), 30, Scalar.PositiveInfinity).IgnoresGravity = true; DemoHelper.AddLine(DemoInfo, new Vector2D(1200, 200), new Vector2D(800, 420), 30, Scalar.PositiveInfinity).IgnoresGravity = true; DemoHelper.AddLine(DemoInfo, new Vector2D(800, 420), new Vector2D(700, 470), 30, Scalar.PositiveInfinity).IgnoresGravity = true; DemoHelper.AddLine(DemoInfo, new Vector2D(700, 470), new Vector2D(600, 486), 30, Scalar.PositiveInfinity).IgnoresGravity = true; DemoHelper.AddLine(DemoInfo, new Vector2D(600, 486), new Vector2D(570, 486), 30, Scalar.PositiveInfinity).IgnoresGravity = true; Scalar rest = DemoHelper.Coefficients.Restitution; DemoHelper.Coefficients.Restitution = 1; DemoHelper.AddCircle(DemoInfo, 20, 20, 300, new ALVector2D(0, 409, 115)); for (int x = 160; x < 500; x += 42) { Body b = DemoHelper.AddCircle(DemoInfo, 20, 20, 300, new ALVector2D(0, x, 450)); Scene.Engine.AddJoint(new FixedHingeJoint(b, b.State.Position.Linear - new Vector2D(0, 500), new Lifespan())); } DemoHelper.Coefficients.Restitution = rest; }
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; }