Exemplo n.º 1
0
        public static CollisionType[,] backgroundCollisionCheck(Rectangle objectDestinationRectangle)
        {
            CollisionType[,] temp = new CollisionType[10, 10];

            Vector2 tempy = new Vector2(objectDestinationRectangle.X + objectDestinationRectangle.Width / 2, objectDestinationRectangle.Y + objectDestinationRectangle.Height / 2);

            int posX = (int)(tempy.X / 32);

            if (posX < 5)
            {
                posX = 5;
            }

            int posY = (int)(tempy.Y / 32);

            if (posY < 5)
            {
                posY = 5;
            }

            for (int i = 0; i < temp.GetLength(0); i++)
            {
                for (int j = 0; j < temp.GetLength(1); j++)
                {
                    temp[i, j] = new CollisionType();
                }
            }

            int x = 0;
            int y = 0;

            Rectangle tempRect = Rectangle.Empty;

            for (int i = posY - 5; i < m_TileData.GetLength(0) && i < posY + 5; i++)
            {
                for (int j = posX - 5; j < m_TileData.GetLength(1) && j < posX + 5; j++)
                {
                    if (Level.isTileCollideable(i, j) == true)
                    {
                        tempRect.Width  = m_DestinationRectangle.Width;
                        tempRect.Height = m_DestinationRectangle.Height;

                        tempRect.X = j * m_DestinationRectangle.Width;
                        tempRect.Y = i * m_DestinationRectangle.Height;

                        if (j < (m_TileData.GetLength(1) - 1))
                        {
                            j++;
                            magicRectangleExtentionFunctionWithExtraRecursionForTheHellOfItButNotReallySinceWithoutThisRecursionThenTheCollisionWouldStillBeBrokenAndABrokenCollisionIsntAnyFunForAnyoneUnlessYoureAGhostSinceGhostsDontNeedCollisionButIfAGhostCouldCollideWithThingsThenSaidGhostWouldAlsoApreciateThisFunctionAndAllOfItsGlory(ref tempRect, i, ref j);
                        }

                        CollisionCheck.collisionCheck(objectDestinationRectangle, tempRect, ref temp[y, x]);
                    }
                    x++;
                }
                x = 0;
                y++;
            }
            return(temp);
        }
Exemplo n.º 2
0
        public static CollisionType[,] backgroundCollisionCheck(Rectangle objectDestinationRectangle)
        {
            CollisionType[,] temp = new CollisionType[10, 10];

            Vector2 tempy = new Vector2(objectDestinationRectangle.X + objectDestinationRectangle.Width / 2, objectDestinationRectangle.Y + objectDestinationRectangle.Height / 2);

            int posX = (int)(tempy.X / 32);
            if (posX < 5)
            {
                posX = 5;

            }

            int posY = (int)(tempy.Y / 32);
            if (posY < 5)
            {
                posY = 5;
            }

            for (int i = 0; i < temp.GetLength(0); i++)
            {
                for (int j = 0; j < temp.GetLength(1); j++)
                {
                    temp[i, j] = new CollisionType();
                }
            }

            int x = 0;
            int y = 0;

            Rectangle tempRect = Rectangle.Empty;

            for (int i = posY - 5; i < m_TileData.GetLength(0) && i < posY + 5; i++)
            {
                for (int j = posX - 5; j < m_TileData.GetLength(1) && j < posX + 5; j++)
                {
                    if (Level.isTileCollideable(i, j) == true)
                    {
                        tempRect.Width = m_DestinationRectangle.Width;
                        tempRect.Height = m_DestinationRectangle.Height;

                        tempRect.X = j * m_DestinationRectangle.Width;
                        tempRect.Y = i * m_DestinationRectangle.Height;

                        if (j < (m_TileData.GetLength(1) - 1))
                        {
                            j++;
                            magicRectangleExtentionFunctionWithExtraRecursionForTheHellOfItButNotReallySinceWithoutThisRecursionThenTheCollisionWouldStillBeBrokenAndABrokenCollisionIsntAnyFunForAnyoneUnlessYoureAGhostSinceGhostsDontNeedCollisionButIfAGhostCouldCollideWithThingsThenSaidGhostWouldAlsoApreciateThisFunctionAndAllOfItsGlory(ref tempRect, i, ref j);
                        }

                        CollisionCheck.collisionCheck(objectDestinationRectangle, tempRect, ref temp[y, x]);

                    }
                    x++;
                }
                x = 0;
                y++;
            }
            return temp;
        }