示例#1
0
        /// <summary>
        /// Checks to see if a coordinate is colliding with the bounds of
        /// a game screen
        /// </summary>
        /// <param name="obj">Coordinate of object</param>
        /// <param name="screen">Display to compare with</param>
        /// <returns></returns>
        public static Boolean DetectBoundaries(Coord obj, GameScreen screen)
        {
            if (obj.X < 0 || obj.X >= screen.Width) return true;
            if (obj.Y < 0 || obj.Y >= screen.Height) return true;

            return false;
        }
示例#2
0
 /// <summary>
 /// Checks to see if any coordinate in a list collides with the screen
 /// </summary>
 /// <param name="obj">List of coordinates</param>
 /// <param name="screen">Display to compare with</param>
 /// <returns></returns>
 public static Boolean DetectBoundaries(IList<Coord> obj, GameScreen screen)
 {
     return obj.Any(x => DetectBoundaries(x, screen));
 }
示例#3
0
        /// <summary>
        /// Generic method for creating a random coordinate that doesn't collide with
        /// specified coordinates and a game screen. 
        /// </summary>
        /// <param name="screen">Object representing the bounds of the display</param>
        /// <param name="coordsNotToCollideWith">List of coordinates to avoid</param>
        /// <returns></returns>
        public static Coord GenerateRandomCoordinate(GameScreen screen, IList<Coord> coordsNotToCollideWith)
        {
            var coord = Coord.GenerateRandomCoord(screen.Width, screen.Height);

            while (CollisionDetector.Detect(coordsNotToCollideWith, coord)
                && CollisionDetector.DetectBoundaries(coord, screen))
            {
                coord = Coord.GenerateRandomCoord(screen.Width, screen.Height);
            }

            return coord;
        }