Ejemplo n.º 1
0
        /// <summary>
        /// Adds an object to the WorldGrid.
        /// </summary>
        /// <param name="obj">Object to add.</param>
        public void Add(WorldComponent obj)
        {
            try
            {
                Tuple <int, int> cellIndex =
                    GetCellFromPoint(obj.Position.ToPoint());
                WorldCell cell = Cells[cellIndex.Item1][cellIndex.Item2];

                cell.Add(obj);
                obj.Cell = cell;
            }
            catch
            {
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates a given object within the world grid. Moving it to a new
        /// cell if required.
        /// </summary>
        /// <param name="obj">Object to update.</param>
        public void Update(WorldComponent obj)
        {
            try
            {
                Tuple <int, int> cellIndex =
                    GetCellFromPoint(obj.Position.ToPoint());
                WorldCell cell = Cells[cellIndex.Item1][cellIndex.Item2];

                if (obj.Cell != cell)
                {
                    obj.Cell.Remove(obj);
                    cell.Add(obj);
                    obj.Cell = cell;
                }
            }
            catch
            {
            }
        }