// Update is called once per frame
 void Update()
 {
     if (MinigameInputHelper.IsButton1Held(hand.player) && !hand.isBurned())
     {
         rbody.MoveRotation(Mathf.Lerp(rbody.rotation, rotLimit, rotSpeed * Time.deltaTime));
     }
     else
     {
         rbody.MoveRotation(Mathf.Lerp(rbody.rotation, startRot + startRotLimit, rotSpeed * Time.deltaTime));
     }
 }
Пример #2
0
        void Update()
        {
            if (direction)
            {
                spriteRenderer.flipX = false;
            }
            else
            {
                spriteRenderer.flipX = true;
            }
            float horizontal_axis = MinigameInputHelper.GetHorizontalAxis(player + 1);
            bool  button1         = MinigameInputHelper.IsButton1Down(player + 1);
            bool  button2         = MinigameInputHelper.IsButton2Down(player + 1);
            bool  button2Up       = MinigameInputHelper.IsButton2Up(player + 1);
            float pos_x           = gameObject.transform.position.x;
            float pos_y           = gameObject.transform.position.y;
            float o_pos_x         = other.transform.position.x;
            float o_pos_y         = other.transform.position.y;
            //double p1_height = this.GetComponent<MoveScript>().playerHeight;
            double p1_width = 0.6 * this.GetComponent <MoveScript>().playerWidth;

            time += Time.deltaTime;
            if (horizontal_axis < -0.1)
            {
                direction = true;                                     //left
            }
            else if (horizontal_axis > 0.1)
            {
                direction = false;                                         //right
            }
            if ((button1 || MinigameInputHelper.IsButton1Held(player + 1)) && time >= cooldown && TYPE != 4 && ballCharge < 30)
            {
                ballCharge++;
            }

            if (MinigameInputHelper.IsButton1Up(player + 1) && time >= cooldown && ballCharge > 0 && TYPE != 4)
            {
                if (player == 0)
                {
                    animator.Play("Attack");
                }
                else
                {
                    animator.Play("Attack2");
                }
                //animator.SetInteger("state", 3 + TYPE);
                attacktime = 0;
                time       = 0;
                GameObject p;
                attacktime = 0;
                if (direction && !gameObject.GetComponent <ActionScript>().defenseOn)
                {
                    p = Instantiate(projectile, transform.position - new Vector3((float)2, -1, 0), transform.rotation);
                    p.GetComponent <Rigidbody2D>().velocity = new Vector2(-2.5f, 1.0f) * ballCharge;
                }
                else if (!gameObject.GetComponent <ActionScript>().defenseOn)
                {
                    p = Instantiate(projectile, transform.position + new Vector3((float)2, 1, 0), transform.rotation);
                    p.GetComponent <Rigidbody2D>().velocity = new Vector2(2.5f, 1.0f) * ballCharge;
                }
                ballCharge = 0;
            }

            //if(attacktime > 0.5 && animator.GetInteger("state") == 3 + TYPE) animator.SetInteger("state", 0 + TYPE);

            if (button1 && time >= cooldown && TYPE != 0)             //kick
            {
                double xdist = gameObject.transform.position.x - other.transform.position.x;

                /*if (!direction && ((pos_x < 0 && xdist > 0 && xdist < 2) ||
                 * (pos_x > 0 && xdist < 0 && xdist > -2)) &&
                 * other.GetComponent<ActionScript>().defenseOn)
                 * {
                 * other.GetComponent<ActionScript>().shieldHits = other.GetComponent<ActionScript>().shieldHits + 1;
                 * }*/
                time = 0;
                if (player == 0)
                {
                    animator.Play("K_Attack");
                }
                else
                {
                    animator.Play("Attack_K2");
                }
                if (direction && xdist > 0 && xdist < 3 * p1_width)                /*((pos_x < 0 && xdist > 0 && xdist < 2*p1_width) ||
                                                                                    * (pos_x > 0 && xdist < 0 && xdist > -2*p1_width)))*/
                {
                    if (!other.GetComponent <ActionScript>().defenseOn)
                    {
                        gameObject.GetComponent <HealthScript>().TakeDamage(1);
                        Debug.Log("reached here");
                    }
                    else
                    {
                        other.GetComponent <ActionScript>().shieldHits++;
                        other.GetComponent <Renderer>().material.SetColor("_Color", Color.blue);
                        Debug.Log(shieldHits);

                        /*if (shieldHits >= 3)
                         * {
                         * shield.transform.localScale = new Vector3(0, 0, 0);
                         * defenseOn = false;
                         * shieldHits = 0;
                         * defCooldown = 0;
                         * }*/
                    }
                }

                /*if (direction && ((pos_x < 0 && xdist < 0 && xdist > -2) ||
                 * (pos_x > 0 && xdist > 0 && xdist < 2)) &&
                 * other.GetComponent<ActionScript>().defenseOn)
                 * {
                 * other.GetComponent<ActionScript>().shieldHits++;
                 * }*/
                if (!direction && xdist < 0 && xdist > -3 * p1_width)                /*((pos_x < 0 && xdist < 0 && xdist > -2*p1_width) ||
                                                                                      * (pos_x > 0 && xdist > 0 && xdist < 2*p1_width)))*/
                {
                    if (!other.GetComponent <ActionScript>().defenseOn)
                    {
                        gameObject.GetComponent <HealthScript>().TakeDamage(1);
                        Debug.Log("reached here");
                    }
                    else
                    {
                        other.GetComponent <ActionScript>().shieldHits++;
                        other.GetComponent <Renderer>().material.SetColor("_Color", Color.blue);
                        Debug.Log(shieldHits);

                        /*if (shieldHits >= 3)
                         * {
                         * shield.transform.localScale = new Vector3(0, 0, 0);
                         * defenseOn = false;
                         * shieldHits = 0;
                         * defCooldown = 0;
                         * }*/
                    }
                }
            }

            /*if (button1 && TYPE != 0) {
             * Debug.Log("karate attack");
             *
             * //animator.SetInteger("state", 3 + TYPE);
             * Debug.Log(animator.GetInteger("state"));
             * attacktime = 0;
             * }
             * /*dif (button1 && time >= cooldown && TYPE != 0 && !other.GetComponent<ActionScript>().defenseOn){//punch //IS THERE A SHIELD CHECK HERE?? yes!
             * double xdist = pos_x - o_pos_x;
             * if (!direction && ((pos_x < 0 && xdist > 0 && xdist < 2*p1_width) ||
             *      (pos_x > 0 && xdist < 0 && xdist > -2*p1_width)))
             * {
             *      gameObject.GetComponent<HealthScript>().TakeDamage(1);
             * }
             * if (direction && ((pos_x < 0 && xdist < 0 && xdist > -2*p1_width) ||
             *      (pos_x > 0 && xdist > 0 && xdist < 2*p1_width)))
             * {
             *      gameObject.GetComponent<HealthScript>().TakeDamage(1);
             * }
             * }*/
            defCooldown += Time.deltaTime;
            if (defCooldown > 3 && !defenseOn)
            {
                GameObject.Find("shieldready" + player).transform.localScale = new Vector3(1, 1, 1);
            }
            else
            {
                GameObject.Find("shieldready" + player).transform.localScale = new Vector3(0, 0, 0);
            }
            if (button2 && TYPE != 8 && defCooldown > 3)
            {
                shield.transform.localScale = new Vector3(1, 1, 1);
                defenseOn   = true;
                defCooldown = 0;
            }
            if (shieldHits >= 3)
            {
                shield.transform.localScale = new Vector3(0, 0, 0);
                defenseOn   = false;
                shieldHits  = 0;
                defCooldown = 0;
            }
            if (button2Up)
            {
                shield.transform.localScale = new Vector3(0, 0, 0);
                defenseOn = false;
            }
            attacktime += Time.deltaTime;
        }
        // Update is called once per frame
        void Update()
        {
            //Don't take any input if stunned
            if (stunned)
            {
                stunTime -= Time.deltaTime;
                if (stunTime <= 0)
                {
                    stunned = false;
                }
                thisRigidBody.velocity = new Vector2(0, thisRigidBody.velocity.y);
            }
            else
            {
                //Horizontal movement. Maintains y velocity
                inputVector = new Vector2(MinigameInputHelper.GetHorizontalAxis(playerNumber) * moveSpeed, thisRigidBody.velocity.y);
                if (inputVector != thisRigidBody.velocity && !isDashing)
                {
                    thisRigidBody.velocity = inputVector;
                }

                //Jump input
                if (MinigameInputHelper.IsButton1Down(playerNumber) || MinigameInputHelper.GetVerticalAxis(playerNumber) == 1)
                {
                    //Only jumps if the player is not already jumping or falling
                    if (thisRigidBody.velocity.y < 0.01f && thisRigidBody.velocity.y > -0.01f)
                    {
                        //jump by adding upward force
                        thisRigidBody.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
                        doubleJumpUsed = false;
                        animator.SetBool("isJumping", true);
                    }
                    //Double jump
                    else if (!doubleJumpUsed && hasDoubleJump)
                    {
                        thisRigidBody.velocity = new Vector3(thisRigidBody.velocity.x, 0, 0);
                        thisRigidBody.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
                        doubleJumpUsed = true;
                    }
                }
                else if (thisRigidBody.velocity.y < 0.01f && thisRigidBody.velocity.y > -0.01f)
                {
                    animator.SetBool("isJumping", false);
                }

                // Dash
                if (MinigameInputHelper.IsButton2Down(playerNumber) && hasDash && !isDashing)
                {
                    if (this.gameObject.GetComponent <SpriteRenderer>().flipX == false)
                    {
                        thisRigidBody.AddForce(transform.right * 15f, ForceMode2D.Impulse);
                        isDashing = true;
                        Invoke("resetDash", 0.5f);
                    }
                    else
                    {
                        thisRigidBody.AddForce(transform.right * -15f, ForceMode2D.Impulse);
                        isDashing = true;
                        Invoke("resetDash", 0.5f);
                    }
                }


                //Jetpack input
                if (MinigameInputHelper.IsButton1Held(playerNumber) && hasJetPack)
                {
                    velVector = new Vector3(thisRigidBody.velocity.x, jetPackVelocity, 0);
                    thisRigidBody.velocity = velVector;
                }
            }
            //Animation stuff
            tagged = GetComponent <Tag>().isTagged;
            animator.SetFloat("verticalVelocity", thisRigidBody.velocity.y);
            GameObject bomb = GetComponent <Tag>().bomb;

            //Adjust speed for moving platforms
            if (transform.parent != null && transform.parent.gameObject.GetComponent <Rigidbody2D>() != null)
            {
                Vector2 parentVelocity = transform.parent.gameObject.GetComponent <Rigidbody2D>().velocity;
                thisRigidBody.velocity += parentVelocity;
                animator.SetFloat("horizontalSpeed", Mathf.Abs(thisRigidBody.velocity.x - parentVelocity.x));
                if (thisRigidBody.velocity.x - parentVelocity.x > 0.1)
                {
                    this.gameObject.GetComponent <SpriteRenderer>().flipX = false;
                    bomb.transform.localPosition = new Vector3(Mathf.Abs(bomb.transform.localPosition.x), bomb.transform.localPosition.y, bomb.transform.localPosition.z);
                }
                else if (thisRigidBody.velocity.x - parentVelocity.x < -0.1)
                {
                    this.gameObject.GetComponent <SpriteRenderer>().flipX = true;
                    bomb.transform.localPosition = new Vector3(-1f * Mathf.Abs(bomb.transform.localPosition.x), bomb.transform.localPosition.y, bomb.transform.localPosition.z);
                }
            }
            else
            {
                animator.SetFloat("horizontalSpeed", Mathf.Abs(thisRigidBody.velocity.x));
                //Flip the sprite
                if (thisRigidBody.velocity.x > 0.1)
                {
                    this.gameObject.GetComponent <SpriteRenderer>().flipX = false;
                    bomb.transform.localPosition = new Vector3(Mathf.Abs(bomb.transform.localPosition.x), bomb.transform.localPosition.y, bomb.transform.localPosition.z);
                }
                else if (thisRigidBody.velocity.x < -0.1)
                {
                    this.gameObject.GetComponent <SpriteRenderer>().flipX = true;
                    bomb.transform.localPosition = new Vector3(-1f * Mathf.Abs(bomb.transform.localPosition.x), bomb.transform.localPosition.y, bomb.transform.localPosition.z);
                }
            }


            //Explode if game is complete
            float completion = MinigameController.Instance.GetPercentTimePassed();

            if (completion >= 1)
            {
                bombAnimator.SetTrigger("explode");
                //Stop bomb particles
                bombAnimator.gameObject.GetComponent <ParticleSystem>().Stop();
                bombAnimator.gameObject.GetComponent <ParticleSystem>().Clear();
                //Scale the bomb to make the exlosion big
                bombTransform.localScale = new Vector2(2, 2);
            }
        }
        void FixedUpdate()
        {
            float moveHorizontal = MinigameInputHelper.GetHorizontalAxis(player_num);
            float moveVertical   = MinigameInputHelper.GetVerticalAxis(player_num);

            Vector3 movement = Vector3.Normalize(new Vector3(moveHorizontal, 0.0f, moveVertical));

            anim.SetFloat("Speed", 0);


            //when tongue is not moving, you can run and jump freely
            // if (!tongue.moving)
            {
                tonguePos = transform.position;

                if (movement.magnitude > 0.1)
                {
                    rb.MovePosition(transform.position + movement * horizontalSpeed);

                    Quaternion q = Quaternion.LookRotation(-1 * movement, Vector3.up);
                    if (!anim.GetCurrentAnimatorStateInfo(0).IsName("Ghost_Armature|TongueOut"))
                    {
                        rb.MoveRotation(q);
                    }
                    facingDirection = Vector3.Normalize(movement);
                    anim.SetFloat("Speed", moveHorizontal * moveHorizontal + moveVertical * moveVertical);
                }
                if (grounded && MinigameInputHelper.IsButton1Held(player_num))
                {
                    anim.SetBool("Grounded", false);
                    anim.SetTrigger("Jump");
                    audio.PlayOneShot(jumpingSound, 1.0F);
                    grounded = false;
                    rb.AddForce(Vector3.up * jumpPower);
                }
                else
                {
                    anim.ResetTrigger("Jump");
                }
                if (!grounded && rb.transform.position.y < .01)
                {
                    grounded = true;
                    anim.SetBool("Grounded", true);
                }
                if (!grounded)
                {
                    rb.AddForce(Vector3.down * fallPower);
                }
                if (MinigameInputHelper.IsButton2Held(player_num) && !tongue.moving)
                {
                    anim.SetTrigger("Tongue");
                    audio.PlayOneShot(tongueSound, 1.0F);

                    tongue.setDestination(transform.position + facingDirection * tongueDistance);
                }
                else
                {
                    anim.ResetTrigger("Tongue");
                }
            }

            //       //move fruits being eaten closer to the mouth
            //       foreach(GameObject fruit in eating)
            //       {
            //           if (fruit != null)
            //           {
            //               Vector3 newPos = Vector3.Lerp(fruit.transform.position, mouth.position, eatingSpeed * Time.deltaTime);
            //               fruit.transform.position = new Vector3(newPos.x, fruit.transform.position.y, newPos.z);
            //           }
            //       }
        }