Exemplo n.º 1
0
    void SpawnHopTarget()
    {
        curHopTarget = CacheManager.ActivateRandom("Basic_HopTarget").GetComponent <HopTarget>();
        Vector2 hopTargetPos;

        if (hopperState == HOPPERSTATES.IDLE)       // if hopper is not moving/idle, spawn same X with player
        {
            hopTargetPos = new Vector2(player.transform.position.x, Random.Range(Constants.MIN_SPAWNABLE_Y, Constants.MAX_SPAWNABLE_Y));
        }
        else
        {
            hopTargetPos = new Vector2(Random.Range(Constants.MIN_SPAWNABLE_X, Constants.MAX_SPAWNABLE_X), Random.Range(Constants.MIN_SPAWNABLE_Y, Constants.MAX_SPAWNABLE_Y));
        }

        //spawn initially off screen then animate to supposed position
        curHopTarget.transform.position = new Vector2(hopTargetPos.x, Constants.OFFSCREEN_POINT_Y);
        StartCoroutine(PositionHopTarget(hopTargetPos));

        int colorIndex = Random.Range(0, Constants.NUMBER_OF_HOPCOLORS);

        curHopTarget.CurHopColor  = (HopColor)colorIndex;
        curHopTarget.sprite.color = SetColorAppearance(curHopTarget.CurHopColor);
    }
Exemplo n.º 2
0
    public void CreateItemsList()
    {
        for (int i = 0; i < anchorPoints.Length; i++)
        {
            anchorPoints[i].ResetAnchor();
        }

        for (int i = 0; i < lostItemPool.Length; i++)
        {
            if (!lostItemPool[i].isStatic)
            {
                lostItemPool[i].transform.SetParent(lostItemPoolParent, false);
                lostItemPool[i].gameObject.SetActive(false);
            }

            lostItemPool[i].correct.SetActive(false);
        }

        itemIdsToDisplay = new List <int>();

        List <LostItemObject> lostItemPoolCopy = lostItemPool.ToList();
        int count = lostItemPoolCopy.Count;

        //add all static items first
        for (int i = count - 1; i >= 0; i--)
        {
            if (lostItemPoolCopy[i].isStatic)
            {
                itemIdsToDisplay.Add(lostItemPoolCopy[i].itemId);
                lostItemPoolCopy.RemoveAt(i);
            }
        }

        //add random items
        for (int i = 0; i < numAdditionalItemsToDisplay; i++)
        {
            int randomIndex = Random.Range(0, lostItemPoolCopy.Count);
            itemIdsToDisplay.Add(lostItemPoolCopy[randomIndex].itemId);
            AnchorPoint anchorPoint = null;
            while (anchorPoint == null)
            {
                AnchorPoint x = lostItemPoolCopy[randomIndex].possibleAnchorPoints[Random.Range(0, lostItemPoolCopy[randomIndex].possibleAnchorPoints.Length)];
                if (!x.taken)
                {
                    anchorPoint = x;
                    x.taken     = true;
                }
            }
            lostItemPoolCopy[randomIndex].transform.SetParent(anchorPoint.transform, false);
            lostItemPoolCopy[randomIndex].transform.localPosition = Vector3.zero;
            lostItemPoolCopy[randomIndex].GetComponent <SpriteRenderer>().color        = new Color(anchorPoint.GetComponent <SpriteRenderer>().color.r, anchorPoint.GetComponent <SpriteRenderer>().color.g, anchorPoint.GetComponent <SpriteRenderer>().color.b, 1);
            lostItemPoolCopy[randomIndex].GetComponent <SpriteRenderer>().sortingOrder = anchorPoint.GetComponent <SpriteRenderer>().sortingOrder;
            lostItemPoolCopy[randomIndex].gameObject.SetActive(true);
            anchorPoint.frame.dynamicEntities.Add(lostItemPoolCopy[randomIndex].GetComponent <SpriteRenderer>());
            lostItemPoolCopy.RemoveAt(randomIndex);
        }

        //generate list of items to find
        itemIdsToFind = new List <int>();
        List <int> itemIdsToDisplayCopy = itemIdsToDisplay.ToArray().ToList();

        for (int i = 0; i < numItemsToFind; i++)
        {
            int randomIndex = Random.Range(0, itemIdsToDisplayCopy.Count);
            itemIdsToFind.Add(itemIdsToDisplayCopy[randomIndex]);
            itemIdsToDisplayCopy.RemoveAt(randomIndex);
        }

        if (lostItemTexts != null)
        {
            for (int i = lostItemTexts.Count - 1; i >= 0; i--)
            {
                CacheManager.Store("LostItemText", lostItemTexts[i].gameObject);
            }
        }

        lostItemTexts = new List <LostItemText>();
        foreach (var itemId in itemIdsToFind)
        {
            var itemName = lostItemPool.Single(x => x.itemId == itemId).itemName;

            GameObject lostItemText = CacheManager.ActivateRandom("LostItemText");
            lostItemText.transform.SetParent(lostItemListParent, false);
            lostItemText.transform.position   = lostItemListParent.position;
            lostItemText.transform.localScale = Vector3.one;
            lostItemText.GetComponent <LostItemText>().AssignInfo(itemId, itemName);
            lostItemTexts.Add(lostItemText.GetComponent <LostItemText>());
        }

        ItemsFound = 0;
    }