コード例 #1
0
    /***************************************************************************************
     * disables the rendering of the offset pearl, generates a new pearl, and adds a force to the new pearl,
     * and applies it in the direction specified by angle.
     * ************************************************************************************/
    public void ThrowPearl(float angle, float force)
    {
        //if the beaver is currently holding a pearl
        if (pearlRenderer.enabled)
        {
            soundPlayer.PlayClip(throwSound, 1.0f);
            playerStateScript.SetHasPearl(false);

            //remove it from his grasp visually
            colDetectScript.HidePearl();

            // thrower doesn't interatct with pearl for given time
            beaverSprite.transform.FindChild("beaver_pearl_trigger").gameObject.layer = LayerMask.NameToLayer("Non_Interactable");

            Invoke("MakeInteractable", 0.5f);

            //throw the pearl in the right direction
            GameObject thrownPearl = Instantiate(Resources.Load("Pearl")) as GameObject;

            //remember which beaver threw this pearl
            thrownPearl.GetComponent <pearl_behaviour>().SetBeaver(this.transform.gameObject);

            //the pearl starts on the player
            thrownPearl.transform.position = new Vector2(transform.position.x, transform.position.y);

            //find the angle to throw based on the angle found for the pearl_offest
            //Vector3 dir = Quaternion.AngleAxis(aimingDirScript.GetThrowAngle(), Vector3.forward) * Vector3.up;
            Vector3 dir = Quaternion.AngleAxis(angle, Vector3.forward) * Vector3.up;

            //apply force to the pearl in that direction
            thrownPearl.GetComponent <Rigidbody2D>().AddForce(dir * force);
        }
    }
コード例 #2
0
    void suffocate()
    {
        //isSuffocating = true;
        playerStateScript.SetIsSuffocating(true);
        //print("isSuffocating set true");
        breath_count = 0;

        // trigger the breathing icon to dead
//		iconIndicator.SetTrigger ("is_dead");
//		iconIndicator.SetBool("isDead", true);

        // the beaver should pass through obstacles when they are suffocating
        transform.FindChild("Beaver").gameObject.layer = LayerMask.NameToLayer("Suffocating");                   //The beaver collider
        beaverMouth.transform.FindChild("beaver_mouth").gameObject.layer = LayerMask.NameToLayer("Suffocating"); // The mouth collider

        //drop the pearl, 180 = downwards,
        throwingScript.ThrowPearl(180.0f, dropPearlForce);
        playerStateScript.SetHasPearl(false);

        //movingScript.enabled = false; // disables movement, dashing, throwing
        movingScript.SetMoveForce(constants.moveForceSlow);
        dashScript.enabled      = false;
        throwingScript.enabled  = false;
        colDetectScript.enabled = false;
        beaverPearlCollider.GetComponent <Collider2D>().enabled = false;
        animator.SetTrigger("breathing_in");         // sets animator trigger so that suffocation animation is played
        Invoke("floating", suffocate_time);          // switch to floating after "suffocate_time" amount of seconds
    }
コード例 #3
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Pearl")
        {
            Destroy(other.gameObject);


            if (gameObject.tag == "Left_Clam")
            {
                scoreKeeperScript.IncrementLeftScore();

                clamSprite.material.color = leftScoredColor;
            }
            else if (gameObject.tag == "Right_Clam")
            {
                scoreKeeperScript.IncrementRightScore();

                clamSprite.material.color = rightScoredColor;
            }

            animator.SetTrigger("scored");

            //Wait a little bit before spawning a new pearl
            Invoke("CreateNewPearl", 1.5f);
        }
        else if (other.tag == "Player")
        {
            player_state        playerStateScript     = other.gameObject.GetComponentInParent <player_state>();
            collision_detection playerCollisionScript = other.gameObject.GetComponentInParent <collision_detection>();

            if (playerStateScript.GetHasPearl())
            {
                playerCollisionScript.HidePearl();

                playerStateScript.SetHasPearl(false);

                if (gameObject.tag == "Left_Clam")
                {
                    scoreKeeperScript.IncrementLeftScore();

                    clamSprite.material.color = leftScoredColor;
                }
                else if (gameObject.tag == "Right_Clam")
                {
                    scoreKeeperScript.IncrementRightScore();

                    clamSprite.material.color = rightScoredColor;
                }

                animator.SetTrigger("scored");

                //Wait a little bit before spawning a new pearl
                Invoke("CreateNewPearl", 1.5f);
            }
        }
    }
コード例 #4
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (!playerStateScript.GetIsSuffocating())
        {
            if (other.tag == "Jellyfish")
            {
                //stop moving
                rBody.velocity = new Vector2(0.0f, 0.0f);

                //play electric shock effects
                statusAnim.SetTrigger("shocked");

                //play electric shock sound
                soundPlayer.PlayClip(shockSound, 1.0f);

                damageScript.Damage();
            }

            if (other.tag == "Pearl")
            {
                // play a sound when grabbing the pearl
                soundPlayer.PlayClip(grabSound, 1.0f);

                pearlRenderer.enabled = true;
                pearlOffset.GetComponent <SpriteRenderer> ().enabled = true;

                Destroy(other.gameObject);

                playerStateScript.SetHasPearl(true);
            }
        }

        if (other.tag == "Platform")
        {
            numberOfPlatformsTouching++;
            //playerStateScript.SetIsTouchingPlatform(true);
        }



        if (other.tag == "Boat") // check if they have 5 platforms and if yes they win
        {
            /*
             * Debug.Log(scoreScript.getLeftScore());
             * Debug.Log(scoreScript.getRightScore());
             * Debug.Log(scoreScript.getMaxScore());
             */
            if (other.isTrigger)
            {
                if (scoreScript.getLeftScore() == scoreScript.getMaxScore()) // team 1 set to win
                {
                    if (playerStateScript.GetTeamNumber() == "1")
                    {
                        Application.LoadLevel(3);
                    }
                }
                if (scoreScript.getRightScore() == scoreScript.getMaxScore()) // team 2 set to win
                {
                    if (playerStateScript.GetTeamNumber() == "2")
                    {
                        Application.LoadLevel(4);
                    }
                }
            }
        }
    }