Beispiel #1
0
    /// <summary>
    /// Unity Function. Collision checker if the breakable object was hit by the hammer.
    /// </summary>
    /// <param name="collision">Collision</param>
    void OnCollisionEnter2D(Collision2D collision)
    {
        if (!isBroken)
        {
            if (collision.collider.gameObject.layer == LayerMask.NameToLayer("HammerBreaker"))                // Hammer
            {
                HammerObject hammer = collision.collider.gameObject.GetComponentInParent <HammerObject> ();
                if (hammer.IsAttacking())
                {
                    this.Break();
                }
            }
            else if (collision.collider.gameObject.GetComponent <NeedleController>() != null)             // Needle
            {
                Debug.Log("NEEDLE HAS HIT");
                NeedleThrowing   needleThrowing = collision.collider.gameObject.GetComponent <NeedleThrowing> ();
                NeedleController needle         = collision.collider.gameObject.GetComponent <NeedleController> ();
                needleThrowing.setPullTowards(false);
                needleThrowing.setHookPullTowards(false);
                needle.hasHit = true;
//				NeedleController needle = collision.collider.gameObject.GetComponent<NeedleController>();
//				Break ();
            }
        }
    }
Beispiel #2
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.GetComponent <NeedleThrowing>())
        {
            Debug.Log("HOOK NEEDLE HIT");
            NeedleController needleController = other.gameObject.GetComponent <NeedleController> ();
            NeedleThrowing   needleThrowing   = other.gameObject.GetComponent <NeedleThrowing> ();

            if (needleThrowing.getPlayerAttack().HasThread())
            {
                needleThrowing.setExtendedNeedleTransform(gameObject.transform.position);
                needleThrowing.setPullTowards(true);
                needleThrowing.setHookPullTowards(true);

                //			needleThrowing.setExtendedNeedleTransform (GameObject.FindGameObjectWithTag("NeedleExtendedTransform").transform.position);

//				Physics2D.IgnoreCollision (needleThrowing.getPlayerMovement().gameObject.GetComponent<Collider2D>(), gameObject.GetComponent <Collider2D> ());
                needleController.hasHit = true;
            }
        }
//		else if (other.gameObject.CompareTag ("Player")) {
//			PlayerMovement player = other.GetComponent<PlayerMovement> ();
//
//			player.transform.position = Vector3.MoveTowards (player.transform.position, transform.position, 1 * Time.deltaTime);
//		}
    }
Beispiel #3
0
    /// <summary>
    /// Slices the sky block into fragments. The fragments are then dropped to be picked up by the player avatar.
    /// </summary>
    /// <param name="pieceCount">Number of pieces</param>
    /// <param name="needle">Needle that sliced the sky block.</param>
    /// <param name="needleThrowing">Needle Throwing behaviour</param>
    public void Split(float pieceCount, NeedleController needle, NeedleThrowing needleThrowing)
    {
        // You can only split if the numerator is greater than 0
        // TODO: Add a constraint for splitting a piece too small (since players can cascadingly split)
        // i.e. Split to 4, return 2/4, Split to 8, and so on. Maybe check if the decimal value is past a certain threshold
        // and if its too small, prompt the user that he/she can't do that via Yuni/Hints


        //		Debug.Log ("num is "+this.GetNumerator());
        //		Debug.Log ("den is "+this.GetDenominator());
        //		Debug.Log ("divided by "+pieceCount);

        if (this.GetNumerator() > 0)
        {
            if (pieceCount <= 0 && needle != null)
            {
                // Deflect needle if pieceCount is 0
                Debug.Log("NEEDLE HAS HIT");
                needleThrowing.setPullTowards(false);
                needleThrowing.setHookPullTowards(false);
                needle.hasHit = true;
            }
            else if (this.NotTooSmall(pieceCount))
            {
                Debug.Log("Entered Split");
                float newDenominator = this.GetDenominator() * pieceCount;
                //			float newNumerator = this.GetNumerator () * pieceCount;

                // Create a SkyFragmentPiece for each pieceCount
                float speed         = 500f;
                int   originalCount = skyFragmentPieces.Count;
                for (int i = 0; i < pieceCount; i++)
                {
                    this.skyFragmentPieces.Add(CreateSkyFragmentPiece(this.skyBlockParent.GetDetachedManager().gameObject, (int)this.GetNumerator(), (int)newDenominator));
                    this.skyFragmentPieces [originalCount + i].transform.localPosition = new Vector3(this.skyFragmentPieces [i].GetWidth() * i, 0f, 0f);
                    this.skyFragmentPieces [originalCount + i].GetRigidBody2D().AddRelativeForce(Random.onUnitSphere * speed);

                    this.skyFragmentPieces [originalCount + i].SetPiecesNeverBreak(this.piecesNeverBreak);
                }

                this.SetNumerator(0);
                this.SetDenominator(newDenominator);
                this.HasBeenBroken();
            }
            else
            {
                // Too small. Yuni prompt.
                // TODO: Yuni Hints
            }
        }
    }