Esempio n. 1
0
    void Update()
    {
        float joyStickX = xboxInput.getXaxis();

        //Color choice
        //prevent from infinite change
        if (currentState == 0)
        {
            if (joyStickX < 0.5f && joyStickX > -0.5f)
            {
                changedRecently = false;
            }

            //change color for player
            if (joyStickX == 1 && !changedRecently)
            {
                SoundManager.instance.RandomizeSfx(choice);
                currentColor = GameVariables.getNextColorRight(currentColor, usedColors);
                colorImages();
                changedRecently = true;
            }
            else if (joyStickX == -1 && !changedRecently)
            {
                SoundManager.instance.RandomizeSfx(choice);
                currentColor = GameVariables.getNextColorLeft(currentColor, usedColors);
                colorImages();
                changedRecently = true;
            }

            if (usedColors.ContainsValue(currentColor))
            {
                currentColor = GameVariables.getNextColorRight(currentColor, usedColors);
                colorImages();
            }
        }

        //Bonus Choice
        if (currentState == 1)
        {
            transform.FindChild("Player").gameObject.SetActive(false);
            bonusGO.SetActive(true);
            if (joyStickX < 0.5f && joyStickX > -0.5f)
            {
                changedRecently = false;
            }

            //change color for player
            if (joyStickX == 1 && !changedRecently)
            {
                SoundManager.instance.RandomizeSfx(choice);
                currentBonus = GameVariables.getNextBonusRight(currentBonus);
                bonusImages();
                changedRecently = true;
            }
            else if (joyStickX == -1 && !changedRecently)
            {
                SoundManager.instance.RandomizeSfx(choice);
                currentBonus = GameVariables.getNextBonusLeft(currentBonus);
                bonusImages();
                changedRecently = true;
            }
        }
        else
        {
            bonusGO.SetActive(false);
        }
        if (currentState == 2 && !changedRecently)
        {
            transform.FindChild("Both/Bonus").transform.GetComponent <Image>().sprite = currentBonus.GetComponent <Image> ().sprite;
            transform.FindChild("Both").gameObject.SetActive(true);
        }
        if (currentState == (maxState - 1) && !changedRecently)
        {
            transform.FindChild("InstructionsPanel/Validate").gameObject.SetActive(false);
        }
        if (Input.GetKeyDown(xboxInput.A) || Input.GetKeyDown(xboxInput.BStart))
        {
            SoundManager.instance.RandomizeSfx(validate);
            int currentReady = nbReady;
            //go to next state and update Debug.Loging
            if (currentState < maxState)
            {
                currentState++;

                if (!usedColors.ContainsValue(currentColor))
                {
                    usedColors.Add(playerControllerId, currentColor);
                }

                if (currentState == maxState - 1)
                {
                    nbReady++;
                }
                if (currentState < maxState)
                {
                    text.text = textState [currentState];
                }
            }
            //if there are enough player, show "Play" text
            if (nbReady >= GameVariables.minPlayers && nbReady >= GameObject.Find("CheckNewControllers").transform.GetComponent <CheckNewControllers> ().GetNbPlayers())
            {
                playText.enabled = true;
            }
            if (currentState == maxState && currentReady >= GameVariables.minPlayers && currentReady >= GameObject.Find("CheckNewControllers").transform.GetComponent <CheckNewControllers> ().GetNbPlayers())
            {
                SceneManager.LoadScene("ModeSelectionMenu");
            }
        }
        else if (Input.GetKeyDown(xboxInput.B))
        {
            //Player wants to go back to previous menu
            if (currentState == 0)
            {
                SoundManager.instance.RandomizeSfx(close);
                SceneManager.LoadScene(1);
            }
            //go to previous state and update Debug.Loging
            if (currentState > 0)
            {
                if (currentState == maxState - 1)
                {
                    nbReady--;
                }

                currentState--;
                switch (currentState)
                {
                case 0:
                    transform.FindChild("Player").gameObject.SetActive(true);
                    transform.FindChild("InstructionsPanel/Validate").gameObject.SetActive(true);
                    usedColors.Remove(playerControllerId);
                    break;

                case 1:
                    transform.FindChild("InstructionsPanel/Validate").gameObject.SetActive(true);
                    transform.FindChild("Both").gameObject.SetActive(false);
                    break;

                case 2:
                    transform.FindChild("InstructionsPanel/Validate").gameObject.SetActive(true);
                    transform.FindChild("Both").gameObject.SetActive(true);
                    break;

                default:
                    break;
                }
                text.text = textState [currentState];
            }
            //if there are not enough player, hide "Play" text
            if (nbReady < GameObject.Find("CheckNewControllers").transform.GetComponent <CheckNewControllers> ().GetNbPlayers())
            {
                playText.enabled = false;
            }
        }
    }
    void Update()
    {
        //Remove pause menu if existing
        if (GameVariables.pausedGame)
        {
            SceneManager.UnloadScene("PauseMenu");
            GameVariables.pausedGame = false;
        }

        //X and Y axis are defined in Edit/Project Settings/Input
        movementVector.x = modeDirection * xboxInput.getXaxis() * movementSpeed * Time.deltaTime;
        if (movementVector.x != 0f && mapCollider.OverlapPoint((Vector2)(groundPosition.position + new Vector3(movementVector.x, 0, 0))))
        {
            rgdby.MovePosition(transform.position + movementVector);
            changeAllAnimatorsBool(animatorsBody, "isWalking", true);
            changeAllAnimatorsBool(animatorsArm, "isWalking", true);
            if (movementVector.x < 0)
            {
                transform.localScale = rightOrientationScale;
            }
            else
            {
                transform.localScale = leftOrientationScale;
            }
        }

        movementVector.y = modeDirection * xboxInput.getYaxis() * movementSpeed * Time.deltaTime;
        if (movementVector.y != 0f && mapCollider.OverlapPoint((Vector2)(groundPosition.position + new Vector3(0, movementVector.y, 0))))
        {
            rgdby.MovePosition(transform.position + movementVector);
            changeAllAnimatorsBool(animatorsBody, "isWalking", true);
            changeAllAnimatorsBool(animatorsArm, "isWalking", true);
        }

        if (movementVector.x == 0f && movementVector.y == 0f)
        {
            changeAllAnimatorsBool(animatorsBody, "isWalking", false);
            changeAllAnimatorsBool(animatorsArm, "isWalking", false);
        }


        if (Input.GetKeyDown(xboxInput.A))
        {
            Debug.Log("P" + human.getJoystickId() + " : A");
            triggerAllAnimators(animatorsArmKnife, "attackTrigger");
            SoundManager.instance.RandomizeSfx(attack);
        }
        if (Input.GetKeyDown(xboxInput.B))
        {
            Debug.Log("P" + human.getJoystickId() + " : B");
            if (!bonusUsed)
            {
                Debug.Log("Use Bonus");
                Bonus_Abstract[] scripts = bonus.GetComponents <Bonus_Abstract> ();
                foreach (Bonus_Abstract s in scripts)
                {
                    Debug.Log(s);
                    s.enabled = true;
                }
                bonusUsed = true;
            }
            else
            {
                Debug.Log("Already Use Bonus");
            }
        }
        if (Input.GetKeyDown(xboxInput.X))
        {
            Debug.Log("P" + human.getJoystickId() + " : X");
            if (human.getAmmo() > 0)
            {
                human.removeAmmo();
                triggerAllAnimators(animatorsArm, "shootTrigger");                  //Trigger Animation which will call function from BulletSpawner.cs
                SoundManager.instance.RandomizeSfx(shot);
            }
        }
        if (Input.GetKeyDown(xboxInput.Y))
        {
            Debug.Log("P" + human.getJoystickId() + " : Y");
        }
        if (Input.GetKeyDown(xboxInput.LT))
        {
            Debug.Log("P" + human.getJoystickId() + " : LT");
        }
        if (Input.GetKeyDown(xboxInput.LR))
        {
            Debug.Log("P" + human.getJoystickId() + " : LR");
        }
        if (Input.GetKeyDown(xboxInput.Select))
        {
            Debug.Log("P" + human.getJoystickId() + " : Select");
        }
        if (Input.GetKeyDown(xboxInput.BStart))
        {
            Debug.Log("P" + human.getJoystickId() + " : BStart");
            if (!GameVariables.pausedGame)
            {
                SceneManager.LoadScene("PauseMenu", LoadSceneMode.Additive);
            }
        }
    }