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

            IShape fighterShape = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("fighter.png"), 4, 50, 5);
            Body   fighter      = new Body(new PhysicsState(new ALVector2D(0, 300, 300)), fighterShape, 5000, new Coefficients(0, 1), new Lifespan());

            fighter.State.Velocity.Angular = 9;
            fighter.Mass.MomentOfInertia   = Scalar.PositiveInfinity;

            BodyGraphic fighterGraphic = new BodyGraphic(fighter);

            Scene.AddGraphic(fighterGraphic);

            BodyGraphic fighterGraphic2 = (BodyGraphic)fighterGraphic.Duplicate();

            fighterGraphic2.Body.State.Position.Linear.Y = 500;
            fighterGraphic2.Body.State.Velocity.Angular  = -8.5f;
            Scene.AddGraphic(fighterGraphic2);


            Body      template2 = new Body(new PhysicsState(new ALVector2D(0, 200, 200)), ParticleShape.Default, 4, new Coefficients(0, 1), new Lifespan());
            Matrix2x3 m         = Matrix2x3.FromRotationZ(2);
            int       count     = 0;

            for (int x = -0; x < 1000; x += 25)
            {
                for (int y = -0; y < 1000; y += 25)
                {
                    count++;
                    Body body = template2.Duplicate();
                    body.State.Position.Linear = new AdvanceMath.Vector2D(x, y);
                    body.ApplyPosition();
                    body.State.Velocity.Linear.X = (250 - x) / 10f;
                    body.State.Velocity.Linear.Y = (250 - y) / 10f;
                    body.State.Velocity.Linear   = m * body.State.Velocity.Linear;
                    body.LinearDamping           = .9999f;
                    BodyGraphic g1 = new BodyGraphic(body);
                    Scene.AddGraphic(g1);
                }
            }
            Scene.Engine.AddLogic(new GravityPointField(new Vector2D(400, 400), 500, new Lifespan()));
        }
示例#4
0
        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));
        }
示例#5
0
        public static Body AddLine(DemoOpenInfo info, Vector2D point1, Vector2D point2, Scalar thickness, Scalar mass)
        {
            Vector2D line   = point1 - point2;
            Vector2D avg    = (point1 + point2) * .5f;
            Scalar   length = line.Magnitude;
            Scalar   angle  = line.Angle;

            Scalar Hd2 = thickness * .5f;
            Scalar Wd2 = length * .5f;

            int    curveEdgeCount = 5;
            Scalar da             = MathHelper.Pi / curveEdgeCount;

            List <Vector2D> vertexes = new List <Vector2D>();

            vertexes.Add(new Vector2D(Wd2, Hd2));
            vertexes.Add(new Vector2D(-Wd2, Hd2));
            for (Scalar angle2 = MathHelper.PiOver2 + da; angle2 < MathHelper.ThreePiOver2; angle2 += da)
            {
                vertexes.Add(new Vector2D(-Wd2, 0) + Vector2D.FromLengthAndAngle(Hd2, angle2));
            }
            vertexes.Add(new Vector2D(-Wd2, -Hd2));
            vertexes.Add(new Vector2D(Wd2, -Hd2));
            for (Scalar angle2 = -MathHelper.PiOver2 + da; angle2 < MathHelper.PiOver2; angle2 += da)
            {
                vertexes.Add(new Vector2D(Wd2, 0) + Vector2D.FromLengthAndAngle(Hd2, angle2));
            }
            IShape shape = ShapeFactory.CreateColoredPolygon(vertexes.ToArray(), thickness / 4);

            Body body = new Body(
                new PhysicsState(new ALVector2D(0, avg)),
                shape,
                mass,
                Coefficients.Duplicate(),
                new Lifespan());

            body.Transformation = Matrix2x3.FromRotationZ(angle);
            body.ApplyPosition();
            info.Scene.AddGraphic(CreateGraphic(body));
            return(body);
        }