示例#1
0
    bool TryDropCard(Collider2D c)
    {
        //Only test for the first collider that player is touching
        CardDropoff dropOff = c.GetComponent <CardDropoff>();

        //Also ignore totally if dropoff already has all of its cards (but don't send card away)
        if (dropOff == null || dropOff != wordCollider || !dropOff.CanTakeCard())
        {
            return(false);
        }


        if (holding && buttonFixedPressed)
        {
            //Increment drop counter
            TotalDrops += 1;

            //Check if correct card
            //Unclear if card can be dropped if it's still wrong
            //To prevent backtracking it could fly back to where it came from
            CardPickup cardPickup = holding.GetComponent <CardPickup>();
            if (!dropOff.IsSolution(cardPickup))
            {
                IncorrectDrops += 1;
                //Send back to where it came from
                //Play some kind of negative sound
                AudioSource.PlayClipAtPoint(SoundManager.GetClip("ring_down"), transform.position);
                cardPickup.GetComponent <BoxCollider2D>().enabled = true;
                cardPickup.MoveHome();

                //Action was completed, no input should have more than one action happen
            }
            else
            {
                CorrectDrops += 1;
                //Remove CardPickup monobehaviour
                //Or set flag to prevent pickup again of card (dropoff may be one way)
                //Trigger is already disabled
                dropOff.GiveCard(holding);

                //Play positive sound
                AudioSource.PlayClipAtPoint(SoundManager.GetClip("ring_up"), transform.position);

                //Change color of text
                textColor = CompletionColor;
                var textMesh = dropOff.UITextMesh;
                textMesh.color = CompletionSelectionColor;
            }

            holding            = null;
            didActionThisFrame = true;
            return(true);
        }
        else
        {
            return(false);
        }
    }
示例#2
0
    void TryReleaseTrigger(Collider2D c)
    {
        CardDropoff dropOff = c.GetComponent <CardDropoff>();

        if (wordCollider == null || dropOff == null || wordCollider != dropOff)
        {
            return;
        }
        wordCollider = null;
        //Reset color of text
        var textMesh = dropOff.UITextMesh;

        textMesh.color = textColor;
    }
示例#3
0
    void CreateCardGameElements(List <CardIndexer> phrase)
    {
        dropoffs = new List <CardDropoff>();
        for (int i = 0; i < phrase.Count; i++)
        {
            CardIndexer cardIndexer = phrase[i];
            CardData    card        = cardIndexer.Card;
            CardPickup  cardP       = GameObject.Instantiate(CardPickup, PickupParent).GetComponent <CardPickup>();
            cardP.transform.position = PickupParent.position;
            //Pick card based on directionality
            cardP.SetCard(cardIndexer, Direction);

            CardDropoff dropoff = GameObject.Instantiate(CardDropOff, DropoffParent).GetComponent <CardDropoff>();
            dropoff.transform.position = DropoffParent.position;

            //From or to length
            string textCard  = Direction == CardManager.Direction.To ? card.To : card.From;
            string textBlock = Direction == CardManager.Direction.To ? card.From : card.To;

            //Temp String formatting for capital first letter and period at end
            if (i == 0)
            {
                if (!string.IsNullOrEmpty(textCard))
                {
                    textCard = textCard.First().ToString().ToUpper() + textCard.Substring(1);
                }
                if (!string.IsNullOrEmpty(textBlock))
                {
                    textBlock = textBlock.First().ToString().ToUpper() + textBlock.Substring(1);
                }
            }
            else if (i == phrase.Count - 1)
            {
                if (!string.IsNullOrEmpty(textCard))
                {
                    textCard += ".";
                }
                if (!string.IsNullOrEmpty(textBlock))
                {
                    textBlock += ".";
                }
            }

            GameObject uiText = GameObject.Instantiate(TextBlock, BlockUI);
            uiText.GetComponentInChildren <TextMeshProUGUI>().text = textBlock;

            dropoff.SetCard(cardIndexer, Direction, uiText);
            dropoffs.Add(dropoff);
        }
    }
示例#4
0
    void TryLockInTrigger(Collider2D c)
    {
        CardDropoff dropOff = c.GetComponent <CardDropoff>();

        //Is this not a CardDropoff or does it already have a card that it took?
        if (dropOff == null)
        {
            return;
        }
        //Release old dropoff for new one if it is closer, otherwise ignore it
        else if (wordCollider != null)
        {
            if (Vector3.SqrMagnitude(transform.position - c.transform.position) < Vector3.SqrMagnitude(transform.position - wordCollider.transform.position))
            {
                TryReleaseTrigger(wordCollider.GetComponent <Collider2D>());
            }
            else
            {
                return;
            }
        }

        wordCollider = dropOff;
        //Change color of text if it is selectable
        var textMesh = dropOff.UITextMesh;

        textColor = textMesh.color;

        if (dropOff.CanTakeCard())
        {
            textMesh.color = SelectionColor;
        }
        else
        {
            textMesh.color = CompletionSelectionColor;
        }
    }