Exemplo n.º 1
0
    public void ItemGifted(ItemController.Type typeOfItem)
    {
        Vector2    effectPosition = new Vector2(transform.position.x, transform.position.y + 0.5f);
        GameObject effect         = Instantiate(celebrationEffect, effectPosition, Quaternion.identity);

        GameObject itemEffect = Instantiate(itemAnimationEffect, transform.position, Quaternion.identity);

        itemEffect.transform.Find("Item Sprite").gameObject.GetComponent <SpriteRenderer>().sprite = GameController.instance.playerItemsManager.GetSpriteForType(typeOfItem);

        switch (typeOfItem)
        {
        case ItemController.Type.FOOD:
            food += 2f;
            food  = Mathf.Max(0f, Mathf.Min(6f, food));
            break;

        case ItemController.Type.MEDICINE:
            health += 2f;
            health  = Mathf.Max(0f, Mathf.Min(6f, health));
            break;

        case ItemController.Type.TOY:
            happy += 1.5f;
            happy  = Mathf.Max(0f, Mathf.Min(6f, happy));
            break;
        }

        GameController.instance.HUD.UpdatePanels();
    }
Exemplo n.º 2
0
    public void UseItem(ItemController.Type itemType)
    {
        if (GameController.instance.pet.IsPlayerCloseToPet())
        {
            GameController.instance.pet.ItemGifted(itemType);
            SubstractItem(itemType);

            SoundManager.instance.PlaySingle(useItemSound);
        }
    }
Exemplo n.º 3
0
 int GetIndexOfItemType(ItemController.Type itemType)
 {
     for (int i = 0; i < itemKeys.Length; i++)
     {
         if (itemKeys[i] == itemType)
         {
             return(i);
         }
     }
     return(-1);
 }
    IEnumerator SpawnItem()
    {
        state = SpawnPointState.SPAWNING;

        int randomItemIndex = Random.Range(0, 3);

        ItemController itemController = (ItemController)Instantiate(GameController.instance.itemPrefab, new Vector2(0f, 0f), Quaternion.identity).GetComponent <ItemController>();

        ItemController.Type itemType = (ItemController.Type)randomItemIndex;

        itemController.transform.SetParent(this.transform, false);

        itemController.Init(itemType);

        state = SpawnPointState.WAITING;

        yield break;
    }
Exemplo n.º 5
0
    public void AddItem(ItemController.Type itemType)
    {
        SoundManager.instance.PlaySingle(pickupItemSound);

        if (items.ContainsKey(itemType))
        {
            items[itemType]++;
        }
        else
        {
            items.Add(itemType, 1);
        }

        itemKeys = items.Keys.ToArray();

        currentItemTypeSelectedIndex = GetIndexOfItemType(itemType);
        GameController.instance.HUD.UpdateCurrentItemTypeSelected();
    }
Exemplo n.º 6
0
    public void SubstractItem(ItemController.Type itemType)
    {
        if (items.ContainsKey(itemType) && items[itemType] > 0)
        {
            items[itemType]--;
            if (items[itemType] == 0)
            {
                items.Remove(itemType);
                itemKeys = items.Keys.ToArray();

                if (itemKeys.Length == 0)
                {
                    currentItemTypeSelectedIndex = -1;
                }
                else
                {
                    currentItemTypeSelectedIndex = 0;
                }
            }
        }
    }
Exemplo n.º 7
0
    public Sprite GetSpriteForType(ItemController.Type type)
    {
        Sprite sprite = null;

        switch (type)
        {
        case ItemController.Type.MEDICINE:
            sprite = GameController.instance.medicine;
            break;

        case ItemController.Type.FOOD:
            sprite = GameController.instance.food;
            break;

        case ItemController.Type.TOY:
            sprite = GameController.instance.toy;
            break;

        case ItemController.Type.GEM:
            sprite = GameController.instance.gem;
            break;
        }
        return(sprite);
    }