Exemplo n.º 1
0
    public void Collected()
    {
        // Don't collect if we're not on the quest for the wizzard
        if (!VariableRepo.Instance.Retrieve <bool>("onQuest"))
        {
            return;
        }

        _counter.AddCoin();
        Destroy(gameObject);
    }
 void OnCollisionEnter2D(Collision2D col)
 {
     if (col.collider.bounds.max.y < transform.position.y &&
         col.collider.bounds.min.x < transform.position.x + 0.5f &&
         col.collider.bounds.max.x > transform.position.x - 0.5f &&
         col.collider.tag == "Player")
     {
         if (totalCoins > 0)
         {
             spriteAnim.Play("coinblock_hit");
             audioS.Play();
             coinCounter.AddCoin();
             totalCoins -= 1;
             if (totalCoins == 0)
             {
                 GetComponent <Animator> ().enabled = false;
                 child.transform.GetChild(0).gameObject.GetComponent <SpriteRenderer> ().color  = Color.white;
                 child.transform.GetChild(0).gameObject.GetComponent <SpriteRenderer> ().sprite = disabled;
             }
         }
     }
 }
Exemplo n.º 3
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.tag == "Player")
     {
         if (type == Amount.one)
         {
             coinCounter.AddCoin();
         }
         else if (type == Amount.ten)
         {
             coinCounter.Add10Coins();
         }
         else if (type == Amount.thirty)
         {
             coinCounter.Add30Coins();
         }
         else if (type == Amount.fifty)
         {
             coinCounter.Add50Coins();
         }
         Destroy(this.gameObject);
     }
 }
Exemplo n.º 4
0
    // Attempts to move the player in the requested direction
    // If that space is occupied by a non-passable block, then the player
    // bounce off of the spot and mvoe nowhere
    // rowMove and colMove represent the scale of the movement
    //      1, 0, or -1 for moving by one block
    //      other float values for moving back on recursive call in case of collision
    IEnumerator SmoothMove(float rowMove, float colMove, float distance)
    {
        canMove = false;            // Prevent player from beginning another move while they are moving
        float   remDist = distance; // The remaining distance to move the player
        float   thisMove;           // Holds how much the player will move each frame
        Vector3 startPos = this.gameObject.transform.position;

        // Player begins movithis.gameObject.transform.position;ng slow, and picks up speed until they reach their final position
        while (remDist > 0)
        {
            thisMove = Mathf.Round((distance - remDist) * 100f) / 100f; // Round
            thisMove = Mathf.Max(thisMove, .01f);                       // Max is used to allow the movement to start
            thisMove = Mathf.Min(remDist, thisMove, maxMovementSpeed);  // prevent from moving past the block or too fast

            RaycastHit2D[] hits = Physics2D.RaycastAll(transform.position, new Vector2(colMove, rowMove), thisMove);
            foreach (RaycastHit2D hit in hits)
            {
                if (debug)
                {
                    Debug.Log(hit.collider.gameObject.tag + ", " + hasCollided);
                }

                if ((hit.collider.gameObject.tag == "Blocking" || hit.collider.gameObject.tag == "Door") && !hasCollided)
                {
                    hasCollided = true; // Prevents multiple collisions fro happening
                    if (debug)
                    {
                        Debug.Log("Collision Detected!");
                    }
                    if (hit.collider.gameObject.tag == "Door")
                    {
                        ThoughtBubble.startPos = startPos;
                        Debug.Log("Saving position as: " + ThoughtBubble.startPos);
                        ThoughtBubble.stillMoving = true;
                        Debug.Log("Displaying Thought Bubble...");
                        gameObject.GetComponent <ThoughtBubble>().DisplayBubble();
                    }

                    StartCoroutine(SmoothMove(-rowMove, -colMove, distance - remDist)); // Move in reverse direction until at original position

                    yield break;                                                        // Leave coroutine as to not finish forward movement
                }
                else if (hit.collider.gameObject.tag == "Button")
                {
                    door.GetComponent <DoorObstacle>().Open();
                }
                else if (hit.collider.gameObject.tag == "Coin")
                {
                    CoinCounter.AddCoin();
                    Destroy(hit.collider.gameObject);
                }
            }

            Vector2 move = new Vector2(colMove * thisMove, rowMove * thisMove);
            rb.MovePosition((Vector2)transform.position + move);
            remDist -= thisMove;

            if (debug)
            {
                Debug.Log("Player moved " + thisMove + " units, remaining: " + remDist);
            }

            yield return(new WaitForFixedUpdate()); // Wait for Fixed Update to assure MovePosition functions correctly
        }
        if (debug && remDist != 0)
        {
            Debug.Log("Imperfect movement detected: Ramaining Distance of " + remDist + " was not moved!");
        }
        canMove     = true;  // allow the player to move again
        hasCollided = false; // Resolve any collisions
        ThoughtBubble.stillMoving = false;
    }
Exemplo n.º 5
0
 public void Pick()
 {
     _coinCounter.AddCoin();
 }