public void CollideAgainst(ShapeCollection shapeCollection, bool isCloudCollision)
        {
            Vector3 lastPosition = this.Position;
            Vector3 lastVelocity = this.Velocity;

            float lastY = this.Y;

            mIsOnGround = false;
            mHitHead    = false;
            if (shapeCollection.CollideAgainstBounceWithoutSnag(this.Collision, 0))
            {
                bool wasJumpCancelled = false;

                if (isCloudCollision)
                {
                    // Cloud can't modify X and XVelocity
                    this.X          = lastPosition.X;
                    this.Velocity.X = lastVelocity.X;
                    Vector3 change = this.Position - lastPosition;

                    if (change.LengthSquared() > MaximumCloudRepositionLength * MaximumCloudRepositionLength || change.Y <= 0 || lastVelocity.Y > 0)
                    {
                        // We only want to do cloud collision, but we didn't fall within the cloud criteria, so let's ignore the collision
                        this.Position    = lastPosition;
                        this.Velocity    = lastVelocity;
                        wasJumpCancelled = true;
                    }

                    // Since we may have repositioned this, we want to reposition the rect for future collisions and for
                    // rendering.
                    this.Collision.ForceUpdateDependencies();
                }

                if (!wasJumpCancelled)
                {
                    if (this.Y > lastY)
                    {
                        mIsOnGround = true;
                    }
                    if (this.Y < lastY)
                    {
                        mHitHead = true;
                    }
                }
            }
        }
示例#2
0
 public void CollideAgainst(ShapeCollection shapeCollection, bool isCloudCollision)
 {
     CollideAgainst(() => shapeCollection.CollideAgainstBounceWithoutSnag(this.Collision, 0), isCloudCollision);
 }
 public void CollideAgainst(ShapeCollection shapeCollection, bool isCloudCollision)
 {
     CollideAgainst(() => shapeCollection.CollideAgainstBounceWithoutSnag(this.Collision, 0), isCloudCollision);
 }
示例#4
0
 /// <summary>
 /// Performs a solid or cloud collision against a ShapeCollection.
 /// </summary>
 /// <param name="shapeCollection">The ShapeCollection to collide against.</param>
 /// <param name="isCloudCollision">Whether to perform solid or cloud collisions.</param>
 public void CollideAgainst(ShapeCollection shapeCollection, float elasticity, bool isCloudCollision)
 {
     CollideAgainst(() => shapeCollection.CollideAgainstBounceWithoutSnag(this.AxisAlignedRectangleInstance, elasticity), isCloudCollision);
 }
        public void CollideAgainst(ShapeCollection shapeCollection, bool isCloudCollision)
        {
            Vector3 lastPosition = this.Position;
            Vector3 lastVelocity = this.Velocity;

            float lastY = this.Y;

            mIsOnGround = false;
            mHitHead = false;
            if(shapeCollection.CollideAgainstBounceWithoutSnag(this.Collision, 0))
            {
                bool wasJumpCancelled = false;

                if (isCloudCollision)
                {
                    // Cloud can't modify X and XVelocity
                    this.X = lastPosition.X;
                    this.Velocity.X = lastVelocity.X;
                    Vector3 change = this.Position - lastPosition;

                    if  (change.LengthSquared() > MaximumCloudRepositionLength * MaximumCloudRepositionLength || change.Y <= 0 || lastVelocity.Y > 0)
                    {
                        // We only want to do cloud collision, but we didn't fall within the cloud criteria, so let's ignore the collision
                        this.Position = lastPosition;
                        this.Velocity = lastVelocity;
                        wasJumpCancelled = true;
                    }

                    // Since we may have repositioned this, we want to reposition the rect for future collisions and for
                    // rendering.
                    this.Collision.ForceUpdateDependencies();

                }

                if (!wasJumpCancelled)
                {
                    if (this.Y > lastY)
                    {
                        mIsOnGround = true;
                    }
                    if (this.Y < lastY)
                    {
                        mHitHead = true;
                    }
                }
            }



        }