Exemplo n.º 1
0
        /// <summary>
        /// Determine the prominent collision side of the two tiles
        /// </summary>
        /// <param name="tile">The tile to check against</param>
        /// <returns>The prominent side for the collision of the two tiles</returns>
        public CollisionSide GetCollisionSide(BaseTile tile)
        {
            CollisionSide side = CollisionSide.None;

            if (IsCollided(tile))
            {
                // Calculate offsets
                double topOffset   = Bottom - tile.Top;
                double botOffset   = tile.Bottom - Top;
                double leftOffset  = Right - tile.Left;
                double rightOffset = tile.Right - Left;

                // Start with the top side
                double newOffset = topOffset;
                side = CollisionSide.Top;

                // Check the bottom side
                side      = botOffset > newOffset ? CollisionSide.Bottom : side;
                newOffset = Math.Max(newOffset, botOffset);

                // Check the left side
                side      = leftOffset > newOffset ? CollisionSide.Left : side;
                newOffset = Math.Max(newOffset, leftOffset);

                // Check the right side
                side      = rightOffset > newOffset ? CollisionSide.Right : side;
                newOffset = Math.Max(newOffset, rightOffset);

                // Check if no side
                side = newOffset > MagicNumbers.TILESIZE * 2 ? CollisionSide.None : side;
            }
            return(side);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Determine if two tiles have collided
 /// </summary>
 /// <param name="tile">The tile to check against</param>
 /// <returns>True if the tiles have collided or false otherwise</returns>
 public bool IsCollided(BaseTile tile)
 {
     return(tile != null && tile != this && IsCollided(tile.Rect));
 }