コード例 #1
0
        /// <summary>
        /// Checks if the given object is within the borders of the viewport.
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public bool IsOnScreen(GameplayObject g)
        {
            Point a = g.Pos;
            Point b = new Point(g.SpriteWidth, g.SpriteHeight);

            return(new Rectangle(Camera.Pos, new Point(ScreenWidth, ScreenHeight)).Intersects(new Rectangle(a, b)));
        }
コード例 #2
0
ファイル: EnglishSort.cs プロジェクト: Ben-Lall/TowerDefense
        public int Compare(object a, object b)
        {
            // Assertions and type identification
            Debug.Assert(a != null, "Violation of : a is not null.");
            Debug.Assert(b != null, "Violation of : b is not null.");

            Type[] types   = { typeof(GameplayObject) };
            Type   typeOfA = null;
            Type   typeOfB = null;

            foreach (Type t in types)
            {
                if (a.GetType().IsSubclassOf(t))
                {
                    typeOfA = t;
                }

                if (b.GetType().IsSubclassOf(t))
                {
                    typeOfB = t;
                }
            }

            Debug.Assert(typeOfA != null, "Violation of : a is of drawable type.");
            Debug.Assert(typeOfB != null, "Violation of : b is of drawable type.");

            int aX = 0, aY = 0, bX = 0, bY = 0;

            // Get coordinates of a.
            if (typeOfA == typeof(GameplayObject))
            {
                GameplayObject temp = (GameplayObject)a;
                aX = temp.Pos.X;
                aY = temp.Pos.Y;
            }

            // Get coordinates of b.
            if (typeOfB == typeof(GameplayObject))
            {
                GameplayObject temp = (GameplayObject)b;
                bX = temp.Pos.X;
                bY = temp.Pos.Y;
            }

            // Compare.

            if (aY > bY)
            {
                return(1);
            }
            else if (aY < bY)
            {
                return(-1);
            }
            else   // aY == bY
            {
                if (aX > bX)
                {
                    return(1);
                }
                else if (aX < bX)
                {
                    return(-1);
                }
                else   // aX == bX
                {
                    return(0);
                }
            }
        }