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


C# PhysicsSimulator.Add方法代码示例

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


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

示例1: Load

        public void Load(PhysicsSimulator physicsSimulator, GraphicsDevice device)
        {
            Random rand = new Random();

            physicsSimulator.Add(_topBody);
            physicsSimulator.Add(_rightLegBody);
            physicsSimulator.Add(_leftLegBody);
            physicsSimulator.Add(_topGeom);
            physicsSimulator.Add(_rightLegGeom);
            physicsSimulator.Add(_leftLegGeom);

            _leftWeldJoint = new WeldJoint(_leftLegBody, _topBody, _leftLegBody.Position - new Vector2(-5, _height / 2));
            _leftWeldJoint.Breakpoint = (float)rand.NextDouble() * 3f + 1f;
            _leftWeldJoint.Broke += _leftWeldJoint_Broke;
            physicsSimulator.Add(_leftWeldJoint);

            _rightWeldJoint = new WeldJoint(_rightLegBody, _topBody, _rightLegBody.Position - new Vector2(5, _height / 2));
            _rightWeldJoint.Breakpoint = (float)rand.NextDouble() * 3f + 1f;
            _rightWeldJoint.Broke += _rightWeldJoint_Broke;
            physicsSimulator.Add(_rightWeldJoint);

            _topBrush = new PolygonBrush(_topGeom.LocalVertices, Color.BurlyWood, Color.Black, 1.0f, 0.5f);
            _leftBrush = new PolygonBrush(_leftLegGeom.LocalVertices, Color.BurlyWood, Color.Black, 1.0f, 0.5f);
            _rightBrush = new PolygonBrush(_rightLegGeom.LocalVertices, Color.BurlyWood, Color.Black, 1.0f, 0.5f);

            _topBrush.Load(device);
            _leftBrush.Load(device);
            _rightBrush.Load(device);
        }
开发者ID:rpwjanzen,项目名称:2HourGame,代码行数:29,代码来源:Table.cs

示例2: CreateBorder

        private void CreateBorder(Rectangle rectangle, PhysicsSimulator physicsSimulator)
        {
            var borderWidth = rectangle.Width;
            var borderHeight = rectangle.Height;
            var borderCenter = CalculateCenter(rectangle);

            var borderBody = BodyFactory.Instance.CreateRectangleBody(borderWidth, borderHeight, 1.0f);
            borderBody.IsStatic = true;
            borderBody.Position = borderCenter;
            physicsSimulator.Add(borderBody);

            var borderGeometry = GeomFactory.Instance.CreateRectangleGeom(borderBody, borderWidth, borderHeight);
            // prevent collisions with cannon balls
            borderGeometry.CollisionCategories = ((CollisionCategoryManager)game.Services.GetService(typeof(CollisionCategoryManager))).getCollisionCategory(this.GetType());
            borderGeometry.CollidesWith = ((CollisionCategoryManager)game.Services.GetService(typeof(CollisionCategoryManager))).getCollidesWith(this.GetType());
            physicsSimulator.Add(borderGeometry);
        }
开发者ID:rpwjanzen,项目名称:2HourGame,代码行数:17,代码来源:WorldBorder.cs

示例3: SpriteManager

        public SpriteManager(Game game, Fighter lutador1, Fighter lutador2)
            : base(game)
        {
            this.lutador1 = lutador1;
            this.lutador2 = lutador2;
            simulador = new PhysicsSimulator(new Vector2(0, 10));
            //simulador.Add(lutador1.Body);
            //simulador.Add(lutador1.Geometry);

            groundBody = BodyFactory.Instance.CreateRectangleBody( 800, 10, 1);
            groundGeom = GeomFactory.Instance.CreateRectangleGeom(groundBody, 800, 10);
            groundBody.Position = new Vector2(0, 550);
            groundBody.IsStatic = true;
            groundGeom.RestitutionCoefficient = .2f;
            groundGeom.FrictionCoefficient = .2f;

            barra = ContentManagerFacade.Load<Texture2D>("barra");
            simulador.Add(groundBody);
            simulador.Add(groundGeom);
        }
开发者ID:lucassimao,项目名称:XNA-Street-Fighter,代码行数:20,代码来源:SpriteManager.cs

示例4: CreateRectangleGameObject

 public static GameObject CreateRectangleGameObject(PhysicsSimulator simulator, string resourceName, float width, float height, float mass)
 {
     var go = new GameObject();
     go.ResourceName = resourceName;
     go.Body = BodyFactory.Instance.CreateRectangleBody(width,height, mass);
     go.Geom = GeomFactory.Instance.CreateRectangleGeom(simulator,go.Body, width, height);
     simulator.Add(go.Body);
     simulator.Add(go.Geom);
     return go;
 }
开发者ID:braahyan,项目名称:Platformer,代码行数:10,代码来源:GameObject.cs

示例5: CreateCircleGameObject

 public static GameObject CreateCircleGameObject(PhysicsSimulator simulator, string resourceName, float rad, float mass)
 {
     var go  = new GameObject();
     go.Body = BodyFactory.Instance.CreateCircleBody(rad, mass);
     go.Geom = GeomFactory.Instance.CreateCircleGeom(simulator, go.Body, rad, 20);
     go.ResourceName = resourceName;
     simulator.Add(go.Body);
     simulator.Add(go.Geom);
     return go;
 }
开发者ID:braahyan,项目名称:Platformer,代码行数:10,代码来源:GameObject.cs

示例6: AddToPhysicsSimulator

 /// <summary>
 /// Adds to physics simulator.
 /// </summary>
 /// <param name="physicsSimulator">The physics simulator.</param>
 public void AddToPhysicsSimulator(PhysicsSimulator physicsSimulator)
 {
     foreach (Body body in _bodies)
         physicsSimulator.Add(body);
     foreach (Geom geom in _geoms)
         physicsSimulator.Add(geom);
     foreach (Joint joint in _joints)
         physicsSimulator.Add(joint);
     foreach (Spring spring in _springs)
         physicsSimulator.Add(spring);
 }
开发者ID:amwaterston,项目名称:paradux,代码行数:15,代码来源:Path.cs

示例7: 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()
        {
            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 600;
            graphics.SynchronizeWithVerticalRetrace = false;
            graphics.ApplyChanges();

            assets = new Dictionary<string, Texture2D>();
            gameObjects = new List<GameObject>();

            phySim = new PhysicsSimulator(new Vector2(0, -200));

            var ballObject = GameObjectFactory.CreateCircleGameObject(phySim, "ball", 22f, 1);
            ballObject.Center = new Vector2(250, 400);
            ballObject.Geom.FrictionCoefficient = 0;

            FixedAngleJoint asdf = new FixedAngleJoint(ballObject.Body, 0);
            phySim.Add(asdf);

            player = ballObject;
            gameObjects.Add(ballObject);

            var platformObject = GameObjectFactory.CreateRectangleGameObject(phySim, "platform", 256, 64, 6);
            platformObject.IsStatic = true;
            platformObject.Center = new Vector2(250, 300);
            platformObject.Rotation = MathHelper.ToRadians(-30f);

            var platformObject2 = GameObjectFactory.CreateRectangleGameObject(phySim, "platform", 256, 64, 6);
            platformObject2.Center = new Vector2(5, 150);
            platformObject2.Rotation = MathHelper.ToRadians(90f);
            platformObject2.Geom.FrictionCoefficient = 10;

            var floorObject = GameObjectFactory.CreateRectangleGameObject(phySim, "floor", 1024, 12, 1);
            floorObject.Center = new Vector2(500, 0);
            floorObject.IsStatic = true;
            floorObject.Geom.FrictionCoefficient = 1;

            camera = new Camera2d(new Vector2(0, 0), new Vector2(800, 600), new Vector2(100, 100));

            gameObjects.Add(floorObject);
            gameObjects.Add(platformObject2);
            gameObjects.Add(platformObject);

            base.Initialize();
        }
开发者ID:braahyan,项目名称:Platformer,代码行数:51,代码来源:Game1.cs

示例8: Initialize

        public void Initialize(PhysicsSimulator physicsSimulator)
        {
            //The wave controller controls how the waves move.. how big, how fast, etc..
            //The wave controller is represented as set of points equally
            //spaced horizontally along the width of the wave.
            WaveController = new WaveController();
            WaveController.Position = ConvertUnits.ToSimUnits(0, 300);
            WaveController.Width = ConvertUnits.ToSimUnits(700);
            WaveController.Height = ConvertUnits.ToSimUnits(200);
            WaveController.NodeCount = 20; //how many vertices make up the surface of the wave
            WaveController.DampingCoefficient = .95f; //determines how quickly the wave will disipate
            WaveController.Frequency = .16f; //determines how fast the wave algorithm runs (seconds)

            //The wave generator parameters simply move an end-point of the wave up and down.
            //Think of a string attached to a wall on one end and held by a person on the other.
            //If the person moves the string up and down to make "waves" then the arm is acting
            //similar to the wave generator. The WaveGeneratorStep property controls how fast the "arm"
            //moves.
            WaveController.WaveGeneratorMax = WaveGeneratorMax;
            WaveController.WaveGeneratorMin = WaveGeneratorMin;
            WaveController.WaveGeneratorStep = WaveGeneratorStep;

            WaveController.Initialize();

            //fluid drag controller controls how things move once IN the water.
            FluidDragController = new FluidDragController();
            FluidDragController.Initialize(WaveController, 5f, 4f, 2f, physicsSimulator.Gravity);
            //init with default values.
            physicsSimulator.Add(FluidDragController);
        }
开发者ID:rbrother,项目名称:seikkailulaakso,代码行数:30,代码来源:WaterModel.cs

示例9: Load

 public virtual bool Load(string assetName, ContentManager content, PhysicsSimulator simulator)
 {
     currentTexture = content.Load<Texture2D>(assetName);
     origin = new Vector2(currentTexture.Width / 2, currentTexture.Height / 2);
     body = BodyFactory.Instance.CreateRectangleBody(currentTexture.Height, currentTexture.Width, 1);
     geom = GeomFactory.Instance.CreateRectangleGeom(body, currentTexture.Width, currentTexture.Height);
     body.Position = position;
     body.Tag = this;
     geom.Tag = this;
     simulator.Add(body);
     simulator.Add(geom);
     return true;
 }
开发者ID:ninetailsdev,项目名称:Quark,代码行数:13,代码来源:Sprite.cs

示例10: Load

        public void Load(GraphicsDevice graphicsDevice, PhysicsSimulator physicsSimulator)
        {
            _rectangleTexture = DrawingHelper.CreateRectangleTexture(graphicsDevice, RectangleWidth, RectangleHeight,
                                                                     Color.White, Color.Black);
            int radius;
            if (AttachPoint == 0 | AttachPoint == 2)
            {
                radius = RectangleHeight;
            }
            else
            {
                radius = RectangleWidth;
            }
            _circleTexture = DrawingHelper.CreateCircleTexture(graphicsDevice, radius, Color.White, Color.Black);

            //body is created as rectangle so that it has the moment of inertia closer to the final shape of the object.
            Body = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, RectangleWidth,
                                                                             RectangleHeight, 1f);

            _rectangleGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, Body,
                                                                      RectangleWidth, RectangleHeight);
            _rectangleGeom.FrictionCoefficient = .5f;
            _rectangleGeom.CollisionGroup = CollisionGroup;

            Vector2 offset = Vector2.Zero;
            switch (AttachPoint)
            {
                case 0:
                    {
                        offset = new Vector2(-RectangleWidth/2f, 0); //offset to rectangle to left
                        break;
                    }
                case 1:
                    {
                        offset = new Vector2(0, -RectangleHeight/2f); //offset to rectangle to top
                        break;
                    }
                case 2:
                    {
                        offset = new Vector2(RectangleWidth/2f, 0); //offset to rectangle to right
                        break;
                    }
                case 3:
                    {
                        offset = new Vector2(0, RectangleHeight/2f); //offset to rectangle to bottom
                        break;
                    }
            }

            Body.Position = Position - offset;

            _circleGeom = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, Body, radius, 20,
                                                                offset, 0);
            _circleGeom.FrictionCoefficient = .5f;
            _circleGeom.CollisionGroup = CollisionGroup;

            _revoluteJoint = JointFactory.Instance.CreateFixedRevoluteJoint(physicsSimulator, Body,
                                                                            Position);
            physicsSimulator.Add(_revoluteJoint);
            SpringFactory.Instance.CreateFixedAngleSpring(physicsSimulator, Body,
                                                          SpringConstant, DampingConstant);
        }
开发者ID:irpx,项目名称:SpacePenguinShooter,代码行数:62,代码来源:AngularSpringLever.cs

示例11: add

 public void add(PhysicsSimulator physics)
 {
         physics.Add(body);
         physics.Add(geom);
 }
开发者ID:danielselnick,项目名称:Sentry-Smash,代码行数:5,代码来源:gunit.cs

示例12: 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()
        {
            phsX = new PhysicsSimulator(); //Create physX
            //phsX.Iterations = 5;

            //phsX.Gravity = new Vector2(0, (float)9.8);

            // TODO: Add your initialization logic here
            Random r = new Random();

            for (int x = 48; x < 230; x += 64)
            {
                for (int y = 48; y < 200; y += 48)
                {
                    Body rectangleBody;
                    rectangleBody = BodyFactory.Instance.CreateRectangleBody(phsX, 32, 32, 1);
                    rectangleBody.Position = new Vector2(x, y);
                    phsX.Add(GeomFactory.Instance.CreateRectangleGeom(phsX, rectangleBody, 32, 32));
                }
            }

            //Body leftCorner;
            leftCorner = BodyFactory.Instance.CreateRectangleBody(phsX, 10, 480, 100000);
            leftCorner.Position = new Vector2(5, 240);

            //Body rightCorner;
            rightCorner = BodyFactory.Instance.CreateRectangleBody(phsX, 10, 480, 100000);
            rightCorner.Position = new Vector2(267, 240);

            //Body topCorner;
            topCorner = BodyFactory.Instance.CreateRectangleBody(phsX, 272, 10, 100000);
            topCorner.Position = new Vector2(136, 5);

            //Body bottomCorner;
            bottomCorner = BodyFactory.Instance.CreateRectangleBody(phsX, 272, 10, 100000);
            bottomCorner.Position = new Vector2(136, 475);

            Geom gl = GeomFactory.Instance.CreateRectangleGeom(leftCorner, 10, 480);
            Geom gr = GeomFactory.Instance.CreateRectangleGeom(rightCorner, 10, 480);
            Geom gu = GeomFactory.Instance.CreateRectangleGeom(topCorner, 272, 10);
            Geom gb = GeomFactory.Instance.CreateRectangleGeom(bottomCorner, 272, 10);

            gl.Body.IsStatic = true;
            gr.Body.IsStatic = true;
            gu.Body.IsStatic = true;
            gb.Body.IsStatic = true;

            phsX.Add(gl);
            phsX.Add(gr);
            phsX.Add(gu);
            phsX.Add(gb);

            base.Initialize();
        }
开发者ID:BGCX261,项目名称:zna-hd-svn-to-git,代码行数:60,代码来源:Game1.cs

示例13: Initialize

        public override void Initialize()
        {
            PhysicsSimulator = new PhysicsSimulator(new Vector2(0, 150));

            // This distance has to be big enough to make sure all objects are reactivated
            // before they could collide with an currently active object
            // our biggest object is 25*25 -> 120 would be big enough
            InactivityController controller = new InactivityController(PhysicsSimulator);
            controller.ActivationDistance = 120;

            // Deactivate the object after 2 seconds of idle time
            controller.MaxIdleTime = 2000;
            controller.Enabled = true;

            PhysicsSimulator.Add(controller);
            PhysicsSimulatorView = new PhysicsSimulatorView(PhysicsSimulator);

            base.Initialize();
        }
开发者ID:rbrother,项目名称:seikkailulaakso,代码行数:19,代码来源:Demo2Screen.cs


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