コード例 #1
0
ファイル: StaticAI.cs プロジェクト: deerter/Scarlet-Flash
    private void ExecuteAction()
    {
        if ((Array.IndexOf(AnimationStates.GetAttacks(), characterAction) >= 0))
        {
            characterActions.PerformAttack(characterAction);
        }
        else if (characterAction == AnimationStates.WALK_BACKWARDS)
        {
            characterActions.Block();
            characterActions.Walk(rigidBody, animator, AnimationStates.WALK_BACKWARDS);
        }
        else if (characterAction == AnimationStates.WALK_FORWARDS)
        {
            characterActions.Walk(rigidBody, animator, AnimationStates.WALK_FORWARDS);
        }
        else if (characterAction == AnimationStates.STANDING && !currentCharacter.GetIsJumping())
        {
            animator.SetFloat("Horizontal", 0);
            currentCharacter.EndAnimation(AnimationStates.STANDING);
        }
        else if (characterAction == AnimationStates.JUMPING_BACKWARDS)
        {
            switch (currentCharacter.GetIsFlipped())
            {
            case true: characterActions.Jump(rigidBody, "JumpingRight"); break;

            case false: characterActions.Jump(rigidBody, "JumpingLeft"); break;
            }
        }
        else if (characterAction == AnimationStates.JUMPING_FORWARDS)
        {
            switch (currentCharacter.GetIsFlipped())
            {
            case true: characterActions.Jump(rigidBody, "JumpingLeft"); break;

            case false: characterActions.Jump(rigidBody, "JumpingRight"); break;
            }
        }
        else if (characterAction == AnimationStates.JUMPING_UP)
        {
            characterActions.Jump(rigidBody, "JumpingUp");
        }
        else if (characterAction == AnimationStates.BLOCKING_JUMPING || characterAction == AnimationStates.BLOCKING_CROUCHING)
        {
            characterActions.Block();
            characterActions.Invoke("StopBlocking", 5);   //// Stops blocking after x seconds
        }


        ///// Swap characters
        if (characterAction == "SwapCharacter2")
        {
            characterAssist.Swap("Assist1", false);
        }
        else if (characterAction == "SwapCharacter3")
        {
            characterAssist.Swap("Assist2", false);
        }
    }
コード例 #2
0
ファイル: RotateByArrows.cs プロジェクト: pontura/mundo
 void Update()
 {
     if (inputManager.forward != 0)
     {
         actions.Walk();
         transform.Rotate(Vector3.right * (Time.deltaTime * (speed)));
     }
     else
     {
         actions.Idle();
     }
     if (ui_planets.direction != 0)
     {
         transform.Rotate(Vector3.up * (Time.deltaTime * (speed) * 15) * ui_planets.direction);
     }
 }
コード例 #3
0
    /*public void falling(){       ///////JUST IN CASE/////////////Loops last frames of falling animation
     *          animator.Play(AnimationStates.JUMPING_DOWN,0,0.5f);
     *  }*/

    /////////////////

    void Update()
    {
        if ((currentCharacter.IsAnimationPlaying() && !currentCharacter.GetIsJumping() && !currentCharacter.GetIsHit()))
        { //In case the animation goes from walking to other animation, prevents from sliding behaviour
            rigidBody.velocity = new Vector2(0, 0);
        }

        if (!currentCharacter.GetIsBlocked())
        {
            ///Moving
            animator.SetFloat("Horizontal", 0);  //Sets the horizontal back to 0 so that the animator can move from walking to standing (if not, loops the walking animation)

            // When character moves right (depending on side of the field)
            if ((Input.GetKey(GameConstants.R)))
            {
                switch (currentCharacter.GetIsFlipped())
                {
                case true: characterActions.Walk(rigidBody, animator, AnimationStates.WALK_BACKWARDS); break;

                case false: characterActions.Walk(rigidBody, animator, AnimationStates.WALK_FORWARDS); break;
                }
            }
            // When character moves left (depending on side of the field)
            else if ((Input.GetKey(GameConstants.L)))
            {
                switch (currentCharacter.GetIsFlipped())
                {
                case true: characterActions.Walk(rigidBody, animator, AnimationStates.WALK_FORWARDS); break;

                case false: characterActions.Walk(rigidBody, animator, AnimationStates.WALK_BACKWARDS); break;
                }
            }

            if (Input.GetKeyUp(GameConstants.L) || Input.GetKeyUp(GameConstants.R))
            {
                characterActions.StopBlocking();
                if (currentCharacter.GetAnimationStatus() == AnimationStates.WALK_BACKWARDS || currentCharacter.GetAnimationStatus() == AnimationStates.WALK_FORWARDS)
                {
                    rigidBody.velocity = new Vector2(0, 0);
                }
            }

            //Blocking
            if ((Input.GetKey(GameConstants.R)) && currentCharacter.GetIsFlipped() || (Input.GetKey(GameConstants.L)) && !currentCharacter.GetIsFlipped())
            {
                characterActions.Block();
            }


            // Crouching
            if (Input.GetKey(GameConstants.D) && !currentCharacter.IsAnimationPlaying() && !currentCharacter.GetIsCrouching() && !currentCharacter.GetIsJumping())
            {
                rigidBody.velocity = new Vector2(0, 0);       //Prevents from sliding
                characterActions.SetCoordinatesWhenLanding(); //Prevents from phasing through the ground if the down button is pressed when the character touches the ground after a jump.
                currentCharacter.PlayAnimation(AnimationStates.CROUCH);
                currentCharacter.SetAnimationStatus(AnimationStates.CROUCH);
                currentCharacter.SetIsCrouching(true);
                currentCharacter.SetAnimationPlaying(false);
            }

            if (Input.GetKeyUp(GameConstants.D) && !currentCharacter.GetIsJumping())
            {
                //SetCoordinatesWhenLanding();
                currentCharacter.SetIsCrouching(false);
                if (!currentCharacter.IsAnimationPlaying())
                {
                    currentCharacter.EndAnimation(AnimationStates.STANDING);
                }
            }

            // Jumping
            if (Input.GetKeyDown(GameConstants.U) && !currentCharacter.IsAnimationPlaying() && !currentCharacter.GetIsCrouching() && !currentCharacter.GetIsJumping())
            {
                if (Input.GetKey(GameConstants.R))
                {
                    characterActions.Jump(rigidBody, "JumpingRight");
                }
                else if (Input.GetKey(GameConstants.L))
                {
                    characterActions.Jump(rigidBody, "JumpingLeft");
                }
                else
                {
                    characterActions.Jump(rigidBody, "JumpingUp");
                }
            }
        }
    }
コード例 #4
0
 void Update()
 {
     // Si el estado del juego no estan en JUGANDO
     if (gameManager.jugandoPartida == true)
     {
         // Si el nivel no esta terminado, entonces puede moverse
         if (gameManager.levelComplete == false)
         {
             // Si el personaje no esta muerto, entonces puede moverse
             if (character.stats.characterDie == false)
             {
                 // Si el super poder no esta activo, entonces puede moverse
                 if (character.stats.superPowerActive == false)
                 {
                     float horizontal    = (Input.GetAxis("Horizontal"));
                     bool  jumpButton    = (Input.GetButtonDown("Jump"));
                     bool  meditarButton = (Input.GetButtonDown("Meditar"));
                     pegarButton = (Input.GetButtonDown("Pegar"));
                     bool superataqueButton = (Input.GetButtonDown("Superataque"));
                     // Caminar hacia la izquierda
                     if (Input.GetKey(KeyCode.A) || horizontal < 0)
                     {
                         actions.Walk(-1);
                     }
                     // Caminar hacia la derecha
                     if (Input.GetKey(KeyCode.D) || horizontal > 0)
                     {
                         actions.Walk(1);
                     }
                     // Salto
                     if (Input.GetKeyDown(KeyCode.W) || jumpButton == true)
                     {
                         if (groundcheck.onGround == true)
                         {
                             actions.Jump();
                         }
                     }
                     // Ataque
                     if (Input.GetKeyDown(KeyCode.P) || pegarButton == true)
                     {
                         // Si el contador de ataque es true puede pegar
                         if (attackCounter == true)
                         {
                             actions.Attack();
                             // Desactivo el contador de ataqaue
                             attackCounter = false;
                             pressP        = true;
                             // Inovoko un reset en la velocidad de ataque para resetar el contador y que pueda volver a atacar
                             Invoke("attackCounterReset", character.stats.characterAttackSpeed);
                         }
                         else
                         {
                             pressP = false;
                         }
                     }
                     // Super poder
                     if (Input.GetKeyDown(KeyCode.O) || superataqueButton == true)
                     {
                         actions.SuperPower();
                     }
                     // Meditar
                     if (Input.GetKeyDown(KeyCode.M) || meditarButton == true)
                     {
                         if (character.stats.characterMeditar == false)
                         {
                             actions.Meditar();
                         }
                     }
                     // Si aprieta las dos direcciones al mismo tiempo se queda quieto en el medio
                     if (!Input.anyKey || Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.A))
                     {
                         actions.Idle();
                     }
                 }
             }
         }
         // Si el personaje esta muerto ejecutar la funcion de morir
         else
         {
             actions.Die();
         }
     }
 }