Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (this.enabled)
        {
            anim.SetTrigger("PopupTrigger");
        }

        if (isPlaying)
        {
            hp1.transform.parent.gameObject.SetActive(true);
            hp2.transform.parent.gameObject.SetActive(true);
            hp3.transform.parent.gameObject.SetActive(true);
            hp4.transform.parent.gameObject.SetActive(true);
            hp1.GetComponent <Bar>().setValue(Game.roster[team1.playingCharacters[0]].health / 100f, false);
            hp2.GetComponent <Bar>().setValue(Game.roster[team1.playingCharacters[1]].health / 100f, false);
            hp3.GetComponent <Bar>().setValue(Game.roster[team2.playingCharacters[0]].health / 100f, false);
            hp4.GetComponent <Bar>().setValue(Game.roster[team2.playingCharacters[1]].health / 100f, false);


            if (Game.roster[team1.playingCharacters[0]].health == 0)
            {
                sprite1.transform.GetChild(0).GetComponent <SpriteRenderer>().flipY = true;
                sprite1.transform.GetChild(0).GetComponent <SpriteRenderer>().color = Color.black;
                Color tmp = sprite1.transform.GetChild(0).GetComponent <SpriteRenderer>().color;
                tmp.a = 0.5f;
                sprite1.transform.GetChild(0).GetComponent <SpriteRenderer>().color = tmp;

                sprite1.transform.GetChild(0).GetComponent <Animator>().enabled = false;
            }
            if (Game.roster[team1.playingCharacters[1]].health == 0)
            {
                sprite2.transform.GetChild(0).GetComponent <SpriteRenderer>().flipY = true;
                sprite2.transform.GetChild(0).GetComponent <SpriteRenderer>().color = Color.black;
                Color tmp = sprite2.transform.GetChild(0).GetComponent <SpriteRenderer>().color;
                tmp.a = 0.5f;
                sprite2.transform.GetChild(0).GetComponent <SpriteRenderer>().color = tmp;
                sprite2.transform.GetChild(0).GetComponent <Animator>().enabled     = false;
            }


            if (Game.roster[team2.playingCharacters[0]].health == 0)
            {
                sprite3.transform.GetChild(0).GetComponent <SpriteRenderer>().flipY = true;
                sprite3.transform.GetChild(0).GetComponent <SpriteRenderer>().color = Color.black;
                Color tmp = sprite3.transform.GetChild(0).GetComponent <SpriteRenderer>().color;
                tmp.a = 0.5f;
                sprite3.transform.GetChild(0).GetComponent <SpriteRenderer>().color = tmp;
                sprite3.transform.GetChild(0).GetComponent <Animator>().enabled     = false;
            }
            if (Game.roster[team2.playingCharacters[1]].health == 0)
            {
                sprite4.transform.GetChild(0).GetComponent <SpriteRenderer>().flipY = true;
                sprite4.transform.GetChild(0).GetComponent <SpriteRenderer>().color = Color.black;
                Color tmp = sprite4.transform.GetChild(0).GetComponent <SpriteRenderer>().color;
                tmp.a = 0.5f;
                sprite4.transform.GetChild(0).GetComponent <SpriteRenderer>().color = tmp;
                sprite4.transform.GetChild(0).GetComponent <Animator>().enabled     = false;
            }

            if (Game.roster[team1.playingCharacters[0]].health == 0 && Game.roster[team1.playingCharacters[1]].health == 0)
            {
                isPlaying = false;
            }
            if (Game.roster[team2.playingCharacters[0]].health == 0 && Game.roster[team2.playingCharacters[1]].health == 0)
            {
                isPlaying = false;
            }



            if (waitingForMoveInput)
            {
                moveInput = getInput();
            }

            if (waitingForTargetInput)
            {
                targetInput = getInput();
            }


            if (turn == 1)
            {
                if (!waitingForMoveInput && !waitingForTargetInput)
                {
                    Debug.Log(" It's Player 1's turn!\n\n");
                }
                //Debug.Log(" It's the turn of player 1");
                if (indexCurrentChar == 0)
                {
                    if (!waitingForMoveInput && !waitingForTargetInput)
                    {
                        /*
                         * if (dialogText.text != null)
                         * {
                         *  string tampon = dialogText.text;
                         *  tampon += tampon + "Enter Input for " + Game.roster[team1.playingCharacters[indexCurrentChar]].name + " in team 1 \n A - attack\n S - ultimate\n D - combo\n";
                         *  displayText(tampon);
                         * }
                         * else*/
                        dialogText.text = "Enter Input for " + Game.roster[team1.playingCharacters[indexCurrentChar]].name + " in team 1 \n A - attack\n S - ultimate\n D - combo";
                    }
                    //Debug.Log("Enter Input for " + Game.roster[team1.playingCharacters[indexCurrentChar]].name + " in team 1 ( A - attack S - ultimate D - combo)");

                    waitingForMoveInput = true;
                    if (moveInput != "")
                    {
                        waitingForMoveInput = false;
                        Character currentCharacter = Game.roster[team1.playingCharacters[indexCurrentChar]];


                        applyMoveInput(team2, team1, currentCharacter, 1);

                        if (moveInput != "a" || !waitingForTargetInput)
                        {
                            // resets inputs for next play
                            moveInput        = "";
                            targetInput      = "";
                            indexCurrentChar = 1;
                        }
                    }
                    // the kid didnt give an input dont do anything
                }
                else
                {
                    if (!waitingForMoveInput && !waitingForTargetInput)
                    {
                        dialogText.text = "Enter Input for " + Game.roster[team1.playingCharacters[indexCurrentChar]].name + " in team 1 \n A - attack\n S - ultimate\n D - combo";
                    }
                    // Debug.Log("Enter Input for " + Game.roster[team1.playingCharacters[indexCurrentChar]].name + " in team 1 ( A - attack S - ultimate D - combo)");
                    waitingForMoveInput = true;
                    if (moveInput != "")
                    {
                        waitingForMoveInput = false;
                        Character currentCharacter = Game.roster[team1.playingCharacters[indexCurrentChar]];


                        applyMoveInput(team2, team1, currentCharacter, 0);

                        if (moveInput != "a" || !waitingForTargetInput)
                        {
                            // resets inputs for next play
                            moveInput        = "";
                            targetInput      = "";
                            indexCurrentChar = 0;
                            turn             = 2;
                        }
                    }
                    // the kid didnt give an input dont do anything
                }
            }
            else
            {
                if (!waitingForMoveInput && !waitingForTargetInput)
                {
                    dialogText.text = " It's the turn of player 2";
                }
                //Debug.Log(" It's the turn of player 2");
                if (indexCurrentChar == 0)
                {
                    if (!waitingForMoveInput && !waitingForTargetInput)
                    {
                        dialogText.text = "It's the turn of player 2 \n\nEnter Input for " + Game.roster[team2.playingCharacters[indexCurrentChar]].name + " in team 2 \n A - attack\n S - ultimate\n D - combo";
                    }
                    //Debug.Log("Enter Input for " + Game.roster[team2.playingCharacters[indexCurrentChar]].name + " in team 2 ( A - attack S - ultimate D - combo)");

                    waitingForMoveInput = true;
                    if (moveInput != "")
                    {
                        waitingForMoveInput = false;
                        Character currentCharacter = Game.roster[team2.playingCharacters[indexCurrentChar]];


                        applyMoveInput(team1, team2, currentCharacter, 1);

                        if (moveInput != "a" || !waitingForTargetInput)
                        {
                            // resets inputs for next play
                            moveInput        = "";
                            targetInput      = "";
                            indexCurrentChar = 1;
                        }
                    }
                    // the kid didnt give an input dont do anything
                }
                else
                {
                    if (!waitingForMoveInput && !waitingForTargetInput)
                    {
                        dialogText.text = "Enter Input for " + Game.roster[team2.playingCharacters[indexCurrentChar]].name + " in team 2 \n A - attack\n S - ultimate\n D - combo";
                    }

                    //Debug.Log("Enter Input for " + Game.roster[team2.playingCharacters[indexCurrentChar]].name + " in team 2 ( A - attack S - ultimate D - combo)");
                    waitingForMoveInput = true;
                    if (moveInput != "")
                    {
                        waitingForMoveInput = false;
                        Character currentCharacter = Game.roster[team2.playingCharacters[indexCurrentChar]];


                        applyMoveInput(team1, team2, currentCharacter, 0);

                        if (moveInput != "a" || !waitingForTargetInput)
                        {
                            // resets inputs for next play
                            moveInput        = "";
                            targetInput      = "";
                            indexCurrentChar = 0;
                            turn             = 1;
                        }
                    }
                    // the kid didnt give an input dont do anything
                }
                // code to run the game
            }
        }
        else
        {
            if (!!characterSelection.isDone && isPlaying)
            {
                foreach (Character c in Game.roster)
                {
                    c.reset();
                }
                characterSelection.isDone  = false;
                characterSelection.enabled = true;
                speech.SetActive(false);
                this.gameObject.SetActive(false);
                toggleAllAnimation(false);
                flipAllSprites(false);
                characterSelection.Start();
                characterSelection.initialiseAllHeroes();
                if (team1.playingCharacters != null)
                {
                    team1.playingCharacters.Clear();
                }
                if (team2.playingCharacters != null)
                {
                    team2.playingCharacters.Clear();
                }
            }
        }
    }