Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
 protected override void Open()
 {
     dispose += DemoHelper.BasicDemoSetup(DemoInfo);
     dispose += DemoHelper.CreateTank(DemoInfo, new Vector2D(300, 0));
     Scene.Engine.AddLogic(new GravityField(new Vector2D(0, 1000), new Lifespan()));
     DemoHelper.AddLine(DemoInfo, new Vector2D(0, 700), new Vector2D(300, 700), 30, Scalar.PositiveInfinity).IgnoresGravity   = true;
     DemoHelper.AddLine(DemoInfo, new Vector2D(300, 700), new Vector2D(400, 650), 30, Scalar.PositiveInfinity).IgnoresGravity = true;
     DemoHelper.AddLine(DemoInfo, new Vector2D(400, 650), new Vector2D(500, 650), 30, Scalar.PositiveInfinity).IgnoresGravity = true;
     DemoHelper.AddLine(DemoInfo, new Vector2D(500, 650), new Vector2D(500, 500), 30, Scalar.PositiveInfinity).IgnoresGravity = true;
     DemoHelper.AddLine(DemoInfo, new Vector2D(500, 500), new Vector2D(900, 550), 30, Scalar.PositiveInfinity).IgnoresGravity = true;
     DemoHelper.AddLine(DemoInfo, new Vector2D(400, 400), new Vector2D(600, 300), 30, Scalar.PositiveInfinity).IgnoresGravity = true;
     DemoHelper.AddRagDoll(DemoInfo, new Vector2D(200, 400));
     DemoHelper.AddRagDoll(DemoInfo, new Vector2D(300, 300));
     DemoHelper.AddRagDoll(DemoInfo, new Vector2D(400, 200));
     DemoHelper.AddRagDoll(DemoInfo, new Vector2D(500, 100));
     DemoHelper.AddRagDoll(DemoInfo, new Vector2D(600, 0));
     DemoHelper.AddRagDoll(DemoInfo, new Vector2D(700, -100));
 }
Exemplo n.º 4
0
        protected override void Open()
        {
            dispose += DemoHelper.BasicDemoSetup(DemoInfo);
            dispose += DemoHelper.CreateTank(DemoInfo, new Vector2D(50, 0));

            Scene.Engine.AddLogic(new GravityPointField(new Vector2D(500, 400), 1000, new Lifespan()));
            IShape shape = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("block.png"), 3, 7, 4);

            for (int index = 0; index < 5; index++)
            {
                Vector2D pos = new Vector2D(500, 500) + Vector2D.FromLengthAndAngle(500, .6f * index);
                DemoHelper.AddRagDoll(DemoInfo, pos);
            }

            DemoHelper.AddGrid(
                DemoInfo, shape, 20,
                new BoundingRectangle(400, 400, 800, 710),
                5, 4);
        }
Exemplo n.º 5
0
        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;
        }