Esempio n. 1
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);
//		}
    }
Esempio n. 2
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 ();
            }
        }
    }
Esempio n. 3
0
 /// <summary>
 /// Unity Function. Check if another game object's collider entered the sky block's collider.
 ///
 /// If it is the needle, break the sky block.
 /// </summary>
 /// <param name="other"></param>
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.GetComponent <NeedleController> () != null)
     {
         NeedleController needle         = other.GetComponent <NeedleController> ();
         NeedleThrowing   needleThrowing = other.gameObject.GetComponent <NeedleThrowing> ();
         this.Split(needle.GetSliceCount(), needle, needleThrowing);
         this.HasBeenHit();
     }
 }
Esempio n. 4
0
    /// <summary>
    /// Starts this instance.
    /// </summary>
    void Start()
    {
        needle           = Instantiate(needlePrefab, transform.position, Quaternion.identity);
        needleThrowing   = needle.GetComponent <NeedleThrowing> ();
        needleController = needle.GetComponent <NeedleController> ();


//		if (PlayerPrefs.HasKey ("Player_" + GameController_v7.Instance.GetObjectStateManager().currentPlayerName)) {
//			string playerJSON = PlayerPrefs.GetString ("Player_" + GameController_v7.Instance.GetObjectStateManager().currentPlayerName);
//			PlayerJSONParams playerStats = JsonUtility.FromJson<PlayerJSONParams> (playerJSON);
//			this.hasNeedle = playerStats.hasNeedle;
//			this.hasHammer = playerStats.hasHammer;
//			this.hasThread = playerStats.hasThread;
//			this.equippedDenominator = playerStats.equppedDenominator;
//		}

        this.player = GameObject.FindObjectOfType <PlayerYuni>().GetComponent <PlayerYuni>();


        playerAnimator   = player.GetPlayerAnimator();
        playerController = player.GetPlayerMovement();

        this.fractionNumeratorLabelObject = this.fractionNumeratorLabel.gameObject;
        this.fractionLabelObject.SetActive(false);
        this.numeratorLabelObject.SetActive(false);


        this.listTextMesh = new List <TextMesh> ();
        listTextMesh.Add(numeratorLabel);
        listTextMesh.Add(fractionNumeratorLabel);
        listTextMesh.Add(fractionDenominatorLabel);

        EventBroadcaster.Instance.AddObserver(EventNames.ON_LCD_UNPAUSE, this.IsLCDHit);

        this.hammerAttack.SyncWithEquippedDenominator(this.equippedDenominator);
        Debug.Log("<color=green>Equipped is " + equippedDenominator + "</color>");
        this.needleController.SyncWireSliceCountWithEquippedDenominator(this.equippedDenominator);
        this.hammerAttack.DisableBreaker();


        if (!this.HasHammer())
        {
                        #if UNITY_ANDROID
            GameController_v7.Instance.GetMobileUIManager().ToggleMobileControls(false);
            GameController_v7.Instance.GetMobileUIManager().ToggleBaseWithPickupControls(true);
                        #endif
        }
        if (this.HasNeedle())
        {
            EventBroadcaster.Instance.PostEvent(EventNames.YUNI_ACQUIRED_NEEDLE);
        }

//		EventBroadcaster.Instance.AddObserver (EventNames.ON_LCD_DONE, this.IsLCDDonePlaying);
    }
Esempio n. 5
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
            }
        }
    }
Esempio n. 6
0
    void Awake()
    {
        player = GameObject.FindGameObjectWithTag("Player");
//		playerManager = player.GetComponent<PlayerManager> ();
        needleThrowing = gameObject.GetComponent <NeedleThrowing>();


//		x = transform.position.x;
//		y = transform.position.y;
//		returnSpeed = 50.0f;
        angleSpeed  = 1.0f;
        onlyHitOnce = true;
//		gameObject.SetActive(false);
    }
Esempio n. 7
0
    // Use this for initialization
    void Start()
    {
        anim                    = GetComponent <Animator>();
        rb2d                    = GetComponent <Rigidbody2D>();
        isFacingRight           = true;
        isGrounded              = true;
        this.entranceStandingIn = null;        //Set to null at initialization because we assume player is not at any entrance at the start
        needleWeapon            = Instantiate(needlePrefab, transform.position, Quaternion.identity);
//		needleController = needleWeapon.GetComponent<NeedleController> ();
        needleThrowing = needleWeapon.GetComponent <NeedleThrowing>();
                #if UNITY_ANDROID
        mobile = GameObject.Find("Mobile UI").GetComponent <MobileUI> ();
                #endif

        GameController_v7.Instance.GetPauseController().onPauseGame    += Pause;
        GameController_v7.Instance.GetPauseController().onContinueGame += Continue;
    }