Esempio n. 1
0
    void Awake()
    {
        singleton data = singleton.getInstance();

        int     cellCount = data.cellCount;
        float   size      = prefub.GetComponent <MeshFilter>().sharedMesh.bounds.size.x *prefub.transform.localScale.x;
        Vector3 start     = new Vector3(cellCount * size / 2.0f - size / 2, 0.1f, cellCount * size / 2.0f - size / 2);

        arr = new CellBehaviour[cellCount, cellCount];

        for (int i = 0; i < cellCount; i++)
        {
            for (int j = 0; j < cellCount; j++)
            {
                GameObject obj = Instantiate(prefub.gameObject);
                arr[i, j] = obj.GetComponent <CellBehaviour>();
                obj.transform.SetParent(world.transform);
                obj.transform.localPosition = start;

                data.navigate.SetPoint(i, j, obj.transform);
                start.x -= size;
            }
            start.z -= size;
            start.x  = cellCount * size / 2 - size / 2;
        }

        data.navigate.CreateNavMesh();

        for (int i = 0; i < cellCount; i++)
        {
            for (int j = 0; j < cellCount; j++)
            {
                arr[i, j].SetNode(data.navigate.GetNode(i, j));
            }
        }

        for (int i = 0; i < data.enemyCount; i++)
        {
            Vector3        position = data.navigate.GetNode(Random.Range(0, cellCount - 1), Random.Range(0, cellCount - 1)).position;
            EnemyBehaviour agent    = Instantiate(walker.gameObject, position, Quaternion.identity).GetComponent <EnemyBehaviour>();
            data.enemys.Add(agent);
        }

        info.text = string.Format("world side {0}\nenemy count {1}", data.cellCount, data.enemyCount);
    }
    public void SpawnEntity(CellBehaviour cell, ENTITY _entityToSpawn, Entity.Owner owner)
    {
        if (!_levelController.CheckIfCanSpawn(owner))
        {
            return;
        }

        GameObject entitySpawned    = null;
        GameObject entityToSpawn    = null;
        AudioClip  entitySpawnSound = null;

        switch (_entityToSpawn)
        {
        case ENTITY.None:
            Debug.Log("Antes debes seleccionar una tropa! ");
            FindObjectOfType <AttackButtonController>().GetComponent <AttackButtonController>().ShowButtons();
            soundManagerRef.PlaySingle(soundManagerRef.incorrectMovement);
            break;

        case ENTITY.Prisioner:
            lastTroopSpawned = ENTITY.Prisioner;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Prisioner.ToString() + owner.ToString());
            entitySpawnSound = soundManagerRef.cageSoundSpawn;
            break;

        case ENTITY.Launcher:
            lastTroopSpawned = ENTITY.Launcher;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Launcher.ToString() + owner.ToString());
            entityToSpawn.GetComponentInChildren <ParticleSystem>().Stop();
            entitySpawnSound = soundManagerRef.launcherSoundSpawn;
            break;

        case ENTITY.Tank:
            lastTroopSpawned = ENTITY.Tank;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Tank.ToString() + owner.ToString());
            entitySpawnSound = soundManagerRef.tankSoundSpawn;
            break;

        case ENTITY.Wall:
            lastTroopSpawned = ENTITY.Wall;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Wall.ToString() + owner.ToString());
            break;

        case ENTITY.Turret:
            lastTroopSpawned = ENTITY.Turret;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Turret.ToString() + owner.ToString());
            entitySpawnSound = soundManagerRef.turretSoundSpawn;
            break;
        }

        if (entityToSpawn == null)
        {
            return;
        }
        int  bloodCost   = entityToSpawn.GetComponent <Entity>().bloodCost;
        bool bloodEnough = owner == Entity.Owner.Player ? bloodCost <= _bloodController.GetCurrentPlayerBlood() : bloodCost <= _bloodController.GetCurrentAIBlood();

        if (bloodEnough)
        {
            if (entityToSpawn != null)
            {
                soundManagerRef.PlaySingle(entitySpawnSound);
                entitySpawned = Instantiate(entityToSpawn, new Vector3(cell.transform.position.x, 0f, cell.transform.position.z), entityToSpawn.transform.rotation);
                entitySpawned.GetComponent <Entity>().SetEntity(owner);
                entitySpawned.GetComponent <Entity>().entityType = lastTroopSpawned;

                if (owner == Entity.Owner.Player)
                {
                    currentEntitySelected = ENTITY.None;
                }

                //Node node = _influenceMapComponent.GetNodeAtLocation(new Vector3(cell.transform.position.x, 1f, cell.transform.position.z));

                OnSpawnedTroop?.Invoke(entitySpawned.GetComponent <Entity>());

                if (owner == Entity.Owner.Player)
                {
                    _levelController.currentTroopsPlayerSpawned++;
                    _bloodController.DecreasePlayerBloodValue(entitySpawned.GetComponent <Entity>().bloodCost);
                }
                else if (owner == Entity.Owner.AI)
                {
                    Debug.Log("decreasing blood");
                    _levelController.currentTroopsAISpawned++;
                    _bloodController.DecreaseAIBloodValue(entitySpawned.GetComponent <Entity>().bloodCost);
                }

                FindObjectOfType <AttackButtonController>().GetComponent <AttackButtonController>().HideButtons();
                cell.GetComponent <CellBehaviour>().entityIn = entitySpawned.GetComponent <AbstractNPCBrain>();
                entitySpawned.GetComponent <Entity>().cell   = cell.GetComponent <CellBehaviour>();
            }
        }

        else
        {
            Instantiate(Resources.Load <GameObject>("Prefabs/Popups/SimpleInfoPopup")).GetComponent <SimpleInfoPopupController>().SetPopup("PLAYER", "NOT ENOUGH\nBLOOD");
        }
    }
Esempio n. 3
0
    public void GenerateRivers()
    {
        float             SeaLevel         = 0.1f;
        int               RiverCount       = 0;
        CellBehaviour     HighestTileOnMap = Cell[0][0];
        List <GameObject> HighestTile      = new List <GameObject>();

        HighestTile.Add(goCell[0][0]);
        for (int q = 0; q < GridSize * 2 + 1; q++)
        {
            for (int r = 0; r < goCell[q].Count; r++)
            {
                if (Cell[q][r].altitude < SeaLevel)
                {
                    Cell[q][r].TileBiome = CellBehaviour.BiomeType.Ocean;
                    StreamCells.Add(Cell[q][r]);
                    Cell[q][r].transform.localScale = new Vector3(1, SeaLevel, 1);
                }

                if (HighestTileOnMap.altitude < Cell[q][r].altitude)
                {
                    HighestTileOnMap = Cell[q][r];
                }

                //if (HexDistance(HighestTile[0].GetComponent<CellBehaviour>().TilePostition, Cell[q][r].TilePostition) > )
                //{
                //
                //}
            }
        }
        HighestTile[0] = HighestTileOnMap.gameObject;

        int RiverLength = 200;

        CellBehaviour[] neighbours = null;
        for (int i = 0; i < 0; i++)
        {
            neighbours = GetNeighbours(HighestTile[i].GetComponent <CellBehaviour>());
            for (int z = 0; z < neighbours.Length; z++)
            {
                neighbours[z].GetComponent <CellBehaviour>().TileBiome = CellBehaviour.BiomeType.Ocean;
                StreamCells.Add(neighbours[z]);
                HighestTile.Add(neighbours[z].gameObject);
                CellBehaviour[] Innerneighbours = null;
                if (neighbours[z] != null)
                {
                    Innerneighbours = GetNeighbours(neighbours[z].GetComponent <CellBehaviour>());
                    for (int p = 0; p < Innerneighbours.Length; p++)
                    {
                        Innerneighbours[p].GetComponent <CellBehaviour>().TileBiome = CellBehaviour.BiomeType.Ocean;
                        StreamCells.Add(Innerneighbours[p]);
                        HighestTile.Add(Innerneighbours[p].gameObject);
                        Innerneighbours[p].altitude *= 0.9f;
                    }
                }
            }
        }

        CellBehaviour[] neighbour = new CellBehaviour[6];

        for (int q = 0; q < HighestTile.Count; q++)
        {
            CellBehaviour NextHighestTile;
            CellBehaviour SecondHighestTile = null;
            HighestTile[q].GetComponent <CellBehaviour>().TileBiome = CellBehaviour.BiomeType.Ocean;
            NextHighestTile = HighestTile[q].GetComponent <CellBehaviour>();

            for (int i = 0; i < RiverLength; i++)
            {
                #region Getting Neighbours

                neighbour = GetNeighbours(HighestTile[q].GetComponent <CellBehaviour>());

                NextHighestTile = HighestTileOnMap;

                for (int l = 0; l < 6; l++)
                {
                    if (neighbour[l] != null)
                    {
                        if (NextHighestTile.altitude > neighbour[l].altitude)
                        {
                            SecondHighestTile = NextHighestTile;
                            NextHighestTile   = neighbour[l];
                        }
                    }
                }

                #endregion

                if (i == 0)
                {
                    if (NextHighestTile.gameObject == HighestTile[q])
                    {
                        break;
                    }

                    bool[] IsGonnaBeWater = new bool[6];
                    for (int v = 0; v < 6; v++)
                    {
                        IsGonnaBeWater[v] = (UnityEngine.Random.value < 0.5f ? true : false);

                        if (neighbour[v] && IsGonnaBeWater[v])
                        {
                            neighbour[v].TileBiome = CellBehaviour.BiomeType.Ocean;
                        }
                    }
                }
                else if (NextHighestTile.GetComponent <CellBehaviour>().TileBiome == CellBehaviour.BiomeType.Ocean)
                {
                    break;
                }
                else if (NextHighestTile.gameObject == HighestTile[q])
                {
                    for (int v = 0; v < 6; v++)
                    {
                        if (neighbour[v])
                        {
                            neighbour[v].TileBiome = CellBehaviour.BiomeType.Ocean;
                        }
                    }
                    break;
                }

                if (SecondHighestTile)
                {
                    StreamCells.Add(SecondHighestTile);
                    SecondHighestTile.GetComponent <CellBehaviour>().TileBiome = CellBehaviour.BiomeType.Ocean;
                }

                NextHighestTile.GetComponent <CellBehaviour>().TileBiome = CellBehaviour.BiomeType.Ocean;
                StreamCells.Add(NextHighestTile);
                HighestTile[q] = NextHighestTile.gameObject;
            }
        }
    }