예제 #1
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));
        }
예제 #2
0
        /// <summary>
        /// Call this to start the demo
        /// (Entry Point)
        /// </summary>
        public static void Run()
        {
            //do this becuase .Net has been erroring with file permissions
            //just leave this line it.
            string dir = Settings.DataDir;


            //create a new window to display stuff
            Window window = new Window(new System.Drawing.Size(1000, 750));

            window.Title = "Physics2D.Net Demo";


            //Create a new Scene
            Scene scene = new Scene();

            //Get the scene's physics engine
            PhysicsEngine physicsEngine = scene.Engine;

            //initialize the engine
            physicsEngine.BroadPhase = new Physics2DDotNet.Detectors.SweepAndPruneDetector();
            //physicsEngine.BroadPhase = new Physics2DDotNet.Detectors.SpatialHashDetector();
            Physics2DDotNet.Solvers.SequentialImpulsesSolver solver = new Physics2DDotNet.Solvers.SequentialImpulsesSolver();
            //solver.Iterations = 3;
            solver.Freezing      = true;
            physicsEngine.Solver = solver;
            //physicsEngine.Solver = new Physics2DDotNet.Solvers.Box2DSolver();



            Viewport viewport = new Viewport(
                new Rectangle(0, 0, window.Size.Width, window.Size.Height), //where
                Matrix2x3.Identity,                                         //how
                scene,                                                      //who
                new Lifespan());                                            // how long

            window.AddViewport(viewport);

            // you can change the veiwport via this
            viewport.ToScreen = Matrix2x3.FromTransformation(.09f, new Vector2D(40, 0));

            //make it so the veiwport will be resized whn the window is
            window.Resized += delegate(object sender, SizeEventArgs e)
            {
                viewport.Width  = e.Width;
                viewport.Height = e.Height;
            };
            System.Windows.Forms.Application.EnableVisualStyles();
            //create the GUI
            DemoSelector selector = new DemoSelector();

            //initialize the GUI
            selector.Initialize(window, viewport, scene);
            //Create the window
            window.Intialize();
            window.DrawingInterval = .02f;
            //Add some intro text
            AddIntroText(window, viewport, scene);

            SetupStatus(window, scene);


            //Show the GUI
            selector.Show();
            //start the physicstimer for Layer.PhysicsEngine
            scene.Timer.IsRunning = true;
            //Begin the rendering loop.
            window.Run();
            return;
        }