示例#1
0
 //Registering functions
 public static void registerPlayer(GameObject playerGO)
 {
     player           = playerGO;
     playerAnimator   = player.GetComponent <PlayerController> ().getAnimator();
     playerController = player.GetComponent <PlayerController> ();
     playerSpaceBody  = player.GetComponent <SpaceGravityBody> ();
     inputController  = player.GetComponent <InputController> ();
 }
示例#2
0
 void Start()
 {
     timeJumpPressed      = 0;
     character            = GetComponent <PlayerController>();
     characterGravityBody = character.GetComponent <SpaceGravityBody> ();
     attackController     = GetComponent <CharacterAttackController> ();
     WeaponManager wpm = WeaponManager.Instance;
 }
示例#3
0
    void Start()
    {
        body                = GetComponent <SpaceGravityBody> ();
        killable            = GetComponent <Killable> ();
        characterController = GetComponent <CharacterController> ();
        attackController    = GetComponent <CharacterAttackController> ();
        GameObject attack = GameObject.Find("skillAttack");

        initializePlayerRotation();
        bpAnimator        = animationBigPappada.GetComponent <Animator>();
        pappadaC          = pappada.GetComponent <PappadaController> ();
        flyParticles      = flyingParticles.GetComponent <ParticleSystem> ();
        getHurtBigPappada = GameObject.Instantiate(getHurtBigPappadaPrefab) as GameObject;
        initializeVariables();
        StartCoroutine("resetWeaponTrail");
    }
 void Start()
 {
     body = GetComponent<SpaceGravityBody> ();
     killable = GetComponent<Killable> ();
     characterController = GetComponent<CharacterController> ();
     attackController = GetComponent<CharacterAttackController> ();
     GameObject attack = GameObject.Find("skillAttack");
     initializePlayerRotation ();
     bpAnimator = animationBigPappada.GetComponent<Animator>();
     pappadaC = pappada.GetComponent<PappadaController> ();
     flyParticles = flyingParticles.GetComponent<ParticleSystem> ();
     getHurtBigPappada = GameObject.Instantiate (getHurtBigPappadaPrefab) as GameObject;
     initializeVariables ();
     StartCoroutine ("resetWeaponTrail");
 }
示例#5
0
    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();
                    }
                }
            }
        }
    }
 //Registering functions
 public static void registerPlayer(GameObject playerGO)
 {
     player = playerGO;
     playerAnimator = player.GetComponent<PlayerController> ().getAnimator ();
     playerController = player.GetComponent<PlayerController> ();
     playerSpaceBody = player.GetComponent<SpaceGravityBody> ();
     inputController = player.GetComponent<InputController> ();
 }
示例#7
0
    private bool spaceAttract(Transform objectToAttract, out float distance, bool applyForce, bool hasToChangeFacing, float gravityMultiplyier)
    {
        //Only attract the body to the planet if it is close enough.
        distance = Vector3.Distance(transform.position, objectToAttract.position);
        SpaceGravityBody body           = objectToAttract.GetComponent <SpaceGravityBody> ();
        float            forceMagnitude = body.GetComponent <Rigidbody>().velocity.magnitude;

        distance = distance - sphereRadius;

        if (distance <= gravityDistance)
        {
            Vector3 targetDir = (objectToAttract.position - transform.position);
            targetDir = new Vector3(targetDir.x, targetDir.y, 0f).normalized;

            Vector3 objectUp = objectToAttract.up;

            if (hasToChangeFacing)
            {
                objectToAttract.rotation = Quaternion.FromToRotation(objectUp, targetDir) * objectToAttract.rotation;
            }
            float forceToAdd = -Constants.GRAVITY_FORCE_OF_PLANETS * Time.deltaTime;

            bool hasToAddForce = true;

            float ratioDistance = distance / gravityDistance;
            if (body.getUsesSpaceGravity())
            {
                bool isOrbiting = body.getIsOrbitingAroundPlanet();
                if (!isOrbiting)
                {
                    float angle = Vector3.Angle(body.GetComponent <Rigidbody>().velocity, targetDir);
                    angle = Mathf.Abs(angle);
                    if (angle >= Constants.ANGLE_CAN_ENTER_ORBIT_START && angle <= Constants.ANGLE_CAN_ENTER_ORBIT_END)
                    {
                        if (ratioDistance >= Constants.PERCENTAGE_ATHMOSPHERE_CAN_ENTER_ORBIT_START && ratioDistance <= Constants.PERCENTAGE_ATHMOSPHERE_CAN_ENTER_ORBIT_END)
                        {
                            GameManager.mainCamera.GetComponent <CameraFollowingPlayer> ().followObjective(gameObject);
                            isOrbiting = true;
                            body.setIsOrbitingAroundPlanet(true);
                        }
                    }
                }

                if (ratioDistance <= Constants.PERCENTAGE_ATHMOSPHERE_CAN_ENTER_ORBIT_START)
                {
                    if (isOrbiting)
                    {
                        GameManager.mainCamera.GetComponent <CameraFollowingPlayer> ().unfollowObjective();
                    }
                    isOrbiting = false;
                    body.setIsOrbitingAroundPlanet(false);
                }
                if (isOrbiting && !body.getIsGettingOutOfOrbit())
                {
                    hasToAddForce = false;
                    //Meeec, no funciona be, sempre va a la dreta
                    //bool goesRight = Vector3.Angle(targetDir,-body.rigidbody.velocity) < Vector3.Angle(targetDir,body.rigidbody.velocity);
                    bool  goesRight = GameManager.player.GetComponent <PlayerController>().getIsLookingRight();
                    float angle2    = Util.getAngleFromVectorAToB(body.GetComponent <Rigidbody>().velocity, transform.position - body.transform.position);
                    goesRight = angle2 < 0f;


                    if (goesRight)
                    {
                        forceMagnitude *= -1;
                    }
                    else
                    {
                        targetDir *= -1f;
                    }
                    float forceRatio = Mathf.Cos(Mathf.Deg2Rad * Vector3.Angle(body.GetComponent <Rigidbody>().velocity, targetDir));

                    Vector3 forwardDirection = body.GetComponent <Rigidbody>().transform.forward.normalized;

                    if (!GameManager.player.GetComponent <PlayerController>().getIsLookingRight())
                    {
                        forwardDirection *= -1f;
                    }
                    body.GetComponent <Rigidbody>().velocity = ((forwardDirection) + (((targetDir.normalized) * Mathf.Abs(forceRatio)))).normalized * forceMagnitude;
                    if (body.getIsFallingIntoPlanet())
                    {
                        body.GetComponent <Rigidbody>().velocity -= objectUp * Constants.AMMOUNT_OF_DOWN_SPEED_ON_LANDING;
                    }
                    objectToAttract.parent = transform;
                }


                float ratio = 1f - (distance / gravityDistance);
                forceToAdd *= Constants.GRAVITY_MULTIPLYIER_ON_SPACE_JUMPS * ratio;
            }
            if (body.getIsGettingOutOfOrbit())
            {
                hasToAddForce = false;
            }
            if (hasToAddForce && applyForce)
            {
                objectToAttract.GetComponent <Rigidbody>().AddForce(gravityMultiplyier * targetDir * forceToAdd, ForceMode.VelocityChange);
            }
            body.GetComponent <Rigidbody>().velocity = body.GetComponent <Rigidbody>().velocity.normalized *Mathf.Abs(forceMagnitude);
            //We only put the body in the hierarchy if it has touched a planet after doing "Space travel".
            if (!body.getUsesSpaceGravity())
            {
                objectToAttract.parent = transform;
            }

            return(true);
        }
        return(false);
    }