The public class manages contact between two shapes. A contact exists for each overlapping AABB in the broad-phase (except if filtered). Therefore a contact object may exist that has no contact points.
예제 #1
0
 public void Add(Contact contact)
 {
     if (ContactCount >= ContactCapacity)
         return;
     //			Debug.Assert(ContactCount < ContactCapacity);
     _contacts[ContactCount++] = contact;
 }
예제 #2
0
        private bool PhysicsBody_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            Entity entity = GetEntity(fixtureB);

            if (entity == null)
            {
                return(false);
            }

            if (entity is Character character)
            {
                if (character.CurrentHull != null)
                {
                    return(false);
                }
                if (character.IsHuman)
                {
                    if (!triggeredBy.HasFlag(TriggererType.Human))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (!triggeredBy.HasFlag(TriggererType.Creature))
                    {
                        return(false);
                    }
                }
            }
            else if (entity is Item item)
            {
                if (item.CurrentHull != null)
                {
                    return(false);
                }
                if (!triggeredBy.HasFlag(TriggererType.Item))
                {
                    return(false);
                }
            }
            else if (entity is Submarine)
            {
                if (!triggeredBy.HasFlag(TriggererType.Submarine))
                {
                    return(false);
                }
            }

            if (!triggerers.Contains(entity))
            {
                if (!IsTriggered)
                {
                    OnTriggered?.Invoke(this, entity);
                }
                TriggererPosition[entity] = entity.WorldPosition;
                triggerers.Add(entity);
            }
            return(true);
        }
 private bool BeginFeetContact( Contact contact )
 {
     if ( contact.FixtureA == mFeet && !contact.FixtureB.IsSensor
          || contact.FixtureB == mFeet && !contact.FixtureA.IsSensor )
         ++mNumFootContacts;
     return true;
 }
예제 #4
0
        // Collision handlers
        public bool CollisionWithEnemy(Fixture f1, Fixture f2, Contact contact)
        {
            Vector2 normal;
            FixedArray2<Vector2> points;
            contact.GetWorldManifold(out normal, out points);

            foreach (IGameComponent comp in this.game.Components)
            {
                GameEnemy enemy = comp as GameEnemy;
                if (enemy != null)
                {
                    if (enemy.getFixture() == f2)
                    {

                        if ((Math.Abs(normal.Y) > Math.Abs(normal.X)) && (normal.Y < 0))    // The contact is coming from above
                        {
                            enemy.Die(); // Uncomment this line if we decide to fix the timing so we dispose after the animation
                            this.increaseScore(10);
                            this.Jump();
                            break;
                        }
                        else
                        {
                            this.Die();
                        }

                        break;
                    }
                }
            }

            return true;
        }
예제 #5
0
        public bool BeginContact(Contact contact)
        {
            // If this is a collision between static objects, just disable it.
            if (contact.FixtureA.Body.BodyType == BodyType.Static && contact.FixtureB.Body.BodyType == BodyType.Static)
            {
                return false;
            }
            if (!contact.FixtureA.IsSensor && !contact.FixtureA.IsSensor)
            {
                Rigidbody rigidbodyA = contact.FixtureA.Body.UserData.rigidbody;
                Rigidbody rigidbodyB = contact.FixtureB.Body.UserData.rigidbody;

                // If we have real colliders clashing, one of them must have a rigid body
                // I don't dare disabling it though...
                if ((rigidbodyA == null) && (rigidbodyB == null))
                {
                    return true;
                }
                // If both are rigid bodies - none of them must be kinematic
                if ((rigidbodyA != null) && (rigidbodyB != null) && rigidbodyA.isKinematic && rigidbodyB.isKinematic)
                {
                    return true;
                }
            }
            beginContacts.Enqueue(new ColliderContact(contact));
            return true;
        }
예제 #6
0
        private void PreSolve(Contact contact, ref Manifold oldManifold)
        {
            if ((Flags & DebugViewFlags.ContactPoints) == DebugViewFlags.ContactPoints)
            {
                Manifold manifold = contact.Manifold;

                if (manifold.PointCount == 0)
                    return;

                Fixture fixtureA = contact.FixtureA;

                FixedArray2<PointState> state1, state2;
                Collision.Collision.GetPointStates(out state1, out state2, ref oldManifold, ref manifold);

                FixedArray2<Vector2> points;
                Vector2 normal;
                contact.GetWorldManifold(out normal, out points);

                for (int i = 0; i < manifold.PointCount && _pointCount < MaxContactPoints; ++i)
                {
                    if (fixtureA == null)
                        _points[i] = new ContactPoint();

                    ContactPoint cp = _points[_pointCount];
                    cp.Position = points[i];
                    cp.Normal = normal;
                    cp.State = state2[i];
                    _points[_pointCount] = cp;
                    ++_pointCount;
                }
            }
        }
예제 #7
0
        public bool onCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
        {
            Torque = -Torque;
            _fixtures.Last().Body.AngularVelocity = 0;

            return true;
        }
예제 #8
0
        public virtual bool OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
        {
            Vector2 normal = Vector2.Zero;

            Contact currentContact = contact;
            Vector2 nextNormal = Vector2.Zero;
            FixedArray2<Vector2> fx; // No idea what that is, but the function wants it
            // Iterate through the contacts, summing the normals
            do
            {
                Vector2 vec = Vector2.Zero;
                contact.GetWorldManifold(out vec, out fx);
                normal += vec;
                currentContact = currentContact.Next;
            } while (currentContact != null);

            if (normal.Y > Y && normal.X == 0)
            {
                Pressed = true;

                _pressing.Add(fixtureB);
            }

            return true;
        }
예제 #9
0
 public void EndContact(Contact contact)
 {
     if (contact.FixtureA.Body.UserData != null && contact.FixtureB.Body.UserData != null)
     {
         endContacts.Enqueue(new ColliderContact(contact));
     }
 }
예제 #10
0
 public BodyCollisionEventArgs(BodyComponent bodyComponentA, BodyComponent bodyComponentB, Contact contact)
 {
     BodyComponentA = bodyComponentA;
     BodyComponentB = bodyComponentB;
     Contact = contact;
     IsColliding = true;
 }
        internal ContactManager()
        {
            ContactList = null;
            ContactCount = 0;

            OnBroadphaseCollision = AddPair;
        }
예제 #12
0
        public Boolean collisionBullet(Fixture fixA, Fixture fixB, Contact contact)
        {
            if (!isHung)
            //je joins la balle a la cible avec un angle strict, et la balle au joueur avec un distance joint
            {
                Vector2 diff = bullet.FixtureObject.Body.Position - fixB.Body.Position;
                //ObjCercle bulletTP = new ObjCercle(diff, radius, 0.0f, worldPhysic, fixB.Body);
                //worldPhysic.RemoveBody(bullet.FixtureObject.Body);
                //bullet = bulletTP;
                //bullet.addDisplayer();

                //juncture = new FarseerPhysics.Dynamics.Joints.DistanceJoint(juncturePoint.Body, bullet.FixtureObject.Body, new Vector2(1, 1)/*AnchorPointJuncturePoint*/, new Vector2(1, 1));
                //juncture = JointFactory.CreateDistanceJoint(worldPhysic, juncturePoint.Body, bullet.FixtureObject.Body, new Vector2(10,0)/*AnchorPointJuncturePoint*/, new Vector2(10,0));
                //worldPhysic.AddJoint(juncture);

                //junctureHook = JointFactory. CreateRevoluteJoint(worldPhysic, fixA.Body, fixB.Body, diff);
                //junctureHook.MaxImpulse = 3;
                //junctureHook.

                worldPhysic.RemoveBody(bullet.FixtureObject.Body);
                bullet = null;
                //bullet.FixtureObject.Body.BodyType = BodyType.Dynamic;
                juncture = new FarseerPhysics.Dynamics.Joints.DistanceJoint(juncturePoint.Body, fixB.Body, AnchorPointJuncturePoint, new Vector2(diff.X, diff.Y));

                worldPhysic.AddJoint(juncture);
                isHung = true;
            }
            return false;
        }
예제 #13
0
        protected override bool OnCollision(Fixture projectile, Fixture collided, Contact contact)
        {
            if (NoCollide)
                return false;

            var collidedUnit = (collided.Body.UserData is Unit) ? (Unit)(collided.Body.UserData) : null;

            if (collidedUnit != null) {
                if (collidedUnit == Owner) {
                    Owner.ModifyAttackCooldown(-1000f);
                    Expire();
                }
                else {
                    foreach (Aura aura in Auras) {
                        collidedUnit.AddAura(aura);
                    }
                    collidedUnit.Hurt(Damage);
                    Body.LinearVelocity = Vector2.Zero;
                    Body.IgnoreGravity = false;
                    Body.ApplyLinearImpulse(new Vector2((Owner.Position.X - collidedUnit.Position.X)*7, -200));
                    Body.ApplyTorque(-2000f);
                    Body.CollidesWith = Category.Cat1 | Category.Cat2;
                    Body.CollisionCategories = Category.Cat5;
                }
            }

            return false;
        }
예제 #14
0
 public virtual bool OnCollidedWith(Fixture f, UserControlledCharacter obj, Fixture f2, Contact info)
 {
     if (Engine.CameraLock)
     {
         Engine.CameraLock = false;
     }
     return false;
 }
예제 #15
0
 bool m_body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
 {
     if (OnCollision != null && fixtureB.Body.UserData is RigidBodyComponent)
     {
         return(OnCollision(contact, fixtureA.Body.UserData as RigidBodyComponent, fixtureB.Body.UserData as RigidBodyComponent));
     }
     return(true);
 }
예제 #16
0
 private bool OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
 {
     if (fixtureB.CollisionCategories == Category.Cat3)
     {
         fixtureB.Body.Dispose();
         System.Diagnostics.Debug.WriteLine("body removed");
     }
     return true;
 }
예제 #17
0
        protected override bool OnCollision(Fixture fix1, Fixture fix2, Contact contact) {
            base.OnCollision(fix1, fix2, contact);

            if (contact.IsTouching && contact.Manifold.LocalNormal.Y < 0) {
                canJump = true;
                isJumping = false;
            }
            return true;
        }
예제 #18
0
        bool OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
        {
            if (fixtureB.UserData is EnemyBarrier) {
                direction.X = -direction.X;
                return false;
            }

            return true;
        }
 private bool OnCollision( Fixture fixtureA, Fixture fixtureB, Contact contact )
 {
     if ( !fixtureB.IsSensor && fixtureB.UserData is Flat )
     {
         var diff = MathHelper.WrapAngle( UpDir.Angle - Rotation );
         Rotation = Rotation + diff;
     }
     return contact.IsTouching;
 }
예제 #20
0
 public bool onCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
 {
     //if (_fixtures.Count > 0 && _fixtures[0].Body.BodyType == BodyType.Static && fixtureB.UserData is Player)
     //{
     //    _fixtures[0].Body.BodyType = BodyType.Dynamic;
     //    _fixtures[0].Body.SleepingAllowed = false;
     //}
     return true;
 }
예제 #21
0
        private bool WinPoint_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (fixtureB.Body is Player)
            {
                GoToWinLevelMenmu();
            }

            return(true);
        }
예제 #22
0
파일: Mushroom.cs 프로젝트: EkoGame/EkoGame
 private bool Body_OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
 {
     if (fixtureB.Body.UserData is Shaman)
     {
         _animationPlayer.Restart();
         fixtureB.Body.LinearVelocity = new Vector2();
         fixtureB.Body.ApplyLinearImpulse(_force);
     }
     return true;
 }
        public virtual bool OnCollidedWith(Fixture f, TutorialMonster monster, Fixture f2, Contact info)
        {
            if (!used)
            {
                monster.EndChase();
                used = true;
            }

            return true;
        }
예제 #24
0
 private bool OnCollision(Fixture fixturea, Fixture fixtureb, Contact manifold)
 {
     //_rectangle.Body.CreateFixture(_rectangle.Shape); //Calls the constructor in Fixture
     //_rectangle.Body.DestroyFixture(_rectangle);
     //_rectangle.Body.Inertia = 40;
     //_rectangle.Body.LocalCenter = new Vector2(-1,-1);
     //_rectangle.Body.Mass = 10;
     _rectangle.Enabled = false;
     return false;
 }
예제 #25
0
파일: Enemy.cs 프로젝트: IlRomanenko/Mario
 bool phys_body_OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
 {
     if (fixtureA.Body.UserData == this && fixtureB.Body.UserData is Player)
         SolveCollision(fixtureA, fixtureB, contact);
     else if (fixtureA.Body.UserData is Player && fixtureB.Body.UserData == this)
         SolveCollision(fixtureB, fixtureA, contact);
     else
         SolveChangeDirection(contact);
     return true;
 }
예제 #26
0
파일: BasicBullet.cs 프로젝트: qwook/hungry
 bool HandleCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
 {
     WeakReference scene_wr = new WeakReference(Set.Scene);
     _RenderSet.Scene.Game.AddUpdateEventHandler(this, (sender, e) => {
         new BulletCollisionParticle((Scene)scene_wr.Target, PositionX, PositionY).CenterShift();
         Derez();
         return true;
     });
     return true;
 }
예제 #27
0
 bool OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
 {
     var crateBody = fixtureB.Body;
     var crate = crateBody.UserData as Crate;
     if (crate != null)
     {
         GameWorld.RemoveCrate(crate);
     }
     return true;
 }
예제 #28
0
 public bool OnCollision(Fixture a, Fixture b, Contact c) {
     if (a.Body.UserData is Ball && b.Body.UserData is Block) {
         (b.Body.UserData as Block).Damage();
     }
     else if (a.Body.UserData is Block && b.Body.UserData is Ball)
     {
         (a.Body.UserData as Block).Damage();
     }
     return true;
 }
예제 #29
0
 public virtual bool myOnColision(Fixture f1, Fixture f2, Contact contact)
 {
     this.turningMoment += 2*1000; //2 segundos de giro(se possível)
     if (this.collisionMoment + 500 < this.gameTimeMilliseconds)
     {
         SoundControl.PlaySoundEffect(@"Ships\Collide\PunchCollide");
     }
     this.collisionMoment = this.gameTimeMilliseconds;
     return true;
 }
예제 #30
0
        private bool Body_onCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            var picker = ((Component)fixtureB.userData).entity as Player.Player;

            if (picker != null)
            {
                picker.pickUp(this.weapon);
                this.destroy();
            }
            return(true);
        }
예제 #31
0
파일: Bubble.cs 프로젝트: 925coder/NDC2014
 protected virtual bool OnCollision(Fixture me, Fixture that, Contact contact)
 {
     var enemy = that.Body.UserData as Enemy;
     if (enemy != null)
     {
         GameWorld.KillEnemy(enemy);
         GameWorld.PopBubble(this);
         return false;
     }
     return true;
 }
예제 #32
0
        public bool ObjectiveTouched(Fixture f1, Fixture f2, Contact contact)
        {

            if (game.ragdollManager.ragdoll.OwnsFixture(f1) ||
                game.ragdollManager.ragdoll.OwnsFixture(f2))
            {
                stopwatch.Stop();
                State = ObjectiveState.Complete;
            }
            return true;
        }
예제 #33
0
        protected bool onCollision(Fixture fix1, Fixture fix2, Contact contact)
        {
            if (fix2.CollisionCategories.HasFlag(GameConstants.PlayerCollisionCategory))
            {
                Activated = true;
                setPlayerSpawnPositionsHere();
                physicsObj.body.OnCollision -= new OnCollisionEventHandler(onCollision);
            }

            return false;
        }
        private bool onBodyHitWater(Fixture fixtureA, Fixture fixtureB, Contact contact)
        {
            Vector2 collisionPosition = ConvertUnits.ToDisplayUnits(fixtureB.Body.WorldCenter);

            // Check fall speed
            if (fixtureB.Body.LinearVelocity.Y > _splashMinSpeed)
            {
                Water.Splash(collisionPosition.X - Water.Position.X, -_splashPower);
            }

            return false;
        }
예제 #35
0
        private bool Bullet_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (fixtureB.Body.GetType() == typeof(Bullet) || fixtureB.Body.GetType() == typeof(Rocket) || fixtureB.Body.GetType() == typeof(Player))
            {
                return(false);
            }

            if (fixtureA.Body.GetType() == typeof(Bullet) && gameObjects.Contains((Bullet)fixtureA.Body))
            {
                physicsWorld.RemoveBody(fixtureA.Body);
                gameObjects.Remove((Bullet)fixtureA.Body);
                if (fixtureB.Body is ILivingThing)
                {
                    ILivingThing hitObject = fixtureB.Body as ILivingThing;
                    Bullet       bull      = fixtureA.Body as Bullet;
                    hitObject.DealDamage(bull.Damage);
                }
                return(true);
            }
            return(false);
        }
예제 #36
0
        bool m_body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (!Enabled)
            {
                return(false);
            }

            if (fixtureB.Body.UserData is RigidBodyComponent)
            {
                var otherRB = fixtureB.Body.UserData as RigidBodyComponent;
                if (m_activeObjects.Contains(otherRB) == false)
                {
                    m_activeObjects.Add(otherRB);
                    if (OnTrigger != null)
                    {
                        OnTrigger(otherRB.Owner);
                    }
                }
            }
            return(true);
        }
 public virtual void OnContiniousCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
 {
 }
 public virtual bool OnCollisionEnter(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
 {
     return(true);
 }
예제 #39
0
 bool BallHitPlayer2(Fixture fixtureA, Fixture fixtureB, Contact contact)
 {
     //fire it left and up
     _ballBody.LinearVelocity = new Vector2(Random.Range(ViewportWidth * -.8f, ViewportWidth * -.5f), Random.Range(6f, 9f));
     return(true);
 }