void HandleMouseMoveForPlant()
    {
        if (selectedPlant)
        {
            Vector3 pos      = Utility.GetMouseWorldPos();
            Vector3 plantPos = pos;
            plantPos.y -= 0.3f;
            selectedPlant.transform.position = plantPos;

            if (StageMap.IsPointInMap(pos))
            {
                StageMap.GetRowAndCol(pos, out row, out col);
                if (tempPlant.GetComponent <PlantGrow>().canGrowInMap(row, col))
                {
                    tempPlant.transform.position = StageMap.GetPlantPos(row, col);
                    tempPlant.GetComponent <SpriteDisplay>().SetOrderByRow(row);
                }
                else
                {
                    col = row = -1;
                    tempPlant.transform.position = new Vector3(1000, 1000, 0);
                }
            }
            else
            {
                col = row = -1;
                tempPlant.transform.position = new Vector3(1000, 1000, 0);
            }
        }
    }
Пример #2
0
    IEnumerator Explode()
    {
        yield return(new WaitForSeconds(delayTime));

        GameObject newEffect = Instantiate(effect);

        newEffect.transform.position = transform.position + effectOffset;
        newEffect.GetComponent <SpriteRenderer>().sortingOrder =
            transform.Find("plant").GetComponent <SpriteRenderer>().sortingOrder + 1;
        Destroy(newEffect, 1.5f);

        SearchZombie search = GetComponent <SearchZombie>();

        foreach (GameObject zombie in search.SearchZombiesInCol())
        {
            zombie.GetComponent <ZombieHealthy>().BoomDie();
        }

        AudioManager.GetInstance().PlaySound(explodeSound);
        GetComponent <PlantHealthy>().Die();

        // Create hole
        GameObject tempPlant = Instantiate(hole);

        tempPlant.transform.position = StageMap.GetPlantPos(grow.row, grow.col);
        tempPlant.GetComponent <PlantGrow>().grow(grow.row, grow.col);
    }
Пример #3
0
    IEnumerator Explode()
    {
        yield return(new WaitForSeconds(delayTime));

        GameObject newEffect = Instantiate(effect);

        newEffect.transform.position = new Vector3(1.8f, transform.position.y + 0.5f, 0);
        newEffect.GetComponent <SpriteRenderer>().sortingOrder =
            transform.Find("plant").GetComponent <SpriteRenderer>().sortingOrder + 1;
        Destroy(newEffect, 1.2f);

        GameModel model = GameModel.GetInstance();
        int       row   = GetComponent <PlantGrow>().row;

        object[] zombies = model.zombieList[row].ToArray();
        foreach (GameObject zombie in zombies)
        {
            zombie.GetComponent <ZombieHealthy>().BoomDie();
        }

        AudioManager.GetInstance().PlaySound(explodeSound);

        GetComponent <PlantHealthy>().Die();

        // Create hole
        GameObject tempPlant = Instantiate(hole);

        tempPlant.transform.position = StageMap.GetPlantPos(grow.row, grow.col);
        tempPlant.GetComponent <PlantGrow>().grow(grow.row, grow.col);
    }
Пример #4
0
    void updatePlantsOnMap()
    {
        for (int i = 0; i < StageMap.MAP_MAX; i++)
        {
            int x = i / StageMap.COL_MAX;
            int y = i % StageMap.COL_MAX;

            if (stackSensing[i] != 0 && model.map[x, y] == null && !hasPlant[i])
            {
                if (model.sun - 150 >= 0 || (stackSensing[i] == 12 && model.sun - 50 >= 0))
                {
                    if (stackSensing[i] == 12)
                    {
                        model.sun -= 50;
                    }
                    else
                    {
                        model.sun -= 150;
                    }
                    tempPlant = Instantiate(plantsForPlayer[stackSensing[i] - 1]);
                    tempPlant.transform.position = StageMap.GetPlantPos(i / StageMap.COL_MAX, i % StageMap.COL_MAX);
                    tempPlant.GetComponent <PlantGrow>().grow(x, y);

                    AudioManager.GetInstance().PlaySound(plantGrow);
                    tempPlant   = null;
                    hasPlant[i] = true;
                }
                else
                {
                    money.SetTrigger("nomoney");
                }
            }
            else if (stackSensing[i] == 0 && hasPlant[i] && !model.holeMap[x, y])
            {
                GameObject tempPlant = model.map[x, y];
                tempPlant.GetComponent <PlantHealthy>().Die();
                hasPlant[i] = false;
            }
            else if (stackSensing[i] == 0 && hasPlant[i] && model.holeMap[x, y])
            {
                GameObject tempPlant = model.map[x, y];
                model.map[x, y] = null;
                Destroy(tempPlant);
                hasPlant[i] = false;
            }
        }
    }
    void HandleMouseDownForPlant()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Collider2D collider = Physics2D.OverlapPoint(Utility.GetMouseWorldPos());

            if (collider != null)
            {
                CancelSelectdCard();
                if (collider.gameObject.tag == "Card")
                {
                    collider.gameObject.SendMessage("OnSelect");
                    AudioManager.GetInstance().PlaySound(seedLift);
                }
            }
            else if (selectedPlant)
            {
                if (row != -1)
                {
                    selectedPlant.transform.position = StageMap.GetPlantPos(row, col);
                    selectedPlant.GetComponent <PlantGrow>().grow(row, col);
                    AudioManager.GetInstance().PlaySound(plantGrow);
                    selectedPlant = null;

                    Destroy(tempPlant);
                    tempPlant = null;

                    selectedCard.Select();
                    selectedCard = null;
                }
                else
                {
                    CancelSelectdCard();
                }
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            CancelSelectdCard();
        }
    }