示例#1
0
    void updateSeed(Seed seedToUpdate, int seedIndex)
    {
        Seed.SEED_STATE state = seedToUpdate.getSeedState();
        switch (state)
        {
        case Seed.SEED_STATE.SEED:
            transform.GetChild(seedIndex).GetChild(0).GetComponent <SpriteRenderer>().sprite = seedSprite;
            transform.GetChild(seedIndex).GetChild(0).localPosition    = positionsForPlants["seed"];
            transform.GetChild(seedIndex).GetChild(0).localEulerAngles = rotationForPlants["seed"];
            transform.GetChild(seedIndex).GetChild(0).localScale       = scaleForPlants["seed"];
            break;

        case Seed.SEED_STATE.GROWN:
            transform.GetChild(seedIndex).GetChild(0).GetComponent <SpriteRenderer>().sprite = getPlantedSprite(seedToUpdate);
            transform.GetChild(seedIndex).GetChild(0).localPosition    = positionsForPlants[seedToUpdate.name];
            transform.GetChild(seedIndex).GetChild(0).localEulerAngles = rotationForPlants[seedToUpdate.name];
            transform.GetChild(seedIndex).GetChild(0).localScale       = scaleForPlants[seedToUpdate.name];
            break;

        case Seed.SEED_STATE.GONE_BAD:
            transform.GetChild(seedIndex).GetChild(0).GetComponent <SpriteRenderer>().sprite = goneBadSprite;
            transform.GetChild(seedIndex).GetChild(0).localPosition    = positionsForPlants["rot"];
            transform.GetChild(seedIndex).GetChild(0).localEulerAngles = rotationForPlants["rot"];
            transform.GetChild(seedIndex).GetChild(0).localScale       = scaleForPlants["rot"];
            break;
        }
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if (feasting)
        {
            return;
        }
        if (Input.GetMouseButtonDown(0))
        {
            if (leaveFarmSign.GetComponent <MouseOverObj>().isMouseOver)
            {
                SceneHandler.instance.changeScene(SceneHandler.SCENES.OVERWORLD);
                SoundManager.instance.playSound(SoundManager.SOUNDS.SELECT_SHELF_OBJ);
            }

            if (FeastSign.GetComponent <MouseOverObj>().isMouseOver)
            {
                StartCoroutine(endDay());
            }
        }
        if (Input.GetMouseButtonUp(0))
        {
            Dictionary <int, Seed> plantedSeeds = GameState.instance.getPlantedSeeds();

            for (int i = 0; i < fieldSize; i++)
            {
                if (transform.GetChild(i).GetComponent <MouseOverObj>().isMouseOver)
                {
                    //player trying to plant here
                    if (draggedObject != null)
                    {
                        if (GameState.instance.emptyFarmSlot(i))
                        {
                            plantSeed(i);
                            SoundManager.instance.playSound(SoundManager.SOUNDS.FARM);
                        }
                    }
                    //player trying to harvest here
                    if (draggedObject == null && plantedSeeds.ContainsKey(i))
                    {
                        Seed.SEED_STATE state = plantedSeeds[i].getSeedState();
                        switch (state)
                        {
                        case Seed.SEED_STATE.SEED:
                            break;

                        case Seed.SEED_STATE.GROWN:
                            GameState.instance.eatFood(i);
                            removeSeed(i);
                            SoundManager.instance.playSound(SoundManager.SOUNDS.HARVEST);
                            break;

                        case Seed.SEED_STATE.GONE_BAD:
                            removeSeed(i);
                            plantedSeeds.Remove(i);
                            SoundManager.instance.playSound(SoundManager.SOUNDS.HARVEST_ROTTEN);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            draggedObject = null;
        }
    }