Exemplo n.º 1
0
    public HexBomb RefillBoardWitBombs(Color[] p_colors, HexBomb p_bombPrefab, Action <HexTile> p_callback)
    {
        HexTile newTile          = null;
        HexBomb newBomb          = null;
        int     randomColorIndex = -1;
        bool    bombPlaced       = false;

        for (int i = 0; i < GameTiles.Length; i++)
        {
            for (int j = 0; j < GameTiles[i].Length; j++)
            {
                if (GameTiles[i][j] == null)
                {
                    if (!bombPlaced)
                    {
                        newTile    = Instantiate(p_bombPrefab);
                        newBomb    = (HexBomb)newTile;
                        bombPlaced = true;
                    }
                    else
                    {
                        newTile = Instantiate(_hexTilePrefab);
                    }
                    newTile.SetBoardPosition(new Vector2Int(i, j));
                    newTile.transform.SetParent(_boardParentGO.transform);

                    randomColorIndex = UnityEngine.Random.Range(0, p_colors.Length);

                    if (newTile is HexBomb)
                    {
                        newTile.Init(p_colors[randomColorIndex], randomColorIndex, p_callback);
                    }
                    else
                    {
                        newTile.Init(p_colors[randomColorIndex], randomColorIndex, null);
                    }

                    newTile.transform.position =
                        Vector3.left * GameTiles.Length / 2f
                        + Vector3.down * GameTiles[i].Length / 2f
                        + Vector3.right * HEX_TILE_WIDTH / 2f
                        + Vector3.up * HEX_TILE_HEIGTH / 2f
                        + (Vector3.right * i * 0.79f) * HEX_TILE_WIDTH
                        + (Vector3.up * j) * HEX_TILE_HEIGTH
                        + (Vector3.down * (HEX_TILE_HEIGTH - 1f))
                        + (Vector3.left * (HEX_TILE_WIDTH - 1f))
                        + (i % 2 == 0 ? Vector3.zero : Vector3.up * HEX_TILE_HEIGTH * 0.49f);

                    GameTiles[i][j] = newTile;
                }
            }
        }

        SetTileConnections(GameTiles);

        return(newBomb);
    }
Exemplo n.º 2
0
 private void RefillBoard()
 {
     if (ScoreC.Score > GRM.BombScoreThreshold * _bombCount)
     {
         _bombCount++;
         HexBomb newBomb = BC.RefillBoardWitBombs(GRM.HexTileColors, GRM.HexBombPrefab, _hexTileExplosionCallback);
         _playerMadeMove += newBomb.DecrementCounter;
     }
     else
     {
         BC.RefillBoard(GRM.HexTileColors);
     }
 }
Exemplo n.º 3
0
    public void FloorCheck(List <Vector3> positions, int currentPositionIndex)
    {
        bool changed = false;

        int count = positions.Count;

        //Debug.Log("positions to check: " + count);
        overlapSphereCollider.transform.position = positions[count - 1];
        for (int j = 0; j < count; j++)
        {
            Vector3 top    = positions[j];
            Vector3 bottom = positions[j] + new Vector3(0, -3, 0);

            Collider[] overlappingColliders = Physics.OverlapCapsule
                                                  (bottom, top, overlapSphereCollider.radius);

            //Debug.Log("positions[j]: " + positions[j]);
            // Debug.Log("overlapSphereCollider.radius: " + overlapSphereCollider.radius);

            //Debug.Log("overlappingColliders.Length: " + overlappingColliders.Length);
            for (int i = 0; i < overlappingColliders.Length; i++)
            {
                Transform t = overlappingColliders[i].transform;
                //if (t.parent != null)
                {
                    Hex hex = t /*.parent*/.GetComponent <Hex>();
                    if (hex != null)
                    {
                        HexStates hexState = hex.State;
                        if (hexState != HexStates.Full)//TODO: I dont like the full/enemy deal here
                        {
                            if (hex.Specialty == HexSpecialties.Enemy)
                            {
                                Debug.Log("An enemy is touching a sensitive hexagon...");
                                HexMap.InfectPlayerPath(hex);
                                return;
                            }


                            switch (hexState)
                            {
                            /* case HexStates.AwaitingFill:
                             *   isOnAPotentialWall = true; break;*/
                            /*case HexStates.Full:
                             *  Collide(); break;*/
                            case HexStates.Empty:
                            {
                                hex.ChangeState(HexStates.Path);
                                changed = true;
                            }
                            break;
                            }

                            Vector3 hexPosition = hex.transform.position;
                            hexPosition.y          = Hex.HEX_PRESSED_Y;
                            hex.transform.position = hexPosition;
                        }
                    }
                    else
                    {
                        HexBomb bomb = t /*.parent*/.GetComponent <HexBomb>();
                        if (bomb != null)
                        {
                            bomb.Explode();
                        }
                    }
                }
            }
        }

        if (changed)
        {
            SoundManager.PlayOneShotSoundAt(SoundNames.HexPressed, positions[currentPositionIndex]);// t.position);

            if (HexMap.CalculateFill())
            {
                SoundManager.PlayOneShotSoundAt(SoundNames.AllGlocken, positions[currentPositionIndex]);
            }
        }
    }
Exemplo n.º 4
0
    public void GenerateMap()
    {
        if (mapWasGenerated)
        {
            Debug.LogError("Someone's trying to regenerate the map!");
        }

        hexes = new Hex[numberOfColumns, numberOfRows];

        Bounds     zoneBounds    = mapZone.bounds;
        List <Hex> realHexesList = new List <Hex>(32);

        Wall[] walls = FindObjectsOfType <Wall>();

        for (int column = 0; column < numberOfColumns; column++)
        {
            for (int row = 0; row < numberOfRows; row++)
            {
                Vector3 hexPosition   = Hex.PositionInWorld(column, row);
                bool    hexIsInBounds = zoneBounds.Contains(hexPosition);

                /*    (hexPosition.x >= bounds.min.x &&
                 *   hexPosition.x <= bounds.max.x &&
                 *   hexPosition.z >= bounds.min.z &&
                 *   hexPosition.z <= bounds.max.z);*/
                if (hexIsInBounds)
                {
                    bool isAWall = false;
                    for (int i = 0; i < walls.Length; i++)
                    {
                        Bounds wallBounds = walls[i].collider.bounds;
                        if (wallBounds.Contains(hexPosition))
                        {
                            isAWall = true;
                            break;
                        }
                    }
                    Hex hex = Instantiate(hexPreFab);
                    hex.Construct(column, row, hex.GetComponent <HexComponent>());
                    hex.transform.position = hexPosition;
                    hexes[column, row]     = hex;
                    realHexesList.Add(hex);

                    if (isAWall)
                    {
                        hex.ChangeState(HexStates.Full);
                    }
                    else
                    {
                        if (Random.Range(0, bombGenerationChance) == 0)
                        {
                            HexBomb hexBomb = Instantiate
                                                  (hexBombPreFab, hexPosition, Quaternion.identity);
                            hexBomb.hex = hex;
                        }
                        else if (Random.Range(0, hardHexGenerationChance) == 0)
                        {
                            hex.ChangeState(HexStates.Hard);
                        }
                    }
                }

                //Material hexMaterial = GetMaterialForHex(hex);
                //hexComponent.GetComponentInChildren<MeshRenderer>().material = hexMaterial;
                //hexComponent.SetHex(hex);

                /* if (hexComponent.GetComponentInChildren<TMPro.TextMeshPro>())
                 * {
                 *   hexComponent.GetComponentInChildren<TMPro.TextMeshPro>().text = column + "," + row;
                 * }*/
                // if(column == 0 && row == 0)

                /* {
                 *   GameObject hexModel = Instantiate(hexModelPreFab, hex.PositionInWorld(), Quaternion.identity);
                 *   hexModel.transform.parent = transform;
                 * }*/

                //  hexComponent.GetComponentInChildren<TMPro.TextMeshPro>().enabled=false;
            }
        }

        realHexes = realHexesList.ToArray();

        for (int i = 0; i < walls.Length; i++)
        {
            Destroy(walls[i].gameObject);////0;
        }
        Destroy(mapZone.gameObject);
        #region irrelevant
        //StaticBatchingUtility.Combine(gameObject);

        //waterHexMesh = Instantiate(combineableMeshPreFab, transform.position, Quaternion.identity,transform);

        /*mildClimateHexMeshes = new CombineableMesh[mildClimateMaterials.Length];
         * for (int i = 0; i < mildClimateHexMeshes.Length; i++)
         * {
         *  mildClimateHexMeshes[i] = Instantiate(combineableMeshPreFab, transform.position, Quaternion.identity, transform);
         * }
         *
         * for (int i = 0; i < mildClimateHexMeshes.Length; i++)
         * {
         *  mildClimateHexMeshes[i].CombineMeshes(mildClimateMaterials[i]);
         * }*/
        #endregion
        mapWasGenerated = true;
    }
Exemplo n.º 5
0
    public void GenerateMap()
    {
        if (mapWasGenerated)
        {
            Debug.LogError("Someone's trying to regenerate the map!");
        }
        mapCentre = mapZone.transform.position;
        hexes     = new Hex[numberOfColumns, numberOfRows];

        Transform myTransform = transform;

        Bounds     zoneBounds    = mapZone.bounds;
        List <Hex> realHexesList = new List <Hex>(32);

        lowHexesTransforms = new List <Transform>(32);

        Wall[] walls = FindObjectsOfType <Wall>();

        for (int column = 0; column < numberOfColumns; column++)
        {
            for (int row = 0; row < numberOfRows; row++)
            {
                Vector3 hexPosition   = Hex.PositionInWorld(column, row);
                bool    hexIsInBounds = zoneBounds.Contains(hexPosition);

                /*    (hexPosition.x >= bounds.min.x &&
                 *   hexPosition.x <= bounds.max.x &&
                 *   hexPosition.z >= bounds.min.z &&
                 *   hexPosition.z <= bounds.max.z);*/
                if (hexIsInBounds)
                {
                    HexTypes modifiedType = HexTypes.Floor;
                    for (int i = 0; i < walls.Length; i++)
                    {
                        Bounds wallBounds = walls[i].collider.bounds;
                        if (wallBounds.Contains(hexPosition))
                        {
                            modifiedType = walls[i].hexType;
                            break;
                        }
                    }

                    //Find Mat
                    ushort bestMatIndex;
                    {
                        Color32 bestColour = GetBackgroundColourFromBounds(hexPosition, zoneBounds, backGroundTexture);
                        if (useDynamicColours)
                        {
                            ushort?index = FindClosestDynamicMaterial(bestColour);
                            if (index == null)
                            {
                                Material mat = new Material(dynamicColourMat);
                                mat.color = bestColour;
                                dynamicHexColouredMaterials.Add(mat);
                                bestMatIndex = (ushort)(dynamicHexColouredMaterials.Count - 1);
                            }
                            else
                            {
                                bestMatIndex = (ushort)index;
                            }
                        }
                        else
                        {
                            bestMatIndex = FindClosestMaterialIndex(bestColour);
                        }
                    }

                    byte bestFailureMatIndex;
                    {
                        Color32 bestColour =
                            GetBackgroundColourFromBounds(hexPosition, zoneBounds, FailureTexture);

                        byte?index = FindClosestFailureDynamicMaterial(bestColour);
                        if (index == null)
                        {
                            Material mat = new Material(dynamicColourMat);
                            mat.color = bestColour;
                            dynamicFailureColouredMaterials.Add(mat);
                            bestFailureMatIndex = (byte)(dynamicFailureColouredMaterials.Count - 1);
                        }
                        else
                        {
                            bestFailureMatIndex = (byte)index;
                        }
                    }

                    Hex hex = Instantiate(hexPreFab);
                    hex.transform.parent = myTransform;
                    hex.Construct(bestMatIndex, bestFailureMatIndex);
                    hex.transform.position = hexPosition;


                    if (modifiedType != HexTypes.Floor)
                    {
                        hex.ModifyType(modifiedType);
                    }
                    else if (generateRandomThings)
                    {
                        if (Random.Range(0, bombGenerationChance) == 0)
                        {
                            HexBomb hexBomb = Instantiate
                                                  (hexBombPreFab, hexPosition, Quaternion.identity);
                            hexBomb.hex = hex;
                        }
                        else if (Random.Range(0, hardHexGenerationChance) == 0)
                        {
                            hex.ModifyType(HexTypes.Hard);
                        }

                        else if (Random.Range(0, enemyHexGenerationChance) == 0)
                        {
                            hex.ModifyType(HexTypes.Enemy);
                        }
                    }

                    hexes[column, row] = hex;
                    realHexesList.Add(hex);

                    if (hex.State == HexStates.Empty && hex.Specialty == HexSpecialties.None)
                    {
                        lowHexesTransforms.Add(hex.transform);
                    }
                }

                //Material hexMaterial = GetMaterialForHex(hex);
                //hexComponent.GetComponentInChildren<MeshRenderer>().material = hexMaterial;
                //hexComponent.SetHex(hex);

                /* if (hexComponent.GetComponentInChildren<TMPro.TextMeshPro>())
                 * {
                 *   hexComponent.GetComponentInChildren<TMPro.TextMeshPro>().text = column + "," + row;
                 * }*/
                // if(column == 0 && row == 0)

                /* {
                 *   GameObject hexModel = Instantiate(hexModelPreFab, hex.PositionInWorld(), Quaternion.identity);
                 *   hexModel.transform.parent = transform;
                 * }*/

                //  hexComponent.GetComponentInChildren<TMPro.TextMeshPro>().enabled=false;
            }
        }

        //Nesssary stuff
        for (int column = 0; column < numberOfColumns; column++)
        {
            for (int row = 0; row < numberOfRows; row++)
            {
                if (hexes[column, row] != null)
                {
                    Hex hex = hexes[column, row];
                    hex.SetNeighbours(column, row);

                    /*bool isFillable = (hex.State == HexStates.Empty);
                     * hex.fillMark = isFillable ? UNFILLED : FILLED;*/
                }
            }
        }
        //FloodFillMapIsClear = true;
        realHexes = realHexesList.ToArray();

        Debug.Log("Hexes Count: " + realHexes.Length);
        for (int i = 0; i < walls.Length; i++)
        {
            Destroy(walls[i].gameObject);////0;
        }
        Destroy(mapZone.gameObject);
        #region irrelevant
        //StaticBatchingUtility.Combine(gameObject);

        //waterHexMesh = Instantiate(combineableMeshPreFab, transform.position, Quaternion.identity,transform);

        /*mildClimateHexMeshes = new CombineableMesh[mildClimateMaterials.Length];
         * for (int i = 0; i < mildClimateHexMeshes.Length; i++)
         * {
         *  mildClimateHexMeshes[i] = Instantiate(combineableMeshPreFab, transform.position, Quaternion.identity, transform);
         * }
         *
         * for (int i = 0; i < mildClimateHexMeshes.Length; i++)
         * {
         *  mildClimateHexMeshes[i].CombineMeshes(mildClimateMaterials[i]);
         * }*/
        #endregion

        HexBomb[] bombs = FindObjectsOfType <HexBomb>();
        for (int i = 0; i < bombs.Length; i++)
        {
            HexBomb bomb          = bombs[i];
            Vector3 bombPosition  = bomb.transform.position;
            Hex     hexAtPosition = GetHex(Hex.GetHexCoordinates(bombPosition));
            if (hexAtPosition != null)
            {
                bomb.transform.position = new Vector3
                                              (hexAtPosition.transform.position.x, bombPosition.y, hexAtPosition.transform.position.z);
                bomb.hex = hexAtPosition;
                //TODO: not elegant at allllkl
            }
        }

        mapWasGenerated = true;
    }