示例#1
0
        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);
            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);
        }
示例#3
0
        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;
        }
示例#4
0
        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;
                        }
                    };
                }
            }
        }
示例#5
0
        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;
            });
        }
示例#6
0
        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));
        }
示例#7
0
        protected override void Open()
        {
            dispose += DemoHelper.BasicDemoSetup(DemoInfo);


            Scene.Engine.AddLogic(new GravityField(new Vector2D(0, 1000), new Lifespan()));

            List <Body> chain = DemoHelper.AddChain(DemoInfo, new Vector2D(400, 50), 100, 30, 200, 20, 800);
            Vector2D    point = new Vector2D(300, 50);

            Body Anchor = DemoHelper.AddCircle(DemoInfo, 30, 18, Scalar.PositiveInfinity, new ALVector2D(0, point));

            Anchor.IgnoresGravity = true;
            HingeJoint joint = new HingeJoint(chain[0], Anchor, point, new Lifespan());

            joint.DistanceTolerance = 10;
            Scene.Engine.AddJoint(joint);
        }
示例#8
0
        protected override void Open()
        {
            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 shape = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("block.png"), 3, 7, 4);


            DemoHelper.AddGrid(
                DemoInfo, shape, 20,
                new BoundingRectangle(300, 500, 900, 710),
                50, 2);

            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)));
        }
示例#9
0
        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()));

            IShape shape = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("block.png"), 3, 7, 4);

            DemoHelper.AddGrid(
                DemoInfo, shape, 20,
                new BoundingRectangle(400, 200, 500, 510),
                50, 2);


            Scalar      boxlength    = 50;
            Scalar      spacing      = 4;
            Scalar      anchorLenght = 30;
            Scalar      anchorGap    = (boxlength / 2) + spacing + (anchorLenght / 2);
            List <Body> chain        = DemoHelper.AddChain(DemoInfo, new Vector2D(200, 500), boxlength, 20, 200, spacing, 600);

            Vector2D point2 = new Vector2D(chain[chain.Count - 1].State.Position.Linear.X + anchorGap, 500);
            Body     end2   = DemoHelper.AddCircle(DemoInfo, anchorLenght / 2, 14, Scalar.PositiveInfinity, new ALVector2D(0, point2));

            end2.IgnoresGravity = true;
            HingeJoint joint2 = new HingeJoint(chain[chain.Count - 1], end2, point2, new Lifespan());

            joint2.DistanceTolerance = 10;
            Scene.Engine.AddJoint(joint2);

            Vector2D point1 = new Vector2D(chain[0].State.Position.Linear.X - anchorGap, 500);
            Body     end1   = DemoHelper.AddCircle(DemoInfo, anchorLenght / 2, 14, Scalar.PositiveInfinity, new ALVector2D(0, point1));

            end1.IgnoresGravity = true;
            HingeJoint joint1 = new HingeJoint(chain[0], end1, point1, new Lifespan());

            joint1.DistanceTolerance = 10;
            Scene.Engine.AddJoint(joint1);
            end2.State.Position.Linear.X -= 10;
            end1.State.Position.Linear.X += 10;
            end2.ApplyPosition();
            end1.ApplyPosition();
        }
示例#10
0
        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;
        }
示例#11
0
        private void DoGuns(Body body, Body enemy, Key fire)
        {
            //this method requires a deep understanding of delegates and events. ENJOY :P
            Scalar projectileSpeed  = 500;
            Scalar projectileRadius = 3;
            Scalar projectileMass   = 3;

            BoundingRectangle rect;
            Matrix2x3         ident = Matrix2x3.Identity;

            body.Shape.CalcBoundingRectangle(ref ident, out rect);


            DateTime lastFire = DateTime.Now;
            Scalar   distance = rect.Max.X + projectileRadius * 2;
            EventHandler <KeyboardEventArgs> keyDown = delegate(object sender, KeyboardEventArgs e)
            {
                DateTime now = DateTime.Now;
                if (e.Key == fire &&
                    !body.Lifetime.IsExpired &&
                    now.Subtract(lastFire).TotalSeconds > .3)
                {
                    lastFire = now;
                    Vector2D normal      = body.Matrices.ToWorldNormal * Vector2D.XAxis;
                    Vector2D position    = new Vector2D(body.Matrices.ToWorld.m02, body.Matrices.ToWorld.m12) + (normal * distance);
                    Vector2D offset      = normal.LeftHandNormal * 3 * projectileRadius;
                    Body     projectile1 = DemoHelper.AddCircle(DemoInfo, projectileRadius, 8, projectileMass, new ALVector2D(0, position + offset));
                    Body     projectile2 = DemoHelper.AddCircle(DemoInfo, projectileRadius, 8, projectileMass, new ALVector2D(0, position - offset));
                    projectile1.Lifetime.MaxAge = 5;
                    projectile2.Lifetime.MaxAge = 5;
                    Vector2D velocity = normal * projectileSpeed;
                    body.State.Velocity.Linear       -= (projectileMass * 2 * velocity) * body.Mass.MassInv;
                    projectile1.State.Velocity.Linear = velocity + body.State.Velocity.Linear;
                    projectile2.State.Velocity.Linear = velocity + body.State.Velocity.Linear;
                    EventHandler <CollisionEventArgs> collided = delegate(object sender1, CollisionEventArgs e1)
                    {
                        Body projectile = (Body)sender1;
                        projectile.Lifetime.IsExpired = true;
                        bool isHit = e1.Other == enemy || e1.Other == body;

                        List <Body> particles = DemoHelper.AddParticles(
                            DemoInfo,
                            projectile.State.Position.Linear,
                            projectile.State.Velocity.Linear,
                            (isHit) ? (200) : (10));
                        if (isHit && !e1.Other.Lifetime.IsExpired)
                        {
                            ExplosionLogic explosionLogic = new ExplosionLogic(
                                e1.Other.State.Position.Linear,
                                e1.Other.State.Velocity.Linear,
                                9000, .1f, e1.Other.Mass.Mass,
                                new Lifespan(.5f));
                            Scene.Engine.AddLogic(explosionLogic);
                            e1.Other.Lifetime.IsExpired = true;
                            particles[0].Removed       += delegate(object sender2, RemovedEventArgs e2)
                            {
                                if (particles[0].Lifetime.IsExpired)
                                {
                                    e1.Other.State.Velocity = ALVector2D.Zero;
                                    e1.Other.State.Position = new ALVector2D(DemoHelper.NextScalar(-600, 900), DemoHelper.NextScalar(-600, 900), DemoHelper.NextScalar(-600, 900));
                                    e1.Other.ApplyPosition();
                                    e1.Other.Lifetime.IsExpired = false;
                                    Scene.AddGraphic((BodyGraphic)e1.Other.Tag);
                                }
                            };
                        }
                        else if (e1.Other.Shape is CircleShape &&
                                 !e1.Other.IgnoresCollisionResponse)
                        {
                            e1.Other.Lifetime.IsExpired = true;
                        }
                    };
                    projectile1.Collided += collided;
                    projectile2.Collided += collided;
                }
            };

            Events.KeyboardDown += keyDown;
            dispose             += delegate()
            {
                Events.KeyboardDown -= keyDown;
            };
        }