当前位置: 首页>>代码示例>>C#>>正文


C# World.Step方法代码示例

本文整理汇总了C#中FarseerPhysics.Dynamics.World.Step方法的典型用法代码示例。如果您正苦于以下问题:C# World.Step方法的具体用法?C# World.Step怎么用?C# World.Step使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FarseerPhysics.Dynamics.World的用法示例。


在下文中一共展示了World.Step方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ChangeCentroidTest0

        public void ChangeCentroidTest0()
        {
            Scene scene = new Scene();
            FloatPortal portal0 = new FloatPortal(scene);
            FloatPortal portal1 = new FloatPortal(scene);
            portal0.SetTransform(new Transform2(new Vector2(0, 0), 1, (float)Math.PI / 2));
            portal1.SetTransform(new Transform2(new Vector2(10, 0), 2, (float)Math.PI / 2));
            Portal.SetLinked(portal0, portal1);
            PortalCommon.UpdateWorldTransform(scene);

            World world = new World(new Xna.Vector2(0, 0f));
            Body body0 = Factory.CreateBox(world, new Vector2(1, 2));
            Body body1 = Factory.CreateBox(world, new Vector2(1, 2));

            Xna.Vector2 startPos = new Xna.Vector2(0, 1);
            body0.Position = startPos;
            body1.Position = startPos;
            Portal.Enter(portal0, body1);

            PortalJoint portalJoint = Factory.CreatePortalJoint(world, body0, body1, portal0);

            for (int i = 0; i < 10; i++)
            {
                body0.LocalCenter += new Xna.Vector2(0, 0.1f);
                body1.LocalCenter += new Xna.Vector2(0, 0.1f);

                world.Step(1 / (float)60);
                Assert.IsTrue(body0.Position == startPos);
            }
        }
开发者ID:AyyTee,项目名称:Aventyr,代码行数:30,代码来源:PortalJointTests.cs

示例2: PortalJointTest1

        public void PortalJointTest1()
        {
            Scene scene = new Scene();
            FloatPortal portal0 = new FloatPortal(scene);
            FloatPortal portal1 = new FloatPortal(scene);
            portal0.SetTransform(new Transform2(new Vector2(), 1, 0, true));
            portal1.SetTransform(new Transform2(new Vector2(10, 0), 1, 0));
            portal0.Linked = portal1;
            portal1.Linked = portal0;
            PortalCommon.UpdateWorldTransform(scene);

            World world = new World(new Xna.Vector2(0, 0f));
            Body body0 = Factory.CreateBox(world, new Vector2(1, 2));
            Body body1 = Factory.CreateBox(world, new Vector2(1, 2));
            Portal.Enter(portal0, body1);

            PortalJoint portalJoint = Factory.CreatePortalJoint(world, body0, body1, portal0);

            world.Step(1 / (float)60);

            AssertPortalJoint(body0, body1, portal0);
        }
开发者ID:AyyTee,项目名称:Aventyr,代码行数:22,代码来源:PortalJointTests.cs

示例3: Main

        static void Main()
        {
            window = new RenderWindow(new VideoMode(1280, 720), "", Styles.Close);
            window.SetFramerateLimit(60);
            window.Closed += (sender, eventArgs) => window.Close();

            shipTex = new Texture("Ship.png");
            asteroidTex = new Texture("Asteroid.png");

            var shipSpr = new Sprite(shipTex);
            shipSpr.Origin = new Vector2f(shipTex.Size.X / 2f, shipTex.Size.Y / 2f);

            var asteroidSpr = new Sprite(asteroidTex);
            asteroidSpr.Origin = new Vector2f(asteroidTex.Size.X / 2f, asteroidTex.Size.Y / 2f);

            world = new World(new Vector2(0, 0));

            var debugView = new SFMLDebugView(world);
            debugView.AppendFlags(DebugViewFlags.Shape);

            CreateBounds(20, 11.25f);

            var ship = CreateShip();
            ship.Position = new Vector2(3, 1);
            ship.Rotation = 1.7f;

            var ship2 = CreateShip();
            ship2.Position = new Vector2(3, 1);
            ship2.Rotation = 1.7f;

            var asteroid = CreateAsteroid();
            asteroid.Position = new Vector2(4, 4);

            window.KeyPressed += (sender, eventArgs) =>
            {
                if (eventArgs.Code == Keyboard.Key.Space)
                {
                    CreateBullets(ship);
                }
            };

            while (window.IsOpen())
            {
                window.DispatchEvents();

                if (Keyboard.IsKeyPressed(Keyboard.Key.W))
                {
                    ship.ApplyForce(ship.GetWorldVector(new Vector2(0.0f, -25.0f)));
                }

                if (Keyboard.IsKeyPressed(Keyboard.Key.S))
                {
                    ship.ApplyForce(ship.GetWorldVector(new Vector2(0.0f, 25.0f)));
                }

                if (Keyboard.IsKeyPressed(Keyboard.Key.A))
                {
                    ship.ApplyTorque(-10);
                }

                if (Keyboard.IsKeyPressed(Keyboard.Key.D))
                {
                    ship.ApplyTorque(10);
                }

                world.Step(1f / 60);

                window.Clear(Color.Black);

                shipSpr.Position = new Vector2f(ship.Position.X * 64, ship.Position.Y * 64);
                shipSpr.Rotation = (ship.Rotation * (180 / (float)Math.PI));
                window.Draw(shipSpr);

                asteroidSpr.Position = new Vector2f(asteroid.Position.X * 64, asteroid.Position.Y * 64);
                asteroidSpr.Rotation = (asteroid.Rotation * (180 / (float)Math.PI));
                window.Draw(asteroidSpr);

                var start = ship.Position;
                var step = (float)(2 * Math.PI) / 200;
                byte col = 0;
                var line = new VertexArray(PrimitiveType.Lines, 2);
                line[0] = new Vertex(new Vector2f(start.X * 64, start.Y * 64), Color.White);
                for (var dir = 0f; dir <= 2 * Math.PI; dir += step)
                {
                    float min = 100;
                    byte res = 255;
                    var point = start + LengthDir(dir, 20);
                    world.RayCast((f, p, n, fr) =>
                    {
                        if (fr > min)
                            return 1;

                        min = fr;
                        res = (byte)(fr * 255);
                        point = p;
                        return fr;
                    }, start, point);

                    line[0] = new Vertex(new Vector2f(start.X * 64, start.Y * 64), new Color(col, 0, 0));
                    line[1] = new Vertex(new Vector2f(point.X * 64, point.Y * 64), new Color(col, 0, 0));
//.........这里部分代码省略.........
开发者ID:Rohansi,项目名称:Programe,代码行数:101,代码来源:Program.cs

示例4: Initialize

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            mines = new List<Mine>();
            explosions = new List<Explosion>();
            weaponCharges = new List<IPowerup>();
            bombs = new List<Bomb>();

            world = new World(new Vector2(0.0f, -20f));

            PrimitiveDrawing.SetUp(this.world);
            //FarseerPhysics.Settings.EnableDiagnostics = false;
            FarseerPhysics.Settings.MaxPolygonVertices = 30;

            highScore = 20; //TODO

            world.Clear();
            shielded = false;
            botherBall = null;
            speedTimer = 0;
            timeSinceStart = 0;
            touchedGround = true;
            score = 0;
            ball = BodyFactory.CreateCircle(world, 1.5f, 1f, new Vector2(0.0f, 3f), ballColor);
            ball.BodyType = BodyType.Dynamic;
            ball.Friction = 10;
            floorBody = new Body(world)
            {
                BodyType = BodyType.Static,
                Position = Vector2.Zero,
                FixedRotation = true
            };
            currentFloorLength = 0;
            BodyFactory.CreateRectangle(world, 4f, (float)(1706665.0 / 512.0), 1f, new Vector2(-35.4333f, ball.Position.Y), Color.Black).Friction = 0.0f;
            BodyFactory.CreateRectangle(world, 4f, (float)(1706665.0 / 512.0), 1f, new Vector2(35.3333f, ball.Position.Y), Color.Black).Friction = 0.0f;
            highScoreLine = BodyFactory.CreateRectangle(
                world,
                66.6666f,
                (float)(66.6666030883789 / (double)this.GraphicsDevice.Viewport.AspectRatio / 40.0),
                1f,
                new Vector2(0.0f, (float)(-this.highScore - 66.6666030883789 / (double)this.GraphicsDevice.Viewport.AspectRatio / 80.0)),
                Color.Red
            );
            highScoreLine.IsStatic = true;
            highScoreLine.IsSensor = true;
            ball.OnCollision += Ball_OnCollision;
            world.Step(1000);

            base.Initialize();
        }
开发者ID:Learn-app-ios,项目名称:FallingBombs,代码行数:55,代码来源:Game1.cs


注:本文中的FarseerPhysics.Dynamics.World.Step方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。