Exemplo n.º 1
0
    // Update is called once per frame
    protected virtual void Update()
    {
        if (freeze_player)
        {
            rb.velocity = Vector3.zero;
            return;
        }
        // move the ball to the player if the player has the ball
        // move ball to player
        if (has_ball)
        {
            if (ball.transform.parent != null)
            {
                ball.transform.localPosition = Vector3.zero;
                ball.GetComponent <Rigidbody2D>().velocity = Vector2.zero;
            }
            Vector3 vel = rb.velocity;
            if (!charging)
            {
                Vector2 input_value_left;
                float   horiz_left = 0, vert_left = 0;
                if (is_keyboard)
                {
                    if (current_keyboard == keyboard_id)
                    {
                        if (Input.GetKey("w"))
                        {
                            vert_left = 1;
                        }
                        else if (Input.GetKey("s"))
                        {
                            vert_left = -1;
                        }
                        if (Input.GetKey("d"))
                        {
                            horiz_left = 1;
                        }
                        else if (Input.GetKey("a"))
                        {
                            horiz_left = -1;
                        }
                    }
                }
                else
                {
                    if (!is_dummy)
                    {
                        input_value_left = gp.leftStick.ReadValue();
                        horiz_left       = input_value_left.x;
                        vert_left        = input_value_left.y;
                        if (Mathf.Abs(horiz_left) > deadzone ||
                            Mathf.Abs(vert_left) > deadzone)
                        {
                            direction = angle(horiz_left, vert_left);                             // + (float)Math.PI;
                        }
                    }
                }
            }
        }

        // wall jump slide
        if (wall_jump_on && !grounded && rb.velocity.y < -.1f && wall_jump_script.touching_ground())
        {
            if (rb.velocity.y < wall_jump_slide)
            {
                rb.velocity = Vector2.up * wall_jump_slide;
            }
        }

        // passing pointer
        if (has_ball && !charging && !is_dummy)
        {
            // quick throw direction
            // if (pointer.activeSelf == false) Debug.Log(gameObject.name + ": POINTER IS ACTIVE!!!");

            /*
             * pointer.SetActive(true);
             *          float diffx, diffy;
             *          diffx = transform.position.x - _teammate.position.x;
             *          diffy = transform.position.y - _teammate.position.y;
             *          pointer.transform.localEulerAngles = Vector3.forward * ((angle(diffx,diffy)*Mathf.Rad2Deg) + 135.0f);
             */

            // Debug.Log("Angle: " + pointer.transform.localEulerAngles.z);
            // pointer.transform.localEulerAngles = new Vector3(0, 0, (direction) * Mathf.Rad2Deg + 135.0f + 180.0f);
            if (_teammate != null && _teammate.gameObject.activeSelf)
            {
                List <Vector3> projection = GetComponent <Projectile_Projection>().quick_prediction(transform.position, _teammate.position);
                pass_indicator(projection);
            }
            //make_projection(_teammate.position);
        }
        else
        {
            // if (pointer.activeSelf == true) Debug.Log(gameObject.name + ": POINTER IS OFF!!!");
            pointer.SetActive(false);
        }

        if (is_dummy)
        {
            return;
        }

        if (is_keyboard)
        {
            if (Input.GetKey("1"))
            {
                current_keyboard = 1;
            }
            else if (Input.GetKey("2"))
            {
                current_keyboard = 2;
            }
            else if (Input.GetKey("3"))
            {
                current_keyboard = 3;
            }
            else if (Input.GetKey("4"))
            {
                current_keyboard = 4;
            }
        }

        if (gp == null && !is_keyboard)
        {
            return;
        }

        // if stunned, do nothing
        if (stunned)
        {
            return;
        }

        // reduce movespeed while charging
        move_spd = (charging) ? max_spd / 2 : max_spd;

        // get input
        float   horiz = 0, vert = 0;
        Vector2 input_value;

        if (!is_keyboard)
        {
            if (gp.dpad.left.isPressed)
            {
                vox.PlayVoice(0);
            }
            else if (gp.dpad.right.isPressed)
            {
                vox.PlayVoice(1);
            }
            else if (gp.dpad.up.isPressed)
            {
                vox.PlayVoice(2);
            }
            else if (gp.dpad.down.isPressed)
            {
                vox.PlayVoice(3);
            }

            input_value = gp.leftStick.ReadValue();
            horiz       = input_value.x;
            vert        = input_value.y;
        }
        horiz        = (Mathf.Abs(horiz) > deadzone) ? horiz : 0;
        vert         = (Mathf.Abs(vert) > deadzone * 4) ? vert : 0;
        facing_angle = angle(horiz, vert);

        // get keyboard input
        if (is_keyboard && current_keyboard == keyboard_id)
        {
            if (Input.GetKey("w"))
            {
                vert = 1;
            }
            else if (Input.GetKey("s"))
            {
                vert = -1;
            }
            if (Input.GetKey("d"))
            {
                horiz = 1;
            }
            else if (Input.GetKey("a"))
            {
                horiz = -1;
            }
        }

        // MOAR PARTICLES!!!
        float horiz_check = (horiz > 0) ? 1 : -1;

        if (Mathf.Abs(horiz) >= .8f && horiz_check != last_dir)
        {
            if (grounded && !charging && !stunned)
            {
                last_dir = horiz_check;
                StartCoroutine(run_puffs(.05f, last_dir));
            }
        }
        if (horiz == 0)
        {
            last_dir = 0;
        }

        // tackle
        if (tackle_input() && false)
        {
            tackle(horiz, vert);
        }

        // don't allow other actions to interrupt
        if (tackling)
        {
            return;
        }

        // move
        apply_input(horiz, vert);

        // test out dropdown (9 = Player, 10 = PlayerDropDown)
        if (vert < 0)
        {
            dropdown();
        }
        gameObject.layer = (dropdown_timer > 0) ? 10 : 9;
        dropdown_timer  -= Time.deltaTime;

        // apply special ability
        Vector2 special_input = new Vector2();

        if (!is_keyboard)
        {
            special_input = gp.leftStick.ReadValue();
            // THIS CODE ENABLES DASHING WITH FACE BUTTONS [facedash]

            /** /
             *
             * if (!has_ball)
             * {
             * if (gp.buttonWest.wasPressedThisFrame)
             * special_input = Vector3.left;
             * else if (gp.buttonNorth.wasPressedThisFrame)
             * special_input = Vector3.up;
             * else if (gp.buttonEast.wasPressedThisFrame)
             * special_input = Vector3.right;
             * else if (gp.buttonSouth.wasPressedThisFrame)
             * special_input = Vector3.down;
             * }
             *
             * /**/

            horiz = special_input.x;
            vert  = special_input.y;
            horiz = (Mathf.Abs(horiz) > deadzone) ? horiz : 0;
            vert  = (Mathf.Abs(vert) > deadzone) ? vert : 0;
        }
        else
        {
            if (keyboard_id == current_keyboard)
            {
                vert = horiz = 0;
                if (Input.GetKey("up"))
                {
                    vert = 1;
                }
                else if (Input.GetKey("down"))
                {
                    vert = -1;
                }
                if (Input.GetKey("right"))
                {
                    horiz = 1;
                }
                else if (Input.GetKey("left"))
                {
                    horiz = -1;
                }
            }
        }
        if (horiz == 0 && vert == 0)
        {
            horiz = _last_horiz;
            vert  = _last_vert;
        }
        else
        {
            _last_horiz = horiz;
            _last_vert  = vert;
        }
        if (!is_keyboard && gp.leftTrigger.wasPressedThisFrame)
        {
            apply_special(horiz, vert);
        }

        // check grounded statement
        grounded     = wiley_timer > 0;
        wiley_timer -= Time.deltaTime;
        // test out jumping

        if (is_keyboard && keyboard_id == current_keyboard && Input.GetKey("space"))
        {
            if (grounded)
            {
                jump();
            }
            else if (wall_jump_on && wall_jump_script.touching_ground())
            {
                wall_jump();
            }
        }
        if (!is_keyboard && gp.buttonSouth.wasPressedThisFrame)
        {
            if (grounded)
            {
                jump();
            }
            else if (wall_jump_on && wall_jump_script.touching_ground())
            {
                wall_jump();
            }
        }

        // countdown regrab time
        no_regrab -= Time.deltaTime;

        // move the ball with the player
        if (has_ball)
        {
            // move ball to player and zero velocity
            if (ball.transform.parent != null)
            {
                ball.transform.localPosition = Vector3.up * .25f;
            }
            ball.GetComponent <Rigidbody2D>().velocity = Vector2.zero;
            // get throwing input
            if (is_keyboard)
            {
                if (keyboard_id == current_keyboard)
                {
                    vert = horiz = 0;
                    if (Input.GetKey("up"))
                    {
                        vert = 1;
                    }
                    else if (Input.GetKey("down"))
                    {
                        vert = -1;
                    }
                    if (Input.GetKey("right"))
                    {
                        horiz = 1;
                    }
                    else if (Input.GetKey("left"))
                    {
                        horiz = -1;
                    }
                }
            }
            else
            {
                input_value = get_throwing_input();
                horiz       = input_value.x;
                vert        = input_value.y;
            }

            if (
                (Mathf.Abs(horiz) >= throw_deadzone ||
                 Mathf.Abs(vert) >= throw_deadzone) &&
                !charging
                )
            {
                charging = true;
                charge   = 0;
            }

            // quicktoss
            if (gp.buttonEast.wasPressedThisFrame)
            {
                quick_pass();
            }

            if (charging)
            {
                projectingQuick = false;
                // release ball
                if (Mathf.Abs(horiz) <= throw_deadzone &&
                    Mathf.Abs(vert) <= throw_deadzone
                    )
                {
                    clear_projection();
                    charge   = 0;
                    charging = false;
                }
                else
                {
                    charge   += charge_spd * Time.deltaTime;
                    charge    = (charge > charge_max) ? charge_max : charge;
                    direction = angle(last_horiz, last_vert);
                    // projection
                    List <Vector3> projection = GetComponent <Projectile_Projection>().get_prediction(transform.position, throw_force() * Time.fixedDeltaTime);
                    make_projection(projection, projection_dot);
                }
                // throw ball
                if (gp.rightTrigger.wasPressedThisFrame)
                {
                    throw_ball();
                }
            }
            else
            {
                // quickthrow projection
                if (gp.rightTrigger.wasPressedThisFrame)
                {
                    quick_toss();
                }
                projectingQuick = true;
            }
            if (horiz != 0 && vert != 0)
            {
                last_horiz = horiz;
                last_vert  = vert;
            }
        }
        else
        {
            clear_projection();
        }
    }