Exemplo n.º 1
0
 public void AddObject(ArenaObject obj)
 {
     foreach (var cell in LocateCells(obj))
     {
         cell.AddObject(obj);
     }
 }
Exemplo n.º 2
0
 public void RemoveObject(ArenaObject obj)
 {
     foreach (var cell in LocateCells(obj))
     {
         cell.RemoveObject(obj);
     }
 }
Exemplo n.º 3
0
        public bool IsOccupied(Vector2D location, ArenaObject whoWantsToKnow = null)
        {
            double radius = whoWantsToKnow == null ? double.Epsilon
                : Math.Max(whoWantsToKnow.Size.Width, whoWantsToKnow.Size.Height);

            foreach (var obj in GetNearbyObjects(location, radius))
            {
                if (obj != whoWantsToKnow && obj.Occupies(location, whoWantsToKnow))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 4
0
        public bool IsOccupied(Rectangle area, ArenaObject whoWantsToKnow = null)
        {
            double radius = Math.Max(area.Width, area.Height);

            foreach (var obj in GetNearbyObjects(area.Center, radius))
            {
                if (whoWantsToKnow != null && whoWantsToKnow.Code == obj.Code)
                {
                    continue;
                }
                if (!obj.IsPassable(whoWantsToKnow) && obj.Size.Overlaps(area))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Moves an object - do this instead of updating Position directly!
        /// </summary>
        public void MoveObject(ArenaObject obj, Vector2D newPosition)
        {
            var oldCells = LocateCells(obj);
            var newRect  = new Rectangle(newPosition, obj.Size.Width, obj.Size.Height);
            var newCells = LocateCells(newRect);

            // This seems easier
            foreach (var cell in oldCells)
            {
                cell.RemoveObject(obj);
            }
            foreach (var cell in newCells)
            {
                cell.AddObject(obj);
            }

            obj.Position = newPosition;
        }
Exemplo n.º 6
0
 public bool Occupies(Vector2D coordinate, ArenaObject mover)
 {
     if (!IsPassable(mover))
     {
         if (mover == null)
         {
             return(Size.Contains(coordinate));
         }
         else
         {
             var newRect = new Rectangle(coordinate, mover.Size.Width, mover.Size.Height);
             return(Size.Overlaps(newRect));
         }
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 7
0
 public void RemoveObject(ArenaObject obj)
 {
     Objects.Remove(obj);
 }
Exemplo n.º 8
0
 public void AddObject(ArenaObject obj)
 {
     Objects.AddLast(obj);
 }
Exemplo n.º 9
0
 private IEnumerable <ArenaGridCell> LocateCells(ArenaObject obj)
 {
     return(LocateCells(obj.Size));
 }
Exemplo n.º 10
0
 public override bool IsPassable(ArenaObject mover) => true;
Exemplo n.º 11
0
 public bool Overlaps(ArenaObject other)
 {
     return(Size.Overlaps(other.Size));
 }
Exemplo n.º 12
0
 abstract public bool IsPassable(ArenaObject mover = null);