Exemplo n.º 1
0
    //Clear all the nodes in the Quad-Tree
    public void ClearAllNodes()
    {
        if (!nodeInserted)
        {
            return;
        }
        nodeInserted = false;

        if (divided)
        {
            northEast.ClearAllNodes();
            northWest.ClearAllNodes();
            southEast.ClearAllNodes();
            southWest.ClearAllNodes();
        }
        divided = false;
    }
Exemplo n.º 2
0
    //Clear all the nodes in the Quad-Tree
    public void ClearAllNodes()
    {
        if (numberOfNodesInserted == 0 && !root)
        {
            return;
        }
        numberOfNodesInserted = 0;
        root = false;

        if (divided)
        {
            northEast.ClearAllNodes();
            northWest.ClearAllNodes();
            southEast.ClearAllNodes();
            southWest.ClearAllNodes();
        }
        divided = false;
    }
Exemplo n.º 3
0
    void UpdateAsteroidsPosition()
    {
        // Clearing QuadTree nodes
        if (updateQT)
        {
            quadTree.ClearAllNodes();
        }

        for (int i = 0; i < asteroidsData.Length; i++)
        {
            Asteroid asteroid = asteroidsData[i];
            if (asteroid.isActive)
            {
                asteroid.UpdatePosition(Time.deltaTime);

                //Displaying only objects which are visible to camera in the scene
                bool isVisible      = cameraController.IsVisible(asteroid.position.x, asteroid.position.y);
                bool alreadyShowing = visibleAsteroids.ContainsKey(i);

                if (isVisible && !alreadyShowing)
                {
                    StartCoroutine(SpawnAsteroid(i));
                }
                else if (!isVisible && alreadyShowing)
                {
                    HideAsteroid(i);
                }

                if (updateQT)
                {
                    quadTree.Insert(asteroid.position.x, asteroid.position.y, asteroidRadius, i);
                }
            }
        }
        if (updateQT)
        {
            CheckAsteroidsCollision();
        }
    }