예제 #1
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);
                }
            };
        }
예제 #2
0
파일: Ship.cs 프로젝트: jwmcglynn/TeamQ
        public override void OnCollide(Entity entB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (entB is Bullet)
            {
                //Horrible Casting makes me sad.
                ai.GotShotBy(this, (GameEntity)((Bullet)entB).owner);
            }
            else if (entB is Environment || entB.CollisionBody.IsStatic)
            {
                FarseerPhysics.Collision.WorldManifold manifold;
                contact.GetWorldManifold(out manifold);
                if (ai != null) ai.HitWall(manifold.Points[0] * GameEnvironment.k_invPhysicsScale);
            }

            if (this is Tractorable && m_lastCollideTime <= 0.0f)
            {
                if (((Tractorable)this).IsTractored && (ActualVelocity - entB.ActualVelocity).Length() > 700.0f){
                    this.TakeHit(dmgWhileTractored);
                    m_lastCollideTime = timeBetweenCollisions;
                    Sound.PlayCue("crash", this);
                }
            }

            base.OnCollide(entB, contact);
        }
예제 #3
0
        bool onCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            // since this event handler is called everytime player collides with object,
            // we check if it's a wall or dynamic object (Category 2).  Category 1 are waypoints
            // so we want it to return false and allow it into the region.
            if (fixtureA.CollisionCategories == Category.Cat2
                || fixtureA.CollisionCategories == Category.Cat3
                || fixtureB.CollisionCategories == Category.Cat2
                || fixtureB.CollisionCategories == Category.Cat3)
            {
                Vector2 norm;
                FixedArray2<Vector2> pts;
                contact.GetWorldManifold(out norm, out pts);

                // if normal is facing up and vertical velocity is downward we can jump
                if ((GameplayScreen.getWorld().Gravity.Y >= 0 && norm.Y < 0) ||
                    GameplayScreen.getWorld().Gravity.Y <=0 && norm.Y > 0) // && this._body.LinearVelocity.Y > 0)
                {
                    isJumping = false;
                    this._body.AngularVelocity = 0f;
                    this._body.Rotation = 0f;
                }

                // determine a wall collision to drop horizontal velocity
                // if I can't jump and the normal is not the same direction as the
                // direction player is moving towards then player cant move (IE: wall collision)
                // this.canMove = !(this.direction != norm.X);  // (not working need better solution)

                // allow jumping through a platform from the bottom

                return true;
            }
            else return false;
        }
예제 #4
0
파일: Player.cs 프로젝트: Orujimaru/Orujin
        public override bool OnCollisionEnter(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (!fixtureB.IsSensor)
            {
                Vector2 norm;
                FixedArray2<Vector2> pts;
                contact.GetWorldManifold(out norm, out pts);

                //If player is falling and the collision is downwards
                if (norm.Y < 0 && this.body.LinearVelocity.Y >= 0)
                {
                    this.isOnGround = true;
                }

                return true;
            }
            return false;
        }