Example #1
0
    public void SwitchPlant(bool next)
    {
        int typeNum = (int)type;

        if (next)
        {
            typeNum++;
            if (typeNum > 3)
            {
                typeNum = 0;
            }
            if (canAccessPlant[typeNum] == false)
            {
                typeNum = 0;
            }
        }
        else //previous
        {
            typeNum--;
            if (typeNum < 0)
            {
                typeNum = 3;
                while (canAccessPlant[typeNum] == false)
                {
                    typeNum--;
                }
            }
            type = (OldPlantType)typeNum;
        }
        type = (OldPlantType)typeNum;

        FMODUnity.RuntimeManager.PlayOneShot("event:/UI Change");
        whichSeed.sprite = seedImages[typeNum];
        seedCost.text    = Services.GameController.plantInfo[(int)PlantInfo.plantCost, (int)typeNum] + "b";
    }
Example #2
0
 public void LoadPlant(PlantData data)
 {
     position = data.position;
     type     = (OldPlantType)data.plantType;
     stage    = data.stage;
     if (stage != 1)
     {
         GameObject.Destroy(gameObject.transform.GetChild(0).gameObject);
         GameObject.Instantiate(Resources.Load(type.ToString() + "_" + (stage - 1)), gameObject.transform);
         plantDisplay = gameObject.GetComponentInChildren <MeshRenderer>();
     }
     grown         = data.grown;
     growthPercent = data.growthPercent;
     withering     = data.withering;
     if (growthPercent >= 1.0f)
     {
         growthPercent = 1.0f;
         grown         = true;
     }
     if (grown)
     {
         Services.PlantManager.typeCount[(int)type]++;
         if (type == OldPlantType.Tree)
         {
             Services.PlantManager.CreateNewPylon(position);
         }
     }
     gameObject.transform.localScale = Vector3.Lerp(minSize, maxSize, growthPercent);
 }
Example #3
0
    public OldPlant(OldPlantType type, Vector3 pos)
    {
        stage           = 1;
        this.type       = type;
        ratioNeeded     = Services.GameController.plantInfo[(int)PlantInfo.dependentRatio, (int)type];
        babiesPerDay    = (int)Services.GameController.plantInfo[(int)PlantInfo.babiesPerDay, (int)type];
        babyLimit       = (int)Services.GameController.plantInfo[(int)PlantInfo.babiesAllowed, (int)type];
        position        = pos;
        needsMetPercent = 0;
        growthPercent   = 0;
        neighbors       = new List <OldPlant>();
        needs           = new Dictionary <OldPlantType, int>();
        switch (type)
        {
        case OldPlantType.Grass:
            needs.Add(OldPlantType.Spread, 2);
            break;

        case OldPlantType.Shrub:
            /*needs.Add(PlantType.Spread,3);
             * needsActual.Add(PlantType.Spread,0);
             * needsMet.Add(PlantType.Spread,false);*/
            needs.Add(OldPlantType.Grass, 2);
            break;

        case OldPlantType.Tree:
            /*needs.Add(PlantType.Spread,4);
             * needsActual.Add(PlantType.Spread,0);
             * needsMet.Add(PlantType.Spread,false);
             * needs.Add(PlantType.Grass,3);
             * needsActual.Add(PlantType.Grass,0);
             * needsMet.Add(PlantType.Grass,false);*/
            needs.Add(OldPlantType.Shrub, 2);
            break;
        }
        gameObject = new GameObject(type.ToString());
        gameObject.transform.position = position;
        gameObject.tag = "Plant";

        if (type == OldPlantType.Tree)
        {
            BoxCollider c = gameObject.AddComponent(typeof(BoxCollider)) as BoxCollider;
            c.size      = new Vector3(0.5f, 0.5f, 0.5f);
            c.isTrigger = true;
            c.isTrigger = false;
            c.size      = new Vector3(c.size.x, c.size.y * 10f, c.size.z);
        }
        gameObject.transform.localEulerAngles = new Vector3(0, Random.Range(0, 360), 0);

        GameObject.Instantiate(Resources.Load(type.ToString() + "_" + stage), gameObject.transform);
        gameObject.transform.GetChild(0).gameObject.AddComponent(typeof(ComeUpper));
        sizeRandom = Random.Range(0.75f, 1.5f);
        gameObject.transform.localScale = minSize * sizeRandom;
        plantDisplay = gameObject.GetComponentInChildren <MeshRenderer>();
    }
Example #4
0
    //public FMOD.Studio.EventInstance[] bgmS;

    void Awake()
    {
        sentOutOfGoopMessage = false;
        spawnPosition        = transform.position;
        type     = OldPlantType.Spread;
        mousePos = Input.mousePosition;
        Services.PlayerController = this;
        p_state          = GetComponent <PlayerState>();
        p_sc             = GetComponent <PlayerSc>();
        rb               = GetComponent <Rigidbody>();
        collider         = GetComponent <CapsuleCollider>();
        cam              = Camera.main;
        layerGround      = LayerMask.NameToLayer("Ground");
        Cursor.lockState = CursorLockMode.Locked;
        mouseLook        = cam.gameObject.GetComponent <MouseLook>();
        mouseLook.EnableLook();
        fadeOut.gameObject.SetActive(true);
    }
Example #5
0
    public OldPlant CreateNewPlant(OldPlantType type, Vector3 pos, bool playerPlaced = false)
    {
        bool isCloseEnough = CloseToPylon(pos);

        if (!isCloseEnough)
        {
            Debug.Log("Plant is not in pylon radius");
            return(null);
        }
        if (!playerPlaced)
        {
            foreach (OldPlant p in plants)
            {
                float distance           = Vector3.Distance(pos, p.position);
                float maxAllowedDistance = 0f;
                if (p.type != type)
                {
                    //they're different
                    maxAllowedDistance = Services.GameController.plantInfo[(int)PlantInfo.collideDistanceForOthers, (int)type];
                }
                else
                {
                    maxAllowedDistance = Services.GameController.plantInfo[(int)PlantInfo.collideDistanceForSame, (int)type];
                }
                //this is for all the same
                if (distance < maxAllowedDistance)
                {
                    if ((int)p.type < (int)type - 1)
                    {
                        //its below it, so just destroy it instead
                        p.Destroy();
                    }
                    else
                    {
                        Debug.Log("Plant is too close to other plants");
                        return(null);
                    }
                }
            }
            foreach (OldPlant p in newPlants)
            {
                float distance           = Vector3.Distance(pos, p.position);
                float maxAllowedDistance = 0f;
                if (p.type != type)
                {
                    //they're different
                    maxAllowedDistance = Services.GameController.plantInfo[(int)PlantInfo.collideDistanceForOthers, (int)type];
                }
                else
                {
                    maxAllowedDistance = Services.GameController.plantInfo[(int)PlantInfo.collideDistanceForSame, (int)type];
                }
                //this is for all the same
                if (distance < maxAllowedDistance)
                {
                    if ((int)p.type < (int)type - 1)
                    {
                        //its below it, so just destroy it instead
                        p.Destroy();
                    }
                    else
                    {
                        Debug.Log("Plant is too close to other plants");
                        return(null);
                    }
                }
            }
        }

        OldPlant plant = new OldPlant(type, pos);

        if (type == OldPlantType.Tree && firstTreePlanted == false)
        {
            firstTreePlanted = true;
            Services.EventManager.Fire(new FirstTreePlanted());
        }
        FindNeighbors(plant);
        if (playerPlaced)
        {
            plants.Add(plant);
        }
        else
        {
            newPlants.Add(plant);
        }
        Services.EventManager.Fire(new PlantCreated(plant));

        return(plant);
    }