Exemplo n.º 1
0
 public void Accept(IQuadTreeVisitor aVisitor)
 {
     aVisitor.Visit(this);
     if (this.subTrees != null)
     {
         foreach (IQuadTree subTree in this.subTrees)
         {
             subTree.Accept(aVisitor);
         }
     }
 }
Exemplo n.º 2
0
    void Start()
    {
        Camera     cam      = Camera.main;
        float      height   = 2f * cam.orthographicSize;
        float      width    = height * cam.aspect;
        IRectangle boundary = new Rectangle((int)-width / 2, (int)-height / 2, (int)width, (int)height);

        Debug.Log(height);
        quadTree                      = new QuadTree(4, boundary);
        userObjectSpawner             = new DefaultUserObjectSpawner(boundary);
        insertQuadTreeVisitor         = new InsertQuadTreeVisitor(1, userObjectSpawner);
        debugRenderingQuadTreeVisitor = new DebugRenderingQuadTreeVisitor();
        userObjectSpawner.SetUpperSpawnLimit(1000);
        userObjectSpawner.SetObjectInitialHealth(5);
    }
Exemplo n.º 3
0
        void Init()
        {
            waitForObjectCreation = new WaitForSecondsRealtime(objectCreatePeriod);
            Camera     cam      = Camera.main;
            float      height   = 2f * cam.orthographicSize;
            float      width    = height * cam.aspect;
            IRectangle boundary = new Rectangle(-width / 2, -height / 2, width, height);

            quadTree                      = new QuadTree(4, boundary);
            userObjectSpawner             = new DefaultUserObjectSpawner(boundary, prefabCircle, prefabRectangle);
            insertQuadTreeVisitor         = new InsertQuadTreeVisitor(1, userObjectSpawner);
            debugRenderingQuadTreeVisitor = new DebugRenderingQuadTreeVisitor();
            userObjectSpawner.SetUpperSpawnLimit(PlayerPrefs.GetInt("NumberOfEntities"));
            userObjectSpawner.SetObjectInitialHealth(PlayerPrefs.GetInt("InitialHealth"));
            suitableForSpawn           = true;
            Selection.activeGameObject = gameObject;
        }
Exemplo n.º 4
0
        public bool Insert(IPoint <IUserObject> aPoint, IQuadTreeVisitor aVisitor)
        {
            if (!aPoint.GetUserObject().GetShape().IntersectsWithRectangle(this.boundary))
            {
                return(false);
            }

            aVisitor.Visit(this);

            if (aPoint.GetUserObject().GetHealth() < 1)
            {
                return(false);
            }

            if (null == this.points)
            {
                this.points = new List <IPoint <IUserObject> > (this.capacity);
            }

            if (this.points.Count < this.capacity && null == subTrees)
            {
                this.points.Add(aPoint);
                return(true);
            }
            if (null == this.subTrees)
            {
                this.subdivide();
            }

            foreach (IQuadTree subTree in this.subTrees)
            {
                if (subTree.Insert(aPoint, aVisitor))
                {
                    return(true);
                }
            }
            return(false);
        }