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


C# Body.IgnoreCollisionWith方法代码示例

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


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

示例1: Bullet

        public Bullet(World world, Car _car, Texture2D _dummyTexture)
        {
            car = _car;
            dummyTexture = _dummyTexture;

            bulletPhysicsObject=  BodyFactory.CreateRectangle(world, 0.1f, 0.1f, 1f, Vector2.Zero);
            bulletPhysicsObject.BodyType = BodyType.Dynamic;

            bulletPhysicsObject.IsSensor = true;
            bulletPhysicsObject.IsBullet = true;

            isGoing = false;

            bulletPhysicsObject.IgnoreCollisionWith(car._compound);

            bulletPhysicsObject.CollisionCategories = Category.Cat20;

            bulletPhysicsObject.OnCollision += bullet_OnCollision;
            graphics = GameServices.GetService<GraphicsDeviceManager>();

            pencilTexture = GameServices.GetService<ContentManager>().Load<Texture2D>("Images/pencilTextire");

            laserVertices = new VertexPositionColorTexture[6];

            laserVertices[0].Color = car.mColor;
            laserVertices[1].Color = car.mColor;
            laserVertices[2].Color = car.mColor;
            laserVertices[3].Color = car.mColor;
            laserVertices[4].Color = car.mColor;
            laserVertices[5].Color = car.mColor;

            laserSound = GameServices.GetService<ContentManager>().Load<SoundEffect>("Sounds/laserorribiledimmerda");

            laserSoundInstance=laserSound.CreateInstance();
        }
开发者ID:rroveri,项目名称:triolozzi,代码行数:35,代码来源:Bullet.cs

示例2: Player

        /// <summary>
        ///  Player constructor
        /// </summary>
        /// <param name="a_world">World reference</param>          
        /// <param name="a_texture">Texture reference</param>        
        /// <param name="a_startPosition">Starting Position</param>  
        /// <param name="a_size">Sizing</param>           
        /// <param name="a_bodyType">Type of body? Dynamic, Static or Kenetic?</param>       
        /// <param name="mass">Weight of mass</param>             
        public Player(World a_world, Texture2D a_texture, Vector2 a_startPosition, Vector2 a_size, float mass)
        {
            Vector2 bodySize = new Vector2(a_size.X, a_size.Y);

            //Assigning arguments
            m_texture = a_texture;
            m_size = bodySize;
            m_colour = Color.White;
            m_speed = 10.0f;
            m_canJump = false;

            // Initalising camera Sprite
            m_cameraFocus = new Sprite(a_world, a_texture, bodySize, mass / 2.0f, a_startPosition);
            m_cameraFocus.Position = a_startPosition + new Vector2(0, 20);
            m_cameraFocus.m_body.BodyType = BodyType.Static;

            // Initalising body
            m_body = BodyFactory.CreateCapsule
                (
                a_world,
                ConvertUnits.ToSimUnits(a_size.Y),
                ConvertUnits.ToSimUnits(a_size.X / 2),
                5.0f,
                ConvertUnits.ToSimUnits(a_startPosition),
                0.0f,
                BodyType.Dynamic
                );

            Vector2 collisionBodyPosition = new Vector2(
                a_startPosition.X, a_startPosition.Y + m_texture.Height);

            // Collision body
            m_collisionBody = BodyFactory.CreateRectangle
                (
                a_world,
                ConvertUnits.ToSimUnits(a_size.X),
                ConvertUnits.ToSimUnits(5),
                5.0f,
                ConvertUnits.ToSimUnits(collisionBodyPosition),
                0.0f,
                BodyType.Dynamic
                );

            m_collisionBody.Friction = 5.0f;

            //Collisions
            m_collisionBody.CollidesWith = Category.All;
            m_collisionBody.IgnoreCollisionWith(m_body);
            m_cameraFocus.m_body.CollidesWith = Category.None;

            // Create a joint to keep the torso upright
            JointFactory.CreateAngleJoint(a_world, m_body, m_cameraFocus.m_body);
            JointFactory.CreateAngleJoint(a_world, m_body, m_collisionBody);

            //If collided, jumping possible
            m_collisionBody.OnCollision += Body_OnCollision;
            m_collisionBody.OnSeparation += Body_OnRelease;
        }
开发者ID:Breadmouth,项目名称:Gravitas,代码行数:67,代码来源:Player.cs

示例3: SetUpPhysics

        protected override void SetUpPhysics(World world, Vector2 position, float width, float height, float mass)
        {
            //Create a fixture with a body almost the size of the entire object
            //but with the bottom part cut off.
            float upperBodyHeight = height - (width / 2);

            //fixture = FixtureFactory.AttachRectangle((float)ConvertUnits.ToSimUnits(width), (float)ConvertUnits.ToSimUnits(upperBodyHeight), mass / 2, Vector2.Zero, body); //CreateRectangle(world, (float)ConvertUnits.ToSimUnits(width), (float)ConvertUnits.ToSimUnits(upperBodyHeight), mass / 2);
            body = BodyFactory.CreateRectangle(world, (float)ConvertUnits.ToSimUnits(width), (float)ConvertUnits.ToSimUnits(upperBodyHeight), mass / 2); //fixture.Body;
            body.BodyType = BodyType.Dynamic;
            body.Restitution = 0.0f;
            body.Friction = 0.5f;
            //also shift it up a tiny bit to keey the new object's center correct
            body.Position = ConvertUnits.ToSimUnits(position - (Vector2.UnitY * (width / 4)));
            centerOffset = position.Y - (float)ConvertUnits.ToDisplayUnits(body.Position.Y); //remember the offset from the center for drawing
            //fixture = FixtureFactory.AttachRectangle((float)ConvertUnits.ToSimUnits(width), (float)ConvertUnits.ToSimUnits(upperBodyHeight), mass / 2, Vector2.Zero, body);

            //Now let's make sure our upperbody is always facing up.
            fixedAngleJoint = JointFactory.CreateFixedAngleJoint(world, body);

            //Create a wheel as wide as the whole object
            //wheel = FixtureFactory.AttachCircle((float)ConvertUnits.ToSimUnits(width / 2), mass / 2, body); //CreateCircle(world, (float)ConvertUnits.ToSimUnits(width / 2), mass / 2);
            wheel = BodyFactory.CreateCircle(world, (float)ConvertUnits.ToSimUnits(width / 2), mass / 2);

            //And position its center at the bottom of the upper body
            wheel.Position = body.Position + ConvertUnits.ToSimUnits(Vector2.UnitY * (upperBodyHeight / 2));
            wheel.BodyType = BodyType.Dynamic;
            wheel.Restitution = 0.0f;
            wheel.Friction = 0.5f;

            //These two bodies together are width wide and height high :)
            //So lets connect them together
            motor = JointFactory.CreateRevoluteJoint(world, body, wheel, Vector2.Zero);
            motor.MotorEnabled = true;
            motor.MaxMotorTorque = 4f; //set this higher for some more juice
            motor.MotorSpeed = 0;

            //Make sure the two fixtures don't collide with each other
            wheel.IgnoreCollisionWith(body);
            body.IgnoreCollisionWith(wheel);

            //Set the friction of the wheel to float.MaxValue for fast stopping/starting
            //or set it higher to make the character slip.
            //wheel.Friction = float.MaxValue;
            wheel.Friction = 9f;
        }
开发者ID:DarrenRainey,项目名称:indie-game-teddy,代码行数:45,代码来源:CompositeCharacter.cs

示例4: SetUpPhysics

        /// <summary>
        /// Attached body and wheel together to make a character
        /// </summary>
        /// <param name="world">The world that the character is being added to</param>
        /// <param name="position">The position in the world that the character is being added to</param>
        /// <param name="mass">The mass of the character</param>
        protected override void SetUpPhysics(World world, Vector2 position, float mass)
        {
            float upperBodyHeight = size.Y - (size.X / 2);
            // Create upper body
            body = BodyFactory.CreateRectangle(world, (float)size.X, (float)upperBodyHeight, mass / 2);
            body.BodyType = BodyType.Dynamic;
            body.Restitution = 0.1f;
            body.Friction = 0.5f;
            body.Position = ConvertUnits.ToSimUnits(position) - (Vector2.UnitY * (size.X / 4));

            centerOffset = position.Y - (float)ConvertUnits.ToDisplayUnits(body.Position.Y);

            fixedAngleJoint = JointFactory.CreateFixedAngleJoint(world, body);

            // Create lower body
            wheel = BodyFactory.CreateCircle(world, (float)size.X / 2, mass / 2);
            wheel.Position = body.Position + (Vector2.UnitY * (upperBodyHeight / 2));
            wheel.BodyType = BodyType.Dynamic;
            wheel.Restitution = 0.1f;

            // Connecting bodies
            motor = JointFactory.CreateRevoluteJoint(world, body, wheel, Vector2.Zero);

            motor.MotorEnabled = true;
            motor.MaxMotorTorque = 1000f;
            motor.MotorSpeed = 0;

            wheel.IgnoreCollisionWith(body);
            body.IgnoreCollisionWith(wheel);

            wheel.Friction = float.MaxValue;
        }
开发者ID:brgj,项目名称:Wizards-or-whatever,代码行数:38,代码来源:CompositeCharacter.cs

示例5: Initialize

        public void Initialize(Texture2D sprite, ProjectileType type, Player plr, Body b, Texture2D shadow)
        {
            B = b;

            alreadyCollidedOnceOrMore = false;

            shade = shadow;

            foreach (var item in Game1.projectiles) {
                B.IgnoreCollisionWith(item.B);
            }

            B.OnCollision += new OnCollisionEventHandler(B_OnCollision);

            uint[] d = new uint[shade.Width * shade.Height];

            shade.GetData(d);

            Vertices v = PolygonTools.CreatePolygon(d, shade.Width, true);

            Vector2[] a = v.ToArray();

            h = ShadowHull.CreateConvex(ref a);

            if (plr.direction == 1)
                dir = 1;

            lock (Game1.projectileLock)
            Game1.lightingEngine.Hulls.Add(h);

            //  B.ApplyLinearImpulse(new Vector2(50, -10));
            if (plr.direction == 1) {
                B.Position = new Vector2(-plr.Position.X, plr.Position.Y + 1);
                B.ApplyTorque(-250f);
                B.LinearVelocity = new Vector2(-65, 7);
            } else {
                B.Position = new Vector2(-plr.Position.X, plr.Position.Y + 1);
                B.ApplyTorque(250f);
                B.LinearVelocity = new Vector2(65, 7);
            }

            Active = true;

            position = ConvertUnits.ToDisplayUnits(-plr.Position);
            texture = sprite;

            Type = type;

            Pelaaja = plr;

            hitBox.Width = 17;
            hitBox.Height = 17;
            hitBox.X = (int)position.X;
            hitBox.Y = (int)position.Y;
        }
开发者ID:aRkker,项目名称:Ninjapeli,代码行数:55,代码来源:Projectile.cs

示例6: CreateBody


//.........这里部分代码省略.........
            //Body
            _body = new Body(world); 
            FixtureFactory.AttachRectangle(2, 4, LegDensity, Vector2.Zero, _body, matShirt);
            _body.BodyType = BodyType.Dynamic;
            //_body.Mass = 2;
            
            _body.Position = position + new Vector2(0, -3);

            //Left Arm
            _lowerLeftArm = new Body(world); 
            FixtureFactory.AttachRectangle(.7f, elbowDistance, ArmDensity, Vector2.Zero, _lowerLeftArm, matSkin);
            _lowerLeftArm.BodyType = BodyType.Dynamic;
            _lowerLeftArm.AngularDamping = LimbAngularDamping;
            //_lowerLeftArm.Mass = 2;
            _lowerLeftArm.Friction = .2f;
            _lowerLeftArm.Rotation = -1.4f;
            _lowerLeftArm.Position = position + new Vector2(-4, -2.2f);

            _upperLeftArm = new Body(world);
            FixtureFactory.AttachRectangle(.7f, elbowDistance, ArmDensity, Vector2.Zero, _upperLeftArm, matShirt);
            _upperLeftArm.BodyType = BodyType.Dynamic;
            _upperLeftArm.AngularDamping = LimbAngularDamping;
           // _upperLeftArm.Body.Mass = 2;
            _upperLeftArm.Rotation = -1.4f;
            _upperLeftArm.Position = position + new Vector2(-2, -1.8f);
            

            //Right Arm
            _lowerRightArm = new Body(world);
            FixtureFactory.AttachRectangle(.7f, elbowDistance, ArmDensity, Vector2.Zero, _lowerRightArm, matSkin);
            _lowerRightArm.BodyType = BodyType.Dynamic;
            _lowerRightArm.AngularDamping = LimbAngularDamping;
            //_lowerRightArm.Mass = 2;
            _lowerRightArm.Friction = .3f;
            _lowerRightArm.Rotation = 1.4f;
            _lowerRightArm.Position = position + new Vector2(4, -2.2f);

            _upperRightArm = new Body(world);
            FixtureFactory.AttachRectangle(.7f, elbowDistance, ArmDensity, Vector2.Zero, _upperRightArm, matShirt);
            _upperRightArm.BodyType = BodyType.Dynamic;
            _upperRightArm.AngularDamping = LimbAngularDamping;
            //_upperRightArm.Body.Mass = 2;
            _upperRightArm.Rotation = 1.4f;
            _upperRightArm.Position = position + new Vector2(2, -1.8f);
            

            //Left Leg
            _lowerLeftLeg = new Body(world); 
            FixtureFactory.AttachRectangle(.7f, 2f, LegDensity, Vector2.Zero, _lowerLeftLeg, matSkin);
            _lowerLeftLeg.BodyType = BodyType.Dynamic;
            _lowerLeftLeg.AngularDamping = LimbAngularDamping;
           // _lowerLeftLeg.Mass = 2;
            _lowerLeftLeg.Friction = .5f;
            _lowerLeftLeg.Position = position + new Vector2(-0.6f, -8);

            _upperLeftLeg = new Body(world); 
            FixtureFactory.AttachRectangle(.7f, 2f, LegDensity, Vector2.Zero, _upperLeftLeg, matShorts);
            _upperLeftLeg.BodyType = BodyType.Dynamic;
            _upperLeftLeg.AngularDamping = LimbAngularDamping;
            _upperLeftLeg.Mass = 2;
            _upperLeftLeg.Position = position + new Vector2(-0.6f, -6);

            //Right Leg
            _lowerRightLeg = new Body(world); 
            FixtureFactory.AttachRectangle(.7f, 2f, LegDensity, Vector2.Zero, _lowerRightLeg, matSkin);
            _lowerRightLeg.BodyType = BodyType.Dynamic;
            _lowerRightLeg.AngularDamping = LimbAngularDamping;
            //_lowerRightLeg.Mass = 2;
            _lowerRightLeg.Friction = .5f;
            _lowerRightLeg.Position = position + new Vector2(0.6f, -8);


            _upperRightLeg = new Body(world); 
            FixtureFactory.AttachRectangle(.7f, 2f, LegDensity, Vector2.Zero, _upperRightLeg, matShorts);
            _upperRightLeg.BodyType = BodyType.Dynamic;
            _upperRightLeg.AngularDamping = LimbAngularDamping;
            //_upperRightLeg.Mass = 2;
            _upperRightLeg.Position = position + new Vector2(0.6f, -6);



            _upperRightArm.IgnoreCollisionWith(_head);
            _upperLeftArm.IgnoreCollisionWith(_head);
            


            AllBodies = new List<Body>();
            AllBodies.Add(_body);
            AllBodies.Add(_head);
            AllBodies.Add(_lowerLeftArm);
            AllBodies.Add(_lowerLeftLeg);
            AllBodies.Add(_lowerRightArm);
            AllBodies.Add(_lowerRightLeg);
            AllBodies.Add(_upperLeftArm);
            AllBodies.Add(_upperLeftLeg);
            AllBodies.Add(_upperRightArm);
            AllBodies.Add(_upperRightLeg);

           
        }
开发者ID:guozanhua,项目名称:KinectRagdoll,代码行数:101,代码来源:RagdollBase.cs


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