Example #1
0
        public bool PerformCollisionAgainst(AnimatedSpriteEntity entity)
        {
            bool didCollisionOccur = false;

            int leftIndex;
            int rightIndex;

            GetIndicesBetween(
                entity.BoundingBoxWorld.LowerLeft.X, entity.BoundingBoxWorld.UpperRight.X, out leftIndex, out rightIndex);

            var boundingBoxWorld = entity.BoundingBoxWorld;

            for (int i = leftIndex; i < rightIndex; i++)
            {
                var separatingVector = GetSeparatingVector(boundingBoxWorld, collisions [i]);

                if (separatingVector != CCVector2.Zero)
                {
                    entity.PositionX += separatingVector.X;
                    entity.PositionY += separatingVector.Y;
                    // refresh boundingBoxWorld:
                    boundingBoxWorld = entity.BoundingBoxWorld;

                    didCollisionOccur = true;
                }
            }

            return(didCollisionOccur);
        }
Example #2
0
 public bool Intersects(AnimatedSpriteEntity other)
 {
     return(this.sprite.BoundingBoxTransformedToWorld.IntersectsRect(other.sprite.BoundingBoxTransformedToWorld));
 }