Beispiel #1
0
    private void SetCurrentMatrix(Vector3 mousePos)
    {
        Vector2 result = Vector2.zero;
        bool    xHit   = false;
        bool    yHit   = false;

        for (int i = 0; i < AxisManager.XAxis.Count; i++)
        {
            if (AxisManager.GetXAxis(i) - 1.5f <= mousePos.x && mousePos.x <= AxisManager.GetXAxis(i) + 1.5f)
            {
                xHit     = true;
                result.x = i;
                break;
            }
        }
        for (int j = 0; j < AxisManager.YAxis.Count; j++)
        {
            if (AxisManager.GetYAxis(j) - 2.9f <= mousePos.y && mousePos.y <= AxisManager.GetYAxis(j) + 0.1f)
            {
                yHit     = true;
                result.y = j;
                break;
            }
        }

        if (xHit && yHit)
        {
            currentMatrix    = result;
            positionSelected = true;
        }
    }
Beispiel #2
0
 private void SpawnZombie()
 {
     if (currentGameStage.Equals(GameStage.NormalWave))
     {
         int row = Random.Range(0, 5);
         Debug.Log("Spawn Zombie in row" + row);
         float   xDelta = Random.Range(0.0f, 3.0f);
         Vector3 genPos = new Vector3(52.0f + xDelta, AxisManager.GetYAxis(row), AxisManager.GetZAxis(row));
         Instantiate(Resources.Load("ZombieNormal"), genPos, Quaternion.identity);
         normalWaveZombieNum--;
     }
     else if (currentGameStage.Equals(GameStage.FinalWave))
     {
     }
 }
Beispiel #3
0
    void UpdatePlanting()
    {
        Vector3 mousePos = gameCam.ScreenToWorldPoint(Input.mousePosition);

        if (positionSelected && Input.GetMouseButtonDown(0) && planting == true && plantingType != PlantType.NotDefined)
        {
            if (sun >= ManagerDefine.GetSunNeedByPlantType(plantingType))
            {
                string prefabName = "";
                switch (plantingType)
                {
                case PlantType.Peashooter:
                    prefabName = "Peashooter";
                    break;

                case PlantType.Sunflower:
                    prefabName = "SunFlower";
                    break;

                case PlantType.SnowPeashooter:
                    prefabName = "SnowPeashooter";
                    break;

                case PlantType.WallNut:
                    prefabName = "WallNut";
                    break;

                default:
                    prefabName = "SunFlower";
                    break;
                }
                Instantiate(Resources.Load(prefabName), new Vector3(AxisManager.GetXAxis((int)currentMatrix.x),
                                                                    AxisManager.GetYAxis((int)currentMatrix.y), AxisManager.GetZAxis((int)currentMatrix.y)), Quaternion.identity);
                sun -= ManagerDefine.GetSunNeedByPlantType(plantingType);


                planting         = false;
                plantingType     = PlantType.NotDefined;
                positionSelected = false;
                CurrentPlantCard.CanBeSelected = false;

                Destroy(plantingSprite.gameObject);
            }
        }
        else if (Input.GetMouseButtonDown(1) && planting == true && plantingType != PlantType.NotDefined)
        {
            Destroy(plantingSprite.gameObject);
            planting         = false;
            plantingType     = PlantType.NotDefined;
            positionSelected = false;
        }
        else
        {
            if (planting == true && plantingType != PlantType.NotDefined)
            {
                // Moving the plant
                if (plantingSprite != null)
                {
                    SetCurrentMatrix(mousePos);
                    plantingSprite.transform.position = new Vector3(AxisManager.GetXAxis((int)currentMatrix.x),
                                                                    AxisManager.GetYAxis((int)currentMatrix.y) - 1.4f,
                                                                    AxisManager.GetZAxis((int)currentMatrix.y));
                }
                else
                {
                    plantingSprite = Instantiate(Resources.Load("PlantSprite", typeof(tk2dSprite)),
                                                 new Vector3(mousePos.x, mousePos.y, 6.0f),
                                                 Quaternion.identity) as tk2dSprite;
                    plantingSprite.SetSprite(ManagerDefine.GetSpriteNameByPlantType(plantingType));
                }
            }
        }
    }