Beispiel #1
0
    private void comboCheck()
    {
        List <string[][]> tempComboList = new List <string[][]>();

        //Adds the first move in a combo to the refindComboList
        if (comboTracker.Count == 1)
        {
            foreach (string[][] moveSet in comboList)
            {
                if (moveSet[0][0] == comboTracker[0])
                {
                    refindComboList.Add(moveSet);
                }
            }
        }
        //Adds all other moves in a combo to the refindComboList
        else if (comboTracker.Count > 1)
        {
            foreach (string[][] moveSet in refindComboList)
            {
                bool addMoveSet = true;
                for (int i = 0; i < comboTracker.Count; i++)
                {
                    if (moveSet[0][i] != comboTracker[i])
                    {
                        addMoveSet = false;
                    }
                }
                if (addMoveSet)
                {
                    if (moveSet[0].Length == comboTracker.Count)
                    {
                        comboSuccess = true;
                        attackString = moveSet[1][0];
                        if (moveSet[1][0] == "HurricaneKick")
                        {
                            SpinKick.GetComponent <AudioSource>().Play();

                            attackDamage = hurricaneKickDamage;
                            TextCanvas.setText("Hurricane Kick");
                            if (Training.getTrainingMode())
                            {
                                Training.training("Hurricane Kick");
                            }
                        }
                        else if (moveSet[1][0] == "UpperCut")
                        {
                            UpperCut.GetComponent <AudioSource>().Play();
                            attackDamage = upperCutDamage;
                            TextCanvas.setText("Upper Cut");
                            if (Training.getTrainingMode())
                            {
                                Training.training("Upper Cut");
                            }
                        }
                        else if (moveSet[1][0] == "SurasshuSlash")
                        {
                            SurasshuSlash.GetComponent <AudioSource>().Play();

                            attackDamage = surasshuSlashDamage;
                            TextCanvas.setText("Surasshu Slash");



                            if (Training.getTrainingMode())
                            {
                                Training.training("Surasshu Slash");
                            }
                        }
                    }
                    else
                    {
                        tempComboList.Add(moveSet);
                    }
                }
            }
            if (tempComboList == null || tempComboList.Count == 0 && !comboSuccess)
            {
                comboTracker.RemoveAt(0);
                foreach (string[][] moveSet in comboList)
                {
                    bool addMove = true;
                    for (int i = 0; i < comboTracker.Count; i++)
                    {
                        if (moveSet[0][i] != comboTracker[i])
                        {
                            addMove = false;
                        }
                    }
                    if (addMove)
                    {
                        tempComboList.Add(moveSet);
                    }
                }
            }
            displayComboUIReset();
            refindComboList = tempComboList;
        }

        //Fail combo, reset combo variables
        if ((refindComboList == null || refindComboList.Count == 0) && !comboSuccess)
        {
            comboReset();
            displayComboUIReset();
        }
        displayComboUI();
    }
Beispiel #2
0
    private void PerformMovement()
    {
        //playerMoving = true if there is horizontal or vertical movement and the player is not attacking, otherwise false.
        playerMoving = Input.GetAxisRaw("Horizontal") == 0 && Input.GetAxisRaw("Vertical") == 0 || playerAttacking  ? false : true;

        if (attackString == "HurricaneKick")
        {
            playerMoving = true;
        }

        //playerAttacking = false once the attack antimation has been played.
        //Stops the player from moving whilst attacking.
        if (!anim.GetCurrentAnimatorStateInfo(0).IsName(attackString) && timeSinceLastHit >= comboTimeMin)
        {
            playerAttacking = false;
        }
        else
        {
            myRigidbody.velocity = new Vector2(0f, 0f);
        }

        //Setting up the movement variables
        bool setH = Input.GetAxisRaw("Horizontal") > 0.1 || Input.GetAxisRaw("Horizontal") < -0.1;
        bool setV = Input.GetAxisRaw("Vertical") > 0.1 || Input.GetAxisRaw("Vertical") < -0.1;
        int  h    = 0;
        int  v    = 0;

        if (setH)
        {
            h = Input.GetAxisRaw("Horizontal") > 0 ? 1 : -1;
        }
        if (setV)
        {
            v = Input.GetAxisRaw("Vertical") > 0 ? 1 : -1;
        }

        //Sets the diagonal speed to 5 and the horizontal and vertical speed to 6
        float movementspeed;

        if (h != 0 && v != 0)
        {
            movementspeed = speed * .7f;
        }
        else
        {
            movementspeed = speed;
        }

        if (!playerAttacking || attackString == "HurricaneKick")
        {
            if (comboTracker != null && comboTracker.Count != 0 && Training.getTrainingMode())
            {
                combo[comboTracker.Count].GetComponent <SpriteRenderer>().sprite  = comboButtonFlashing;
                combo[comboTracker.Count].GetComponent <SpriteRenderer>().enabled = true;
            }

            //--movement
            if (h == 1 || h == -1)
            {
                myRigidbody.velocity = new Vector2(h * movementspeed, myRigidbody.velocity.y);
                lastMove             = new Vector2(h, v);
            }
            if (v == 1 || v == -1)
            {
                myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, v * movementspeed);
                lastMove             = new Vector2(h, v);
            }

            //Stops the player from sliding
            if (Input.GetAxisRaw("Horizontal") < 0.1f && Input.GetAxisRaw("Horizontal") > -0.1f)
            {
                myRigidbody.velocity = new Vector2(0f, myRigidbody.velocity.y);
            }
            if (Input.GetAxisRaw("Vertical") < 0.1f && Input.GetAxisRaw("Vertical") > -0.1f)
            {
                myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, 0f);
            }

            //Reset the comboUI
            if (comboSuccess == true)
            {
                comboSuccess = false;
                comboReset();
                displayComboUIReset();
            }

            //Calls the Action method which deals with attacks
            if (attackString == "")
            {
                Action();
            }
        }
        if (comboTracker != null || comboTracker.Count > 0)
        {
            comboCheck();
        }

        anim.SetFloat("MoveX", h);
        anim.SetFloat("MoveY", v);

        anim.SetFloat("LastMoveX", lastMove.x);
        anim.SetFloat("LastMoveY", lastMove.y);
        //Plays movement animation is playerMoving is true
        anim.SetBool("PlayerMoving", playerMoving);

        //Plays attacking animation and checks if the attack is hitting an enemy
        if (playerAttacking && attackString != "")
        {
            //Plays the attack animation only once
            if (!hasAttackAnimationPlayed)
            {
                //attacking sounds
                int rand = UnityEngine.Random.Range(0, attackSounds.Length);
                audio.clip = attackSounds[rand];
                audio.Play();
                //attacking animation
                anim.SetBool(attackString, playerAttacking);
                hasAttackAnimationPlayed = true;
            }

            //If an attack collies with an enemy calls a damage method on that enemy
            if (enemy != null)
            {
                enemy.SendMessage("EnemyBeenHit", attackDamage);
                enemy = null;
            }
        }
        else if (attackString != "")
        {
            if (Training.getTrainingMode())
            {
                Training.animate(false);
            }
            //Attack animation is set to false and attacking variables are reset
            anim.SetBool(attackString, playerAttacking);
            attackString = "";
            TextCanvas.setText("");
            attackDamage             = 0;
            hasAttackAnimationPlayed = false;
        }
    }