Exemplo n.º 1
0
        private int GetOutOfBounds(GameObject obj)
        {
            int result = (int)OutOfBounds.None;

            if (obj.Position.X - obj.Origin.X < fieldRect.Left)
            {
                result |= (int)OutOfBounds.Left;
            }
            if (obj.Position.X + obj.Origin.X> fieldRect.Right)
            {
                result |= (int)OutOfBounds.Right;
            }
            if (obj.Position.Y - obj.Origin.Y< fieldRect.Top)
            {
                result |= (int)OutOfBounds.Top;
            }
            if (obj.Position.Y + obj.Origin.Y> fieldRect.Bottom)
            {
                result |= (int)OutOfBounds.Bottom;
            }

            return result;
        }
Exemplo n.º 2
0
        private void GetInBounds(GameObject obj, int outOfBounds)
        {
            if ((outOfBounds & (int)OutOfBounds.Left) == (int)OutOfBounds.Left)
            {
                obj.Position = new Vector2(fieldRect.Left + obj.Origin.X, obj.Position.Y);
            }
            else if ((outOfBounds & (int)OutOfBounds.Right) == (int)OutOfBounds.Right)
            {
                obj.Position = new Vector2(fieldRect.Right - obj.Origin.X, obj.Position.Y);
            }

            if ((outOfBounds & (int)OutOfBounds.Top) == (int)OutOfBounds.Top)
            {
                obj.Position = new Vector2(obj.Position.X, fieldRect.Top + obj.Origin.Y);
            }
            else if ((outOfBounds & (int)OutOfBounds.Bottom) == (int)OutOfBounds.Bottom)
            {
                obj.Position = new Vector2(obj.Position.X, fieldRect.Bottom - obj.Origin.Y);
            }
        }