Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (playerState.IsEnabled())
        {
            float moveSpeed = maxMoveSpeed;
            if (slowed)
            {
                moveSpeed /= 2;
            }
            playerJump = this.GetComponentInChildren <PlayerJump>();
            Vector3 newVelocity = rigid.velocity;

            //Horizontal
            float vel = Input.GetAxis("Horizontal") * moveSpeed;
            if (Mathf.RoundToInt(vel) != 0)
            {
                newVelocity.x += vel;
                if (vel > 0 && newVelocity.x > moveSpeed)
                {
                    newVelocity.x = moveSpeed;
                }
                else if (vel < 0 && newVelocity.x < -1 * moveSpeed)
                {
                    newVelocity.x = -moveSpeed;
                }
                rigid.velocity = newVelocity;
            }
            else if ((playerJump.IsGrounded() && !playerState.IsFlying()) || (!playerJump.IsGrounded() && playerJump.IsStillJumped()))
            {
                rigid.velocity = new Vector3(0, rigid.velocity.y);
            }
        }
    }
Пример #2
0
 private void Update()
 {
     if (pj.IsGrounded())
     {
         canDoubleJump = true;
         jumps         = 0;
     }
     PuloDuplo();
 }
Пример #3
0
 // Update is called once per frame
 void Update()
 {
     print("Update");
     print(playerJump.IsGrounded());
     if (playerJump.IsGrounded())
     {
         //get movement input
         m_v3MoveDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, 0).normalized;
     }
 }
Пример #4
0
 private void Update()
 {
     if (Input.GetButtonDown("Jump"))
     {
         if (can.GetPlayerN() == gm.whoPLay && jump.IsGrounded())
         {
             if (caughtColor.GetColor() >= 0 && caughtColor.GetSprite() != null)
             {
                 if (aux < listCores.Count)
                 {
                     if (caughtColor.GetColor() == listCores[aux])
                     {
                         aux++;
                         gm.ScoreUp();
                         Debug.Log(aux);
                     }
                     else
                     {
                         lose = true;
                     }
                 }
                 else if (aux == listCores.Count && jump.IsGrounded())
                 {
                     if (coresAdd < quantCoresAdd)
                     {
                         gm.AddCor(caughtColor.GetColor(), caughtColor.GetSprite());
                         aux++;
                         coresAdd++;
                         Debug.Log(aux);
                     }
                 }
             }
         }
     }
     else if (coresAdd == quantCoresAdd && jump.IsGrounded())
     {
         aux                = 0;
         coresAdd           = 0;
         gm.whoPLay         = nextPlayer;
         transform.position = posiInicial.position;
     }
     if (lose)
     {
         if (multiplayer)
         {
             Destroy(this.gameObject);
         }
         else
         {
             Time.timeScale = 0f;
             scorePanel.SetActive(true);
         }
     }
 }
Пример #5
0
 IEnumerator RunningSound()
 {
     while (true)
     {
         if (isEnabled && IsRunning() && playerJump.IsGrounded())
         {
             AudioManager.instance.playSamusRunning();
         }
         yield return(new WaitForEndOfFrame());
     }
 }
Пример #6
0
    public void Move(Vector3 direction, bool running)
    {
        var speed  = movementSpeed;
        var canRun = running && CanRun();

        if (isCrouching)
        {
            speed *= crouchingMultiplier;
        }
        else if (canRun && playerStamina.HasStamina())
        {
            speed *= runningMultiplier;
        }

        float verticalVelocity = rigidBody.velocity.y;
        var   velocity         = direction * speed * Time.deltaTime;

        velocity.y         = verticalVelocity;
        rigidBody.velocity = velocity;

        targetRotation = Quaternion.LookRotation(direction);

        if (playerJump.IsGrounded())
        {
            AudioManager.Instance.PlayFootsteps(transform.position, canRun && playerStamina.HasStamina());
        }

        if (canRun)
        {
            playerStamina.DecreaseStamina();
        }
        else
        {
            playerStamina.IncreaseStamina();
        }
    }
Пример #7
0
    IEnumerator ResetFlying()
    {
        while (true)
        {
            if (flying)
            {
                playerJump = GetComponentInChildren <PlayerJump>();
                yield return(new WaitForSeconds(0.2f));

                while (!playerJump.IsGrounded())
                {
                    yield return(new WaitForFixedUpdate());
                }
                flying = false;
            }
            yield return(new WaitForFixedUpdate());
        }
    }
Пример #8
0
    // Update is called once per frame
    //TODO update states so that you can only morphball in mid air
    void LateUpdate()
    {
        if (isEnabled)
        {
            playerJump = GetComponentInChildren <PlayerJump>();
            if (standing && Input.GetKeyDown(KeyCode.DownArrow) && playerInventory.HasMorphBall() && (playerJump.IsGrounded() || playerInventory.HasTuckBall()))
            {
                Standing.SetActive(false);
                Morphed.SetActive(true);
                standing = false;
            }

            if (!standing && (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.X)))
            {
                if (!Physics.Raycast(transform.GetChild(1).transform.position, Vector3.up, 0.75f))
                {
                    Standing.SetActive(true);
                    Morphed.SetActive(false);
                    StartCoroutine(SetStanding());
                }
            }

            shooting = Input.GetKeyDown(KeyCode.Z);
        }

        running = rigid.velocity.x != 0;
    }
Пример #9
0
    // Update is called once per frame
    void LateUpdate()
    {
        if (playerState.IsShooting())
        {
            timeSinceLastShot = 0f;
        }
        else
        {
            timeSinceLastShot += Time.deltaTime;
        }
        if (playerState.IsStanding()) //Standing Form
        {
            morphed = false;
            if (playerJump.IsGrounded()) //On Ground
            {
                shotInAir = false;
                spinMove  = false;
                running   = playerState.IsRunning();
                if (playerDirection.IsHoldingUp()) //Is holding up key
                {
                    playerState.SetLookingUp(true);
                }
                else //isnt holding up key
                {
                    playerState.SetLookingUp(false);
                }
            }
            else //In Air
            {
                running = false;
                if (playerState.IsShooting()) //is shooting
                {
                    shotInAir = true;
                }
                if (shotInAir)
                {
                    if (playerDirection.IsHoldingUp()) //is holding up key
                    {
                        playerState.SetLookingUp(true);
                        if (playerState.IsMissleOn())
                        {
                            spriteRenderer.sprite = missleJumpShootUp;
                        }
                        else
                        {
                            spriteRenderer.sprite = jumpShootUp;
                        }
                    }
                    else //isnt holding up key
                    {
                        playerState.SetLookingUp(false);

                        if (playerState.IsMissleOn())
                        {
                            spriteRenderer.sprite = missleJumpShootRight;
                        }
                        else
                        {
                            spriteRenderer.sprite = jumpShootRight;
                        }
                    }
                    spinMove = false;
                }
                else if (playerJump.IsStillJumped()) //jumped from stationary
                {
                    if (playerState.IsMissleOn())
                    {
                        spriteRenderer.sprite = missleStillJumpRight;
                    }
                    else
                    {
                        spriteRenderer.sprite = stillJumpRight;
                    }

                    spinMove = false;
                }
                else if (playerJump.IsMoveJumped()) //is beyblade
                {
                    spinMove = true;
                }
            }
        }
        else //morph ball
        {
            morphed = true;
        }
    }