Пример #1
0
        /// <summary>
        /// Removes object from the game
        /// </summary>
        /// <param name="gameObject"></param>
        public void Remove(IGameObject gameObject)
        {
            if (GameObjects.Contains(gameObject))
            {
                GameObjects.Remove(gameObject);
            }

            if (VisibleGameObjects.Contains(gameObject))
            {
                VisibleGameObjects.Remove(gameObject);
            }

            if (collidingObjects.ContainsKey(gameObject))
            {
                collidingObjects.Remove(gameObject);
            }

            foreach (var go in collidingObjects)
            {
                if (go.Value.Contains(gameObject))
                {
                    go.Value.Remove(gameObject);
                }
            }
        }
Пример #2
0
        public IGameObject GetClosestGameObject(Point location, IEnumerable <IGameObject> excluded, int maxRange = 2000)
        {
            IGameObject        closest      = null;
            List <IGameObject> list         = VisibleGameObjects.Where(x => x.IsPhysicalObject).ToList();
            List <IGameObject> excludedList = new List <IGameObject>();

            if (excluded != null)
            {
                excludedList = excluded.ToList();
            }
            else
            {
                excludedList.Add(Player);
            }


            try
            {
                foreach (var o in list)
                {
                    int xDistance = (int)(Math.Abs(location.X - (o.Location.X - Camera.XOffset)));
                    int yDistance = (int)(Math.Abs(location.Y - (o.Location.Y - Camera.YOffset)));
                    if (xDistance + yDistance < maxRange && !excludedList.Contains(o))
                    {
                        closest  = o;
                        maxRange = xDistance + yDistance;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(closest);
        }