示例#1
0
 public void Slip(bool f)
 {
     if (f)
     {
         state = FerretState.Slipping;
         DropItem();
     }
     else
     {
         state = FerretState.Idle;
     }
 }
    // Update is called once per frame
    void Update()
    {
        //print(f_stamina);

        //IF YOU HAVE STAMINA YOU CAN SPRINT
        if (f_stamina > 0)
        {
            b_cansprint = true;
        }
        else
        {
            b_cansprint = false;
        }

        //Delay stamina Recovery on finishing sprint.
        if (f_stamina < MAX_STAMINA && !b_sprinting && !b_recoverydelay && !b_recovering)
        {
            b_recoverydelay = true;
        }

        //STAMINA DECAY
        if (b_sprinting)
        {
            //Stamina Decay
            f_stamina -= f_staminadecay * Time.deltaTime /** 10*/;

            if (f_stamina <= 0.0f)
            {
                f_stamina   = 0.0f;
                b_cansprint = false;
            }
        }

        // Recovery Delay TIMER
        if (b_recoverydelay && f_staminadelay > 0)
        {
            f_staminadelay -= Time.deltaTime;
        }
        // BEGIN RECOVERING
        if (f_staminadelay <= 0)
        {
            f_staminadelay  = 3.0f;
            b_recoverydelay = false;
            b_recovering    = true;
        }

        if (b_recovering)
        {
            f_stamina += f_staminarecov * Time.deltaTime * 5;

            if (f_stamina >= MAX_STAMINA)
            {
                f_stamina = MAX_STAMINA;
            }
        }


        //SPRINT
        if (Input.GetKey(KeyCode.LeftShift) && b_cansprint && f_stamina > 0)
        {
            f_sprintmult = 2.5f;
            b_sprinting  = true;
            b_recovering = false;
        }
        else
        {
            f_sprintmult = 1.0f;
            b_sprinting  = false;
        }

        //TEMPORARY UI STUFF
        textpro.text = f_stamina.ToString("#");

        //Movement
        if (e_currstate != FerretState.Slipping)
        {
            if (Input.GetKey(KeyCode.W))
            {
                c_control.Move(transform.forward * f_speed * Time.deltaTime * f_sprintmult);
                i_lastKey = 0;
                //c_control.Move(new Vector3(0, 0, i_speed * Time.deltaTime));
            }
            else if (Input.GetKey(KeyCode.S))
            {
                c_control.Move(transform.forward * -f_speed * Time.deltaTime * f_sprintmult);
                i_lastKey = 1;
            }

            if (Input.GetKey(KeyCode.D))
            {
                c_control.Move(transform.right * f_speed * Time.deltaTime * f_sprintmult);
                i_lastKey = 2;
            }
            else if (Input.GetKey(KeyCode.A))
            {
                c_control.Move(transform.right * -f_speed * Time.deltaTime * f_sprintmult);
                i_lastKey = 3;
            }
        }
        else
        {
            //curSpill needs to reference something
            if (h_curSpill != null)
            {
                if (h_curSpill.getSurface() == true)
                {
                    Debug.Log("SLIP");
                    switch (i_lastKey)
                    {
                    case 0:
                        c_control.Move(transform.forward * f_speed * Time.deltaTime * h_curSpill.getSpeed());
                        break;

                    case 1:
                        c_control.Move(transform.forward * -f_speed * Time.deltaTime * h_curSpill.getSpeed());
                        break;

                    case 2:
                        c_control.Move(transform.right * f_speed * Time.deltaTime * h_curSpill.getSpeed());
                        break;

                    case 3:
                        c_control.Move(transform.right * -f_speed * Time.deltaTime * h_curSpill.getSpeed());
                        break;
                    }
                }
            }
        }


        //Jumping
        if (Input.GetKey(KeyCode.Space) && c_control.isGrounded == true)
        {
            f_jumptimer = f_jumptime;
            //c_control.Move(new Vector3(0, i_jumpspeed * Time.deltaTime, 0));
            e_currstate = FerretState.Jumping;
        }
        else if (e_currstate == FerretState.Jumping)
        {
            f_jumptimer -= Time.deltaTime;
            if (f_jumptimer <= 0)
            {
                e_currstate = FerretState.Idle;
            }
        }


        //Mouse Player movement
        transform.Rotate(0, Input.GetAxis("Mouse X") * 1.1f, 0);


        //Checks if absolute angel is between 35 & 0 degrees OR 350(-10) & 360(0) degrees, this is the spot we WANT the camera.
        if (obj_cam.transform.eulerAngles.x <= 35.0f && obj_cam.transform.eulerAngles.x >= 0.0f ||
            obj_cam.transform.eulerAngles.x >= 350.0f && obj_cam.transform.eulerAngles.x <= 360.0f)
        {
            obj_cam.transform.Rotate(Input.GetAxis("Mouse Y") * -0.5f, 0, 0); //The negative multiplier is just so that the camera moves nicer
            if (Input.GetAxis("Mouse Y") != 0.0f)
            {
                f_mouseyprev = (Input.GetAxis("Mouse Y") * -0.5f); //So long as the mouse had previously moved, save the axis it moved for the corrector.
            }
        }
        //To prevent the camera from locking, this checks directly after the sweetspot for 10 units
        //This is done specifically to account for negative angles.
        else if (obj_cam.transform.eulerAngles.x >= 35.0f && obj_cam.transform.eulerAngles.x <= 45.0f && f_mouseyprev <= Input.GetAxis("Mouse Y") ||
                 obj_cam.transform.eulerAngles.x <= 350.0f && obj_cam.transform.eulerAngles.x >= 340.0f && f_mouseyprev >= Input.GetAxis("Mouse Y"))
        {
            obj_cam.transform.Rotate(Input.GetAxis("Mouse Y") * -0.5f, 0, 0);
        }


        if (Input.GetKeyDown(KeyCode.Tab))
        {
            c_command = new GotoMainMenuCommand();
            c_command.Execute(c_command, obj_player);
        }

        switch (e_currstate)
        {
        case FerretState.Idle:
            c_control.Move(new Vector3(0, -f_gravity * Time.deltaTime, 0));
            break;

        case FerretState.Jumping:
            c_control.Move(new Vector3(0, f_jumpspeed * Time.deltaTime, 0));
            break;
        }
    }
示例#3
0
    // Update is called once per frame
    void Update()
    {
        float stamina_start = stamina;

        if (can_climb && Input.GetButton("Climb"))
        {
            state = FerretState.Climbing;
        }
        else if (state == FerretState.Climbing)
        {
            state = FerretState.Idle;
        }

        float sprint = Input.GetAxis("Sprint");

        bool hit_obj    = false;
        bool moved      = false;
        bool butt_moved = false;

        for (int c = 0; c < origins.Length; c++)
        {
            origins[c] = trail[c].position;
        }

        float dt = Time.deltaTime;

        float joystick_x = Input.GetAxis("Horizontal");
        float joystick_y = Input.GetAxis("Vertical");

        float magnitude = new Vector2(joystick_x, joystick_y).magnitude;

        Vector3             movement = new Vector3();
        CharacterController cc       = GetComponent <CharacterController>();

        if (can_climb)
        {
            climb_timer = (climb_timer + dt > LookTime) ? LookTime : climb_timer + dt;
        }
        else
        {
            climb_timer = (climb_timer - dt < 0.0f) ? 0.0f : climb_timer - dt;
        }

        Vector3 dir;

        switch (state)
        {
        case FerretState.Climbing:
            movement += Vector3.up * PLAYER_SPEED * dt;
            break;

        case FerretState.Slipping:
            dir = Quaternion.Euler(0.0f, player_orientation, 0.0f) * Vector3.forward;
            ApplyGravity(ref movement, dt);
            movement += (dir * PLAYER_SPEED) * dt;

            break;

        default:
            if (on_ground && Input.GetButton("Jump") && stamina > 0.0f)
            {
                Jump(PLAYER_JUMP);

                stamina -= JumpCost;
            }

            ApplyGravity(ref movement, dt);

            if (magnitude > 0.01f)
            {
                float theta = (Mathf.Atan2(joystick_x, joystick_y) * Mathf.Rad2Deg);

                if (Cam != null)
                {
                    theta += Cam.GetTheta();
                }

                if (Mathf.Abs(theta - player_orientation) > Mathf.Abs((theta + 360.0f) - player_orientation))
                {
                    theta += 360.0f;
                }
                else if (Mathf.Abs(theta - player_orientation) > Mathf.Abs((theta - 360.0f) - player_orientation))
                {
                    theta -= 360.0f;
                }

                float t_change = 0.0f;
                if (theta != player_orientation)
                {
                    t_change = (theta - player_orientation) / Mathf.Abs(theta - player_orientation);
                }

                player_orientation += t_change * ROT_SPEED * dt;

                if (player_orientation > 360.0f)
                {
                    player_orientation -= 360.0f;
                }
                else if (player_orientation < -360.0f)
                {
                    player_orientation += 360.0f;
                }

                transform.rotation = Quaternion.Euler(0.0f, player_orientation, 0.0f) * handle_rot;

                dir = Quaternion.Euler(0.0f, player_orientation, 0.0f) * Vector3.forward;

                Vector3 input_motion = (dir * PLAYER_SPEED) * dt;

                if (on_ground && sprint > 0.0f && stamina > 0.0f)
                {
                    input_motion *= SprintModifier;

                    stamina -= SprintCost * dt;
                }

                movement += input_motion;

                if (handle != null)
                {
                    handle.rotation = transform.rotation;
                }
            }
            break;
        }

        if (cc != null)
        {
            Vector3 start_pos = cc.transform.position;

            CollisionFlags hits = cc.Move(movement);

            Vector3 end_pos = cc.transform.position;

            if (hits.HasFlag(CollisionFlags.Sides))
            {
                //Debug.Log("HOI!!!");
                hit_obj = true;
            }
            if (hits.HasFlag(CollisionFlags.Below))
            {
                //frwd_up_vel = Vector3.zero;
                on_ground     = true;
                frwd_up_vel.y = Physics.gravity.y / 2.0f;

                Vector3 b_start = trail[trail.Length - 1].transform.position;
                ApplyTailGrav(dt);
                Vector3 b_end = trail[trail.Length - 1].transform.position;

                if (!Mathf.Approximately((b_end - b_start).magnitude, 0.0f))
                {
                    butt_moved = true;
                }
            }
            else
            {
                on_ground = false;
            }

            if (!Mathf.Approximately((end_pos - start_pos).magnitude, 0.0f))
            {
                moved = true;
            }
        }
        else
        {
            transform.position += movement;
        }

        if (handle != null)
        {
            handle.position = transform.position;
        }

        if (!hit_obj && (moved || butt_moved))
        {
            AdjustTail();
        }

        /*
         * if (butt != null)
         * {
         *      Vector3 front_to_back = transform.position - butt.transform.position;
         *
         *      Vector3 back_move = new Vector3();
         *
         *      if (front_to_back.magnitude > 5.0f)
         *      {
         *              butt.transform.rotation = Quaternion.LookRotation(front_to_back.normalized, Vector3.up);
         *
         *              back_move += front_to_back.normalized * PLAYER_SPEED * dt;
         *      }
         *
         *      back_move += Physics.gravity * dt;
         *      butt.Move(back_move);
         *
         *      if (back_handle != null)
         *      {
         *              back_handle.position = butt.transform.position;
         *              //back_handle.transform.rotation = butt.transform.rotation;
         *      }
         * }
         */

        // Stamina
        if (Mathf.Approximately(stamina_start - stamina, 0.0f))
        {
            if (srt > 0.0f)
            {
                srt -= dt;
            }
            else
            {
                stamina += StaminaRecovery * dt;
                if (stamina > MaxStamina)
                {
                    stamina = MaxStamina;
                }
            }
        }
        else
        {
            srt = StaminaRecoveryTime;
        }

        StaminaDisplay.text = stamina.ToString();
    }