예제 #1
0
파일: Node.cs 프로젝트: elodea/Wormhole-2.0
        /// <summary>
        /// Traverse the tree to fetch the node that contains the specified collideable object
        /// </summary>
        /// <param name="obj">collideable object</param>
        /// <returns>The containing node</returns>
        private Node FetchContaining(ICollides obj)
        {
            //guard
            if (obj == null)
            {
                return(null);
            }

            //end condition (no more child nodes)
            if (childNodes == null)
            {
                if (ICollidesList.Contains(obj))
                {
                    return(this);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                //traverse
                foreach (Node n in childNodes)
                {
                    if (n.ContainsPos(obj.RealPos))
                    {
                        return(n.FetchContaining(obj));
                    }
                }

                return(null);
            }
        }
예제 #2
0
파일: Node.cs 프로젝트: elodea/Wormhole-2.0
        /// <summary>
        /// Register collidable to the right node
        /// </summary>
        public void Register(ICollides obj)
        {
            //guards
            if (obj == null)
            {
                return;
            }
            if (!SwinGame.RectOnScreen(grid))
            {
                return;
            }

            //end condition
            if (childNodes == null)
            {
                ICollidesList.Add(obj);
                return;
            }

            //find the node which contains the entiites position
            foreach (Node n in childNodes)
            {
                //only explore traverse relevant nodes
                if (n.ContainsPos(obj.RealPos))
                {
                    n.Register(obj);
                }
            }
        }
예제 #3
0
파일: Node.cs 프로젝트: elodea/Wormhole-2.0
        /// <summary>
        /// clear the tree of all collideable entities
        /// </summary>
        public void Clear()
        {
            ICollidesList?.Clear();

            if (childNodes == null)
            {
                return;
            }

            foreach (Node n in childNodes)
            {
                n.Clear();
            }
        }