Example #1
0
    private void initializeVariables()
    {
        characterController.stopJumping();
        isSpaceJumping                      = false;
        timeHasNotBeenBreathing             = timeBetweenDamageWhenNotBreathing;
        timeHasBeenInSpace                  = 0f;
        centerToExtremesDistance            = (animationBigPappada.GetComponent <Collider>().bounds.size.z / 2f) + extraSafeDistanceFromEnemies;
        isInvulnerable                      = false;
        GetComponent <Rigidbody>().velocity = new Vector3(0f, 0f, 0f);

        lineRenderer = GetComponent <LineRenderer> ();

        //Initialize the animator
        if (bpAnimator != null)
        {
            bpAnimator.SetBool("isJumping", false);
            bpAnimator.SetBool("isSpaceJumping", false);
            bpAnimator.SetBool("isGoingUp", false);
            bpAnimator.SetBool("isChargingSpaceJumping", false);
            bpAnimator.SetBool("isWalking", false);
            bpAnimator.SetBool("isDerribado", false);
        }

        isSpaceJumping = false;
        GameManager.mainCamera.GetComponent <CameraFollowingPlayer> ().returnOriginalZ();
        HideArrow();
        isFinishedSpaceJump = true;
        flyParticles.Stop();
        body.setIsGettingOutOfOrbit(false);
        canDrownInSpace = true;

        if (isDematerialized)
        {
            StartCoroutine(rematerialize());
        }
    }
    void Update()
    {
        //We wait some time to avoid jumping when we select to start the game
        timeSinceGameReenabled += Time.deltaTime;
        if (GameManager.isGameEnded || GameManager.isGamePaused)
        {
            timeSinceGameReenabled = 0f;
        }

        if (!GameManager.isGameEnded && isEnabled && timeSinceGameReenabled > 0.2f && !character.getIsFallingDown())
        {
            //MOVEMENT BUTTON
            if (!attackController.isDoingDash())
            {
                if (Input.GetAxis("Horizontal") != 0f)
                {
                    if (isSpaceJumpCharged)
                    {
                        character.MoveArrow(Input.GetAxisRaw("Horizontal"), Input.GetAxis("Vertical"));
                    }
                    else if (isCharacterAllowedToMove())
                    {
                        ResetJumping();
                        if (attackController.isDoingAnyAttack())
                        {
                            character.Move(Input.GetAxisRaw("Horizontal") / 2f);
                        }
                        else
                        {
                            character.Move(Input.GetAxisRaw("Horizontal"));
                        }
                    }
                    else
                    {
                        character.StopMove();
                    }
                }
                else
                {
                    character.StopMove();
                }
            }

            //NORMAL ATTACK BUTTON

            /*if(character.getIsJumping() && !character.getIsSpaceJumping()){
             *      if (Input.GetButtonDown("Normal Attack")) {
             *              attackController.doAttack(onAirAttack,true);
             *      }
             * }else{*/
            if (Input.GetButtonDown("Normal Attack") && Input.GetAxisRaw("Vertical") > 0.5f && isCharacterAllowedToDoNormalAttack())
            {
                attackController.doAttack(upNormalAttack, true);
            }
            if (Input.GetButtonDown("Normal Attack") && isCharacterAllowedToDoNormalAttack())
            {
                attackController.doAttack(sidesNormalAttack, true);
            }
            //}

            //SPECIAL ATTACK BUTTON
            KameAttackDirectionable kameDir = attackController.getAttack(sidesSpecialAttack) as KameAttackDirectionable;
            if (isCharacterAllowedToDoSpecialAttack())
            {
                if (Input.GetButtonDown("Special Attack"))
                {
                    if (kameDir.isAttackFinished())
                    {
                        attackController.doAttack(sidesSpecialAttack, true);
                    }

                    kameDir.Detonate();
                }
                else if (Input.GetButtonUp("Special Attack"))
                {
                    kameDir.buttonReleased();
                }
                else if (kameDir.canReceiveInputDirections())
                {
                    kameDir.receiveInputDirections(Input.GetAxisRaw("Vertical"), Input.GetAxisRaw("Horizontal"));
                }

                /*if(Mathf.Abs(Input.GetAxisRaw("Vertical"))>Mathf.Abs(Input.GetAxisRaw("Horizontal"))){
                 *      if(Input.GetAxis("Vertical")>0.5f){
                 *              attackController.doAttack(upSpecialAttack,true);
                 *      }else if(Input.GetAxis("Vertical")<-0.5f){
                 *              attackController.doAttack(downSpecialAttack,true);
                 *      }
                 * }else{
                 *      attackController.doAttack(sidesSpecialAttack,true);
                 * }*/
            }

            //JUMP BUTTON
            if (Input.GetButtonDown("Jump") && isSpaceJumpCharged)
            {
                ResetJumping();
                character.SpaceJump();
            }

            if (Input.GetButtonDown("Jump") && (Input.GetAxisRaw("Vertical") < -0.5f || isSpaceJumpCharging))
            {
                if (isCharacterAllowedToSpaceJump())
                {
                    isSpaceJumpCharged = true; character.ChargeJump();
                }
            }
            else if (Input.GetButtonDown("Jump") && isCharacterAllowedToJump())
            {
                character.Jump();
            }

            if (Input.GetButtonDown("Jump"))
            {
                if (character.getIsSpaceJumping())
                {
                    SpaceGravityBody body = GetComponent <SpaceGravityBody>();
                    if (body.getIsOrbitingAroundPlanet())
                    {
                        body.setIsGettingOutOfOrbit(true);
                    }
                }
            }

            if (Input.GetButtonDown("Block"))
            {
                Interactuable    entity = EntityManager.getClosestInteractuable();
                SpaceGravityBody body   = GetComponent <SpaceGravityBody>();
                if (isSpaceJumpCharged)
                {
                    CancelChargingSpaceJump();
                }
                else if (character.getIsSpaceJumping() && body.getIsOrbitingAroundPlanet())
                {
                    body.setIsFallingIntoPlanet(true);
                }
                else if (entity != null)
                {
                    entity.doInteractAction();
                }
                else if (Input.GetAxis("Vertical") < -0.5f && isCharacterAllowedToBlock())
                {
                    attackController.doBlock();
                }
                else if (isCharacterAllowedToDash())
                {
                    attackController.doDash();
                }
            }

            if (Input.GetButtonUp("PauseMenu"))
            {
                if (!GameManager.isGameEnded && !GameManager.playerController.getIsSpaceJumping() && !GameManager.playerController.getIsChargingSpaceJump())
                {
                    if (!GameManager.isGamePaused)
                    {
                        GameManager.pauseGame();
                        GUIManager.activatePauseMenu();
                    }
                    else
                    {
                        GameManager.unPauseGame();
                        GUIManager.deactivatePauseMenu();
                    }
                }
            }
        }
        else if (!isEnabled)
        {
            attackController.interruptActualAttacks();
            if (Input.GetButtonUp("Jump"))
            {
                //If it's not enabled, interrupt any ongoing cinematic
                Planet actualPlanet = GameManager.playerSpaceBody.getClosestPlanet();
                if (actualPlanet != null && actualPlanet.isPlanetCorrupted())
                {
                    PlanetEventsManager pem = (actualPlanet as PlanetCorrupted).getPlanetEventsManager();
                    if (pem != null)
                    {
                        pem.interrupt();
                    }
                }
            }
        }
    }