Ejemplo n.º 1
0
    public void DeactivateCluster(ClickableCube clickedCube)
    {
        //m_CubeClusters.Clear();
        //ClearVisitedCells();

        // List<ClickableCube> needsToBeDestroyed = new List<ClickableCube>();
        // needsToBeDestroyed.Add(clickedCube);
        clickedCube.GetCluster().DeactivateCubes();
    }
Ejemplo n.º 2
0
    public void RecalcuateClusters()
    {
        //Clear all clusters
        m_CubeClusters.Clear();
        //Clear all visited cells
        ClearVisitedCells();
        //Create a container so we can store all cell that needs to be visited
        List <IntVector2> coordToVisit = new List <IntVector2>();
        IntVector2        startCoords;

        //Use function that can find non-visited cells
        //The logic below must be executed until all cells are visited
        while (FindNonVisitedCoord(out startCoords))
        {
            //Create cell cluster
            CubeCluster cubeCluster = new CubeCluster();
            cubeCluster.cubeGrid = this;
            //Add it to the existing list of clusters
            m_CubeClusters.Add(cubeCluster);
            //Add the same cell to the container which stores a coordinates/cells that needs to be visited
            coordToVisit.Add(startCoords);
            //The logic below must be executed until we have no more coordinates to be visited
            while (coordToVisit.Count > 0)
            {
                //Remove current cell from the list
                int        indexToRemove = coordToVisit.Count - 1;
                IntVector2 currentCoords = coordToVisit[indexToRemove];
                coordToVisit.RemoveAt(indexToRemove);
                //Skip iteration if current coordinate/cell is already visited
                if (m_VisitedCells[currentCoords.x, currentCoords.y] == true)
                {
                    continue;
                }
                //Retrieve ClicableCube object based on current coordinates
                ClickableCube clickableCube = m_Grid[currentCoords.x, currentCoords.y];
                //Skip iteration if current ClicableCube is not active
                if (!clickableCube.Activated)
                {
                    //Set status of the current cell to visited
                    m_VisitedCells[currentCoords.x, currentCoords.y] = true;
                    continue;
                }
                //Add current ClicableCube to the cluster
                if (cubeCluster.AddCube(clickableCube, false))
                {
                    //Set status of the current cell to visited
                    m_VisitedCells[currentCoords.x, currentCoords.y] = true;
                    //Search around the current cell for enabled neighbour cells. If found add a coordinate to the need to visit container.
                    AddCoordsIfNeeded(currentCoords, new IntVector2(1, 0), ref coordToVisit);
                    AddCoordsIfNeeded(currentCoords, new IntVector2(-1, 0), ref coordToVisit);
                    AddCoordsIfNeeded(currentCoords, new IntVector2(0, 1), ref coordToVisit);
                    AddCoordsIfNeeded(currentCoords, new IntVector2(0, -1), ref coordToVisit);
                }
            }
        }
    }
    void Awake()
    {
        Debug.Log("Awoke launchable game");
        cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
        ClickableCube clickableCubeComponent = cube.AddComponent <ClickableCube>();

        clickableCubeComponent.listener = gameObject;
        clickableCubeComponent.cubeName = "yoyoyo";

        cube.transform.parent = transform;

        Debug.Log(cube);
    }
Ejemplo n.º 4
0
    void Start()
    {
        //Create a 2D array to hold the cubes, then generate the cubes in it
        m_Grid = new ClickableCube[GridDimX, GridDimY];

        //Create a grid of visited cells
        m_VisitedCells = new bool[GridDimX, GridDimY];

        GenerateCubes();

        m_CubeClusters = new List <CubeCluster>();

        CalculatedCluster = false;
    }
Ejemplo n.º 5
0
    public void RecalcuateClusters()
    {
        m_CubeClusters.Clear();

        ClearVisitedCells();

        List <IntVector2> needsAVisit = new List <IntVector2>();

        IntVector2 StartCoords;

        while (FindNonVisitedCoord(out StartCoords))
        {
            CubeCluster cubecluster = new CubeCluster();

            m_CubeClusters.Add(cubecluster);

            needsAVisit.Add(StartCoords);

            while (needsAVisit.Count > 0)
            {
                int        indexToRemove = needsAVisit.Count - 1;
                IntVector2 currentCoords = needsAVisit[indexToRemove];

                needsAVisit.RemoveAt(indexToRemove);

                if (m_VisitedCells[currentCoords.x, currentCoords.y])
                {
                    continue;
                }

                m_VisitedCells[currentCoords.x, currentCoords.y] = true;

                ClickableCube currentCube = m_Grid[currentCoords.x, currentCoords.y];
                currentCube.setCluster(cubecluster);

                if (!currentCube.Activated)
                {
                    continue;
                }

                cubecluster.AddCube(currentCube);

                AddCoordsIfNeeded(currentCoords, new IntVector2(1, 0), ref needsAVisit, currentCube.GetColourGroup());  //right
                AddCoordsIfNeeded(currentCoords, new IntVector2(-1, 0), ref needsAVisit, currentCube.GetColourGroup()); //left
                AddCoordsIfNeeded(currentCoords, new IntVector2(0, 1), ref needsAVisit, currentCube.GetColourGroup());  //up
                AddCoordsIfNeeded(currentCoords, new IntVector2(0, -1), ref needsAVisit, currentCube.GetColourGroup()); //down
            }
        }
    }
Ejemplo n.º 6
0
    //A helper function to add new coordinates to check in our search.
    //It will first create the new coords, then double check if the coordinates are valid before adding
    //them to the list
    void AddCoordsIfNeeded(IntVector2 coords, IntVector2 checkDir, ref List <IntVector2> coordsToVisit, ColourGroup colourGroup)
    {
        IntVector2 nextCoords = coords + checkDir;

        if (AreCoordsValid(nextCoords))
        {
            ClickableCube Tempcheck = m_Grid[nextCoords.x, nextCoords.y];
            if (Tempcheck != null)
            {
                if (colourGroup == Tempcheck.GetColourGroup())
                {
                    coordsToVisit.Add(nextCoords);
                }
            }
        }
    }
Ejemplo n.º 7
0
 public bool ShouldAddCube(ClickableCube a_cube, bool removeClusters)
 {
     if (a_cube.colorKey == m_clusterColorKey)
     {
         if (a_cube.coord.x >= m_minCoords.x - 1 && a_cube.coord.x <= m_maxCoords.x + 1)
         {
             if (a_cube.coord.y >= m_minCoords.y - 1 && a_cube.coord.y <= m_maxCoords.y + 1)
             {
                 foreach (ClickableCube cube in m_Cubes)
                 {
                     if (a_cube.coord + Vector2Int.up == cube.coord || a_cube.coord - Vector2Int.up == cube.coord || a_cube.coord + Vector2Int.right == cube.coord || a_cube.coord - Vector2Int.right == cube.coord)
                     {
                         return(AddCube(a_cube, removeClusters));
                     }
                 }
             }
         }
     }
     return(false);
 }
Ejemplo n.º 8
0
 public void AddCube(ClickableCube cube)
 {
     m_Cubes.Add(cube);
     if (cube.GetColourGroup() == ColourGroup.Red)
     {
         m_ClusterColor = Color.red;
     }
     if (cube.GetColourGroup() == ColourGroup.Blue)
     {
         m_ClusterColor = Color.blue;
     }
     if (cube.GetColourGroup() == ColourGroup.Green)
     {
         m_ClusterColor = Color.green;
     }
     if (cube.GetColourGroup() == ColourGroup.Yellow)
     {
         m_ClusterColor = Color.yellow;
     }
     cube.ActivatedColor = m_ClusterColor;
 }
Ejemplo n.º 9
0
    private void HandleMouseClick()
    {
        //Use a ray cast to figure what cube we are clicking
        Ray pointerRay = Camera.main.GetComponent <Camera>().ScreenPointToRay(Input.mousePosition);

        RaycastHit hitInfo;

        if (!Physics.Raycast(pointerRay, out hitInfo, PointerRayDist))
        {
            return;
        }

        //Get the cube object or ignore the object if it isn't one.
        ClickableCube clickableCube = hitInfo.collider.gameObject.GetComponent <ClickableCube>();

        if (clickableCube == null)
        {
            return;
        }

        //If this is the first cube we clicked on with out lifting the mouse button, remember
        //the activated state we will set it to.  This is to make dragging the mouse to set the
        //cubes more convenient.
        if (m_CurrentCube == null)
        {
            m_ActivateCubes = !clickableCube.Activated;
        }

        //If the cube is a new one, set the active state
        if (clickableCube != m_CurrentCube)
        {
            //   clickableCube.Activated = m_ActivateCubes;

            m_CurrentCube = clickableCube;

            m_CubeGrid.RecalcuateClusters();
            m_CubeGrid.DeactivateCluster(clickableCube);
        }
    }
Ejemplo n.º 10
0
    public bool AddCube(ClickableCube cube, bool removeClusters)
    {
        if (m_clusterColorKey == "")
        {
            m_clusterColorKey = cube.colorKey;
            m_minCoords       = cube.coord;
            m_maxCoords       = cube.coord;
        }

        if (cube.colorKey == m_clusterColorKey)
        {
            m_Cubes.Add(cube);
            m_minCoords.x = Math.Min(m_minCoords.x, cube.coord.x);
            m_minCoords.y = Math.Min(m_minCoords.y, cube.coord.y);
            m_maxCoords.x = Math.Max(m_maxCoords.x, cube.coord.x);
            m_maxCoords.y = Math.Max(m_maxCoords.y, cube.coord.y);
            if (removeClusters && m_Cubes.Count >= 3)
            {
                Break();
            }
            return(true);
        }
        return(false);
    }
Ejemplo n.º 11
0
    public void AddCube(ClickableCube cube)
    {
        m_Cubes.Add(cube);

        cube.ActivatedColor = m_ClusterColor;
    }
Ejemplo n.º 12
0
    private void PrepareForNextLevel()
    {
        //increse the level
        int level = GameManager.instance.Level;

        gridDimX += level;
        gridDimY += level;

        if (m_Grid != null)
        {
            //delete or recycle all the clickable cubes
            m_Grid = null;
        }
        if (m_VisitedCells != null)
        {
            m_VisitedCells = null;
        }
        if (m_CubeClusters != null)
        {
            m_CubeClusters.Clear();
        }

        //setup camera
        gameCamera.orthographicSize   = (gridDimY + 7f) / 2f;
        gameCamera.transform.position = new Vector3(gridDimX * 0.5f, gameCamera.orthographicSize - 1.5f, -10f);

        //instantiate the turret and give it its min and max pos an the cube grid
        if (turret == null)
        {
            turret = Instantiate(turretPrefab).GetComponent <Turret>();
            GameManager.instance.Turret = turret;
        }
        turret.transform.position = new Vector3(0.0f, gridDimY + 2.5f, 0.0f);
        turret.cubeGrid           = this;
        turret.SetMoveLimits(new Vector3(2.0f, turret.transform.position.y, 0.0f), new Vector3(gridDimX - 3.0f, turret.transform.position.y, 0.0f));

        //Create a 2D array to hold the cubes, then generate the cubes in it
        if (m_Grid == null)
        {
            m_Grid = new ClickableCube[gridDimX, gridDimY];
        }

        //Create a grid of visited cells
        if (m_VisitedCells == null)
        {
            m_VisitedCells = new bool[gridDimX, gridDimY];
        }

        GenerateCubes();
        GenerateRoots();
        GenerateBouncers();

        if (m_CubeClusters == null)
        {
            m_CubeClusters = new List <CubeCluster>();
        }
        RecalcuateClusters();
        CalculatedCluster = false;

        GameManager.instance.Level++;
    }
Ejemplo n.º 13
0
    public void RecalcuateClusters()
    {
        //Clear all clusters
        m_CubeClusters.Clear();

        //Clear all visited cells
        ClearVisitedCells();

        //Create a container so we can store all cell that needs to be visited
        List <IntVector2> cellsToCheck = new List <IntVector2>();
        IntVector2        startCoords;

        //Use function that can find non-visited cells
        //The logic below must be executed until all cells are visited
        while (FindNonVisitedCoord(out startCoords))
        {
            //Create cell cluster and add it to the existing list of clusters
            CubeCluster newCluster = new CubeCluster();
            m_CubeClusters.Add(newCluster);

            //Add the same cell to the container which stores a coordinates/cells that needs to be visited
            newCluster.AddCube(m_Grid[startCoords.x, startCoords.y]);

            cellsToCheck.Add(startCoords);

            while (cellsToCheck.Count > 0)
            {
                //remove the initial start value but keep in temp memory
                int        indexToRemove = cellsToCheck.Count - 1;
                IntVector2 currentCoord  = cellsToCheck[indexToRemove];
                cellsToCheck.RemoveAt(indexToRemove);

                //ignore this cube if its been visited
                if (m_VisitedCells[currentCoord.x, currentCoord.y] == true)
                {
                    continue;
                }
                //flag visible otherwise
                else
                {
                    m_VisitedCells[currentCoord.x, currentCoord.y] = true;
                }

                //List<IntVector2> cardinalCoordsToCheck = new List<IntVector2>();
                //for (int i = 0; i < 4; i++)
                //{
                //    int x = i < 2 ? 1 : 0;
                //    int y = i > 2 ? 1 : 0;

                //    AddCoordsIfNeeded(currentCoord, new IntVector2(x, y), ref cardinalCoordsToCheck);
                //}

                //for (int i = 0; i < cardinalCoordsToCheck.Count; i++)
                //{
                //    ClickableCube cube = m_Grid[cardinalCoordsToCheck[i].x, cardinalCoordsToCheck[i].y];
                //    if (cube.Activated == false)
                //    {
                //        continue;
                //    }

                //    newCluster.AddCube(cube);
                //    cellsToCheck.Add(cardinalCoordsToCheck[i]);
                //}


                //for loop for the cardinal directions
                for (int i = 0; i < 4; i++)
                {
                    //create coords
                    IntVector2 potentialCoords = currentCoord;

                    //check a cardinal direction based on index
                    switch (i)
                    {
                    case 0:
                        potentialCoords.x++;
                        break;

                    case 1:
                        potentialCoords.x--;
                        break;

                    case 2:
                        potentialCoords.y++;
                        break;

                    case 3:
                        potentialCoords.y--;
                        break;

                    default:
                        Debug.LogError("Something really f****d up happened.");
                        break;
                    }

                    //check if coords are legal
                    if (AreCoordsValid(potentialCoords) == false)
                    {
                        continue;
                    }

                    //grab the cube and check if its been activated
                    ClickableCube potential = m_Grid[potentialCoords.x, potentialCoords.y];
                    if (potential.Activated == false)
                    {
                        continue;
                    }

                    //add the cube to the cluster and add it to the need-to-check list
                    newCluster.AddCube(potential);
                    cellsToCheck.Add(potentialCoords);
                }
            }
        }
    }