Exemple #1
0
        public int checkBoundsYUp(Bounds bounds, Direction facing)
        {
            Rectangle rect       = bounds.Rect;
            Vector2   pos        = new Vector2((int)(rect.Center.X / SPRITE_SIZE), (int)(rect.Top / SPRITE_SIZE));
            int       bottommost = rect.Top;

            for (int x = (int)pos.X - 1; x < pos.X + 1; x++)
            {
                // Console.Write("  Y-Up: ");
                BoundingRect objRect = getRect(x, (int)pos.Y);

                int bottom = objRect.getBottom(bounds, facing);
                if (bottom > bottommost && objRect.collides(rect))
                {
                    bottommost = bottom;
                }
            }

            return(bottommost);
        }
Exemple #2
0
        public int checkBoundsXLeft(Bounds bounds, Direction facing)
        {
            Rectangle rect      = bounds.Rect;
            Vector2   pos       = new Vector2(rect.Left / SPRITE_SIZE, (int)Math.Round((float)rect.Bottom / SPRITE_SIZE));
            int       rightmost = rect.Left;

            for (int x = (int)pos.X + 1; x >= pos.X; x--)
            {
                for (int y = (int)pos.Y - 1; y <= pos.Y + 1; y++)
                {
                    BoundingRect objRect = getRect(x, y);

                    int right = objRect.getRight(bounds, facing);
                    if (right > rightmost && objRect.collides(rect))
                    {
                        rightmost = right;
                    }
                }
            }
            return(rightmost);
        }
Exemple #3
0
        public int checkBoundsXRight(Bounds bounds, Direction facing)
        {
            Rectangle rect     = bounds.Rect;
            Vector2   pos      = new Vector2(rect.Right / SPRITE_SIZE, (int)Math.Round((float)rect.Bottom / SPRITE_SIZE));
            int       leftmost = rect.Right;

            for (int x = (int)pos.X; x >= pos.X - 1; x--)
            {
                for (int y = (int)pos.Y - 1; y <= pos.Y + 1; y++)
                {
                    BoundingRect objRect = getRect(x, y);

                    int left = objRect.getLeft(bounds, facing);
                    if (left < leftmost && objRect.collides(rect))
                    {
                        leftmost = left;
                    }
                }
            }

            return(leftmost - rect.Width); // Move back to the top left corner
        }