Exemple #1
0
    private void checkAdjacent(Vector2 pos)
    {
        List <Vector2> adjacency = new List <Vector2>();

        PlantBase[] neighbours = PlantManager.GetNeighboursForPosition(pos);
        for (int i = 0; i < neighbours.Length; i++)
        {
            if (neighbours[i] != null)
            {
                break;
            }
            else
            {
                switch (i)
                {
                case 0:
                    adjacency.Add(Vector2.up);
                    break;

                case 1:
                    adjacency.Add(Vector2.down);
                    break;

                case 2:
                    adjacency.Add(Vector2.left);
                    break;

                case 3:
                    adjacency.Add(Vector2.right);
                    break;
                }
            }

            adjacentPath = adjacency.ToArray();
        }
    }
Exemple #2
0
    void SpreadInfection()
    {
        if (stance == PlantStance.friendly)
        {
            // get neighbours
            PlantBase[] neighbours = PlantManager.GetNeighboursForPosition(gridPos);
            // count how much corn is around us
            int cornCount = 0;
            for (int i = 0; i < neighbours.Length; i++)
            {
                // can't have null plants
                if (neighbours [i] == null)
                {
                    continue;
                }

                if (neighbours [i].plantType == PlantType.corn)
                {
                    cornCount++;
                }
            }
            // not enough corn?
            if (cornCount < 2)
            {
                return;
            }

            for (int i = 0; i < neighbours.Length; i++)
            {
                if (neighbours [i] != null)
                {
                    neighbours [i].InfectPlant();
                }
            }
        }
    }