Esempio n. 1
0
        //Return all objects that could collide with the given object
        public List<GameObject> Retrieve(List<GameObject> gobj_list , Box gobj)
        {
            int index = this.GetIndex(gobj.pos, gobj.box);

            if(index != -1 && index < 10 && this.HasNode == true)
            {
                this.Nodes[index].Retrieve(gobj_list, gobj);
            }
            else if (index >= 10 && this.HasNode == true)
            {
                foreach(GameObject tmp_obj in this.ExtraNode[index - 10])
                {
                    gobj_list.Add(tmp_obj);
                }

                if(index == 10)
                {
                    this.Nodes[0].PullItems(gobj_list);
                    this.Nodes[1].PullItems(gobj_list);
                }
                else if (index == 11)
                {
                    this.Nodes[0].PullItems(gobj_list);
                    this.Nodes[2].PullItems(gobj_list);
                }
                else if(index == 12)
                {
                    this.Nodes[1].PullItems(gobj_list);
                    this.Nodes[3].PullItems(gobj_list);
                }
                else if(index == 13)
                {
                    this.Nodes[2].PullItems(gobj_list);
                    this.Nodes[3].PullItems(gobj_list);
                }
                else if(index == 14)
                {
                    this.PullItems(gobj_list);
                }
            }

            gobj_list.AddRange(this.GameObjectList);

            return gobj_list;
        }
Esempio n. 2
0
        public void Insert(Box gobj)
        {
            if(this.HasNode)
            {
                int index = GetIndex(gobj.pos, gobj.box);

                if (index != -1 && index < 10)
                    this.Nodes[index].Insert(gobj);
                else if (index > 10)
                    this.ExtraNode[index - 10].Add(gobj);
            }
            else
                this.GameObjectList.Add(gobj);

            if(this.GameObjectList.Count > this.MAX_OBJECT && this.Level < this.MAX_LEVEL)
            {
                if (this.HasNode == false)
                    this.Split();

                foreach(Box tmpbox in this.GameObjectList)
                {
                    int index = GetIndex(tmpbox.pos, tmpbox.box);

                    if (index != -1 && index < 10)
                        this.Nodes[index].Insert(tmpbox);
                    else if (index >= 10)
                        this.ExtraNode[index - 10].Add(tmpbox);
                }

                this.GameObjectList.Clear();
            }
        }