示例#1
0
        public override void OnCollide(Entity entB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if(IsTractored && m_lastCollideTime <= 0.0f) {
                if((ActualVelocity - entB.ActualVelocity).Length() > 700.0f) {
                    if (entB is TakesDamage)
                    {
                        ((TakesDamage)entB).TakeHit(tractoredDmg);
                        asteroidHealth -= tractoredDmg;

                        m_lastCollideTime = timeBetweenCollisions;
                        Sound.PlayCue("crash", this);

                    }
                    else if (IsTractored && (ActualVelocity - entB.ActualVelocity).Length() > 700.0f)
                    {
                        asteroidHealth -= tractoredDmg;

                        m_lastCollideTime = timeBetweenCollisions;
                        Sound.PlayCue("crash", this);
                    }
                }
                if (asteroidHealth <= 0) InstaKill();
            }

            base.OnCollide(entB, contact);
        }
示例#2
0
        bool body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (body.BodyType == BodyType.Static) return true;

            Fixture surface;
            if (fixtureA.Body == body)
                surface = fixtureB;
            else
                surface = fixtureA;

            if (surface.Body.BodyType == BodyType.Static && surface.Shape.MassData.Area > 100)
            {
                // rotate to contact normal
                Vector2 normal = contact.Manifold.LocalNormal;

                if (Vector2.Dot(normal, body.LinearVelocity) > 0)
                {
                    return false;
                }

                isPendingAttach = true;
                pendingRotation = (float)Math.Atan2(normal.Y, normal.X);

                body.CollidesWith = Category.None;

                return false;
            }

            return true;
        }
示例#3
0
        public override void Create(FarseerPhysics.Dynamics.World world, float Xoffset)
        {
            base.Create(world, Xoffset);

            _button = FixtureFactory.CreateRectangle(_world, Dimensions.X, Dimensions.Y, 1, Position + new Vector2(Xoffset, 0));
            _fixtures.Add(_button);
            _fixtures.Last().UserData = this;
        }
        public bool deadPlayerOnCollision(Fixture one, Fixture two, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (two.UserData.ToString() == "Grave" || two.Body.UserData.ToString() == "Grave")
            {
                return true;
            }

            return false;
        }
        private bool OnEnter(FarseerPhysics.Dynamics.Fixture fixtureA, FarseerPhysics.Dynamics.Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            Renderer.IsEnabled = false;
            RigidBody.Body.Enabled = false;
            Trigger.Enabled = false;
            playerScript.HasShank = true;

            return true;
        }
示例#6
0
        // Collide with non-circloid bullets and non-circloid ships.
        public override bool ShouldCollide(Entity entB, FarseerPhysics.Dynamics.Fixture fixture, FarseerPhysics.Dynamics.Fixture entBFixture)
        {
            if (entB is CircloidShip || entB is Boss || entB is Bullet || entB is SputnikShip) return false;

            if (entB is TakesDamage && ((TakesDamage) entB).IsFriendly()) {
                return false;
            }

            return true;
        }
示例#7
0
 /// <summary>
 /// Body_OnCollision re-enables jumping capability if on an object
 /// </summary>
 /// <param name="a_fixtureA">fixture passed in from Body A</param> 
 /// <param name="a_fixtureB">fixture passed in from Body B</param> 
 /// <param name="a_contact">Checking contact between fixtures</param> 
 private bool Body_OnCollision(Fixture a_fixtureA, Fixture a_fixtureB, FarseerPhysics.Dynamics.Contacts.Contact a_contact)
 {
     if ((string)a_fixtureB.Body.UserData == "platform")
     {
         m_body.CollisionCategories = Category.None;
         m_body.OnCollision -= Body_OnCollision;
         return true;
     }
     return false;
 }
示例#8
0
 bool Body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
 {
     fixtureB.Body.BodyType = BodyType.Dynamic;
     if (fixtureB.Body.Mass == 101){
         Random rand = new Random();
         this.Position = new Vector2(100 + rand.Next(800), 100 + rand.Next(600));
         realPosition = Position;
     }
     return true;
 }
示例#9
0
        public override bool OnCollidedWith(Fixture f1, UserControlledCharacter character, Fixture f2, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (!character.Invulnerable)
            {
                character.TakeDamage(25, true, true);
                Dead = true;
            }

            return false;
        }
示例#10
0
 public override bool OnCollisionEnter(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
 {
     if (!this.triggered && !this.consumed)
     {
         if (fixtureB.Body.parent.identity.Equals(this.triggerer))
         {
              this.triggered = true;
         }
     }
     return false;
 }
示例#11
0
        bool GroundCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            FarseerPhysics.Collision.Manifold man = new FarseerPhysics.Collision.Manifold();
            //get collision manifold
            contact.GetManifold(out man);

            if (man.LocalNormal.X == 0 && man.LocalNormal.Y == 1)
                _grounded = true;

            return true;
        }
示例#12
0
文件: Bullet.cs 项目: jwmcglynn/TeamQ
        public override bool ShouldCollide(Entity entB, FarseerPhysics.Dynamics.Fixture fixture, FarseerPhysics.Dynamics.Fixture entBFixture)
        {
            if (entB is Bullet) return false; // Don't collide with other bullets.
            if (entB == owner) return false;

            if (entB is TakesDamage) {
                if (((TakesDamage) owner).IsAllied((TakesDamage) entB)) return false;
            }

            return true;
        }
示例#13
0
        public override void Init(FarseerPhysics.Dynamics.World w, Kinect.RagdollManager r)
        {
            world = w;
            target = r.ragdoll;
            body.setWorld(w);

            body.OnCollision += new OnCollisionEventHandler(body_OnCollision);

            world.ProcessChanges();
            IsOperational = true;
        }
示例#14
0
文件: Player.cs 项目: Jamsterx1/Titan
        public override bool collision(Fixture f1, Fixture f2, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (f2.CollisionCategories == Category.Cat3)
            {
                if (!mInvicible && mHealth > 0)
                    mHealth--;

                Console.WriteLine("Health = " + mHealth);
            }
            return true;
        }
示例#15
0
        public override void Create(FarseerPhysics.Dynamics.World world, float Xoffset)
        {
            base.Create(world, Xoffset);

            _door = FixtureFactory.CreateRectangle(_world, Dimensions.X, Dimensions.Y, 1000000, Position + new Vector2(Xoffset, 0));
            JointFactory.CreateFixedAngleJoint(_world, _door.Body);
            _door.Body.BodyType = BodyType.Dynamic;
            _fixtures.Add(_door);
            _door.Restitution = -1.0f;
            _fixtures.Last().UserData = this;
        }
示例#16
0
 public override bool onCollision(Fixture fix1, Fixture fix, FarseerPhysics.Dynamics.Contacts.Contact Contact)
 {
     if (target.Fixture.Contains(fix))
     {
         dispose = true;
         onHit(this, fix.UserData as Creature);
         return true;
     }
     else
         return false;
 }
示例#17
0
文件: Bullet.cs 项目: jwmcglynn/TeamQ
        public override void OnCollide(Entity entB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            m_shouldCull = !(entB is BlackHole);
            if (entB is TakesDamage) {
                ((TakesDamage) entB).TakeHit(bulletStrength);
            }

            // Disable collision response.
            contact.Enabled = false;

            base.OnCollide(entB, contact);
        }
示例#18
0
 public override bool onCollision(Fixture fix1, Fixture fix, FarseerPhysics.Dynamics.Contacts.Contact Contact)
 {
     if (fix.CollisionCategories == Category.Cat2)
         dispose = true;
     if (fix.UserData as Creature != null && ((Creature)fix.UserData).team != this.attacker.team)
     {
         onHit(this, (Creature)fix.UserData);
         attacker.OnAttack((Creature)fix.UserData);
         dispose = true;
     }
     return false;
 }
示例#19
0
文件: Enemy.cs 项目: TobieD/Glide
        private bool RigidBody_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            var collider = (GameModel)fixtureB.Body.UserData;

            //if (collider.Name == "Player")
            //{
            //    m_Receiver = (Player)collider;
            //    Console.WriteLine("Player hit enemy: " + EnemyName);
            //    hasHit = true;
            //}

            return true;
        }
示例#20
0
 public override void OnCollide(Entity entB, FarseerPhysics.Dynamics.Contacts.Contact contact)
 {
     if (entB is Bullet && attachedShip == null)
     {
         //Horrible Casting makes me sad.
         foreach (SquaretopiaShip s in Environment.squares)
         {
             if(s!= this)
                 s.ai.GotShotBy(this, (GameEntity)((Bullet)entB).owner);
         }
     }
     base.OnCollide(entB, contact);
 }
示例#21
0
        public Body(FarseerPhysics.Dynamics.World farseerWorld, GameObject gameObject)
        {
            this._farseerWorld = farseerWorld;
            this._body = new FarseerPhysics.Dynamics.Body(
                            this._farseerWorld,
                            Vector2.Zero,
                            0f,
                            BodyType.Dynamic,
                            gameObject
                            );

            this.IsRigid = false;
        }
        protected override bool BrickBody_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (fixtureB.Body.IsBullet)
            {
                TakeDamage();
            }
            else
            {
                int damage = (int)(fixtureB.Body.LinearVelocity.Length() / 3f);
                TakeDamage(damage);
            }

            return true;
        }
示例#23
0
        private static List<Entity> QueryAABB(FarseerPhysics.Dynamics.World world, FarseerPhysics.Collision.AABB aabb)
        {
            List<Entity> all = new List<Entity>();

            world.QueryAABB(proxy => {
                if (proxy.Fixture.Body.UserData is Bullet || proxy.Fixture.Body.UserData is Environment) return true; // Skip bullets/environment.
                if (proxy.Fixture.IsSensor) return true; // Skip sensors.

                all.Add((Entity) proxy.Fixture.Body.UserData);
                return true;
            }, ref aabb);

            return all;
        }
示例#24
0
        bool Body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (fixtureB.Body.Mass == 101){
                fixtureB.Body.ApplyForce(new Vector2(this.Body.LinearVelocity.X*1000, this.Body.LinearVelocity.Y*1000));
            } else if (fixtureB.Body.Mass == 0.0124407075f) {
                life--;
                if (life < 1){
                    fixtureA.Body.IsSensor = true;
                    fixtureA.Body.BodyType = BodyType.Dynamic;
                }
            } else if (fixtureB.Body.Mass == 12.7999992f) {
                fixtureA.Body.IsSensor = true;
            }

            return true;
        }
示例#25
0
        static bool PhysicsBody_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            //make it dead
            Bullet b = null;
            b = fixtureA.Body.UserData as Bullet;
            Debug.Assert(b != null);

            //hit entity
            Character c = fixtureB.Body.UserData as Character;
            if (c != null)
            {
                c.Kill();
            }
            b.Kill();

            return true;
        }
示例#26
0
 bool phys_body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
 {
     if (fixtureA.Body.UserData == this && fixtureB.Body.UserData is Player)
     {
         if (IsExit)
         {
             MarioGame.GameOver = true;
             MarioGame.GameWin = true;
         }
     }
     else if (fixtureB.Body.UserData == this && fixtureA.Body.UserData is Player)
     {
         if (IsExit)
         {
             MarioGame.GameOver = true;
             MarioGame.GameWin = true;
         }
     }
     return false;
 }
示例#27
0
        public static Entity ClosestEntity(FarseerPhysics.Dynamics.World world, Vector2 fromPosition, Vector2 toPosition, out float distance)
        {
            if (fromPosition == toPosition) {
                distance = 0.0f;
                return null;
            } else {
                Entity closest = null;
                float d = float.PositiveInfinity;

                world.RayCast((FarseerPhysics.Dynamics.Fixture fixture, Vector2 point, Vector2 normal, float fraction) => {
                    if (fixture.Body.UserData is Bullet) return -1.0f; // Skip bullets.
                    if (fixture.IsSensor) return -1.0f; // Skip sensors.

                    closest = (Entity) fixture.Body.UserData;
                    d = Vector2.DistanceSquared(fromPosition, point * GameEnvironment.k_invPhysicsScale);
                    return fraction;
                }, fromPosition * GameEnvironment.k_physicsScale, toPosition * GameEnvironment.k_physicsScale);

                distance = d;
                return closest;
            }
        }
示例#28
0
文件: Megablob.cs 项目: Jntz/jamipeli
        protected override bool body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (hitted)
            {
                return false;
            }

            Player player = fixtureB.Body.UserData as Player;

            if (player != null)
            {
                HealthComponent healthComponent = player.Components
                    .FirstOrDefault(c => c is HealthComponent)
                    as HealthComponent;

                healthComponent.TakeDamage(random.Next(15, 25));

                hitted = true;
            }

            return false;
        }
示例#29
0
        public override Object PlacePhysicsObject(Microsoft.Xna.Framework.Vector2 position, FarseerPhysics.Dynamics.World world)
        {
            List<Fixture> list = world.TestPointAll(position);


            if (pin.Checked && list.Count > 0)
            {
                FixedRevoluteJoint j = new FixedRevoluteJoint(list[0].Body, list[0].Body.GetLocalPoint(position), position);
                if (motorEnabled.Checked)
                {
                    j.MotorEnabled = true;
                    float speed;
                    float maxTorque;
                    if (float.TryParse(motorSpeed.Text, out speed)) j.MotorSpeed = speed;
                    if (float.TryParse(motorTorque.Text, out maxTorque)) j.MaxMotorTorque = maxTorque;
                }

                world.AddJoint(j);
                return j;
            }
            
            if (list.Count > 1)
            {
                RevoluteJoint j = new RevoluteJoint(list[0].Body, list[1].Body, list[0].Body.GetLocalPoint(position), list[1].Body.GetLocalPoint(position));
                if (motorEnabled.Checked)
                {
                    j.MotorEnabled = true;
                    float speed;
                    float maxTorque;
                    if (float.TryParse(motorSpeed.Text, out speed)) j.MotorSpeed = speed;
                    if (float.TryParse(motorTorque.Text, out maxTorque)) j.MaxMotorTorque = maxTorque;
                }
                world.AddJoint(j);
                return j;
            }

            return base.PlacePhysicsObject(position, world);
        }
示例#30
0
        public override void OnCollide(Entity entB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            contact.Enabled = false;

            // Don't collide if the entity is the owner.
            // Don't collide if the entity is not freezable, but still allow collisions with the environment and other
            // force fields if we are not frozen.
            if (entB == owner || !(entB is Freezable || (!hasFrozen && (entB is Environment || entB is ForceField)))) {
                return;
            }

            FarseerPhysics.Collision.WorldManifold manifold;
            contact.GetWorldManifold(out manifold);
            Vector2 posOfCollision = manifold.Points[0]*GameEnvironment.k_invPhysicsScale;

            if (entB is Freezable) {
                if (m_frozen.Contains((Freezable) entB)) {
                    return;
                } else {
                    m_frozen.Add((Freezable) entB);
                }
            }

            OnNextUpdate += () => {
                if (!hasFrozen) {
                    hasFrozen = true;
                    CollisionBody.LinearVelocity = Vector2.Zero;
                    CollisionBody.IsStatic = true;
                    Position = posOfCollision;
                }

                if (entB is Freezable) {
                    Sound.PlayCue("freeze_zap", entB);
                    ((Freezable) entB).Freeze(owner);
                    entB.Zindex = Zindex + RandomUtil.NextFloat(0.001f, 0.009f);
                }
            };
        }
示例#31
0
 public void SetUp()
 {
     physics = new FarseerPhysics();
 }
示例#32
0
 public void SetUp()
 {
     physics = new FarseerPhysics();
     mouse   = Resolve <Mouse>();
 }