Example #1
0
        private void updateColtrolls(GamePadState currentState, Player.EPlayerControlls controllType)
        {
            //schauen ob das GamePad überhaupt verbunden ist
            if (currentState.IsConnected)
            {
                //set isPressed = false
                if (!currentState.IsButtonDown(Buttons.A) && !currentState.IsButtonDown(Buttons.B) && (player1Controlls == controllType || player1Controlls == Player.EPlayerControlls.none))
                    isPressedP1 = false;
                if (!currentState.IsButtonDown(Buttons.A) && !currentState.IsButtonDown(Buttons.B) && (player2Controlls == controllType || player2Controlls == Player.EPlayerControlls.none))
                    isPressedP2 = false;
                if (!currentState.IsButtonDown(Buttons.A) && !currentState.IsButtonDown(Buttons.B) && (player3Controlls == controllType || player3Controlls == Player.EPlayerControlls.none))
                    isPressedP3 = false;
                if (!currentState.IsButtonDown(Buttons.A) && !currentState.IsButtonDown(Buttons.B) && (player4Controlls == controllType || player4Controlls == Player.EPlayerControlls.none))
                    isPressedP4 = false;

                if (currentState.IsButtonDown(Buttons.A) && player1Controlls != controllType && player2Controlls != controllType && player3Controlls != controllType && player4Controlls != controllType)
                {
                    //Player setzen falls noch kein Player ControlType besitzt
                    if (!player1ControllsLRS.isSelected() && player2Controlls != controllType && player3Controlls != controllType && player4Controlls != controllType && !isPressedP1)
                    {
                        player1ControllsLRS.setSelectedKlick();
                        while (player1ControllsLRS.getDisplayedIndex() != (int)controllType)
                            player1ControllsLRS.switchRight();
                        player1Controlls = controllType;
                        isPressedP1 = true;
                    }
                    if (!player2ControllsLRS.isSelected() && player1Controlls != controllType && player3Controlls != controllType && player4Controlls != controllType && !isPressedP2)
                    {
                        player2ControllsLRS.setSelectedKlick();
                        while (player2ControllsLRS.getDisplayedIndex() != (int)controllType)
                            player2ControllsLRS.switchRight();
                        player2Controlls = controllType;
                        isPressedP2 = true;
                    }
                    if (!player3ControllsLRS.isSelected() && player1Controlls != controllType && player2Controlls != controllType && player4Controlls != controllType && !isPressedP3)
                    {
                        player3ControllsLRS.setSelectedKlick();
                        while (player3ControllsLRS.getDisplayedIndex() != (int)controllType)
                            player3ControllsLRS.switchRight();
                        player3Controlls = controllType;
                        isPressedP3 = true;
                    }
                    if (!player4ControllsLRS.isSelected() && player1Controlls != controllType && player2Controlls != controllType && player3Controlls != controllType && !isPressedP4)
                    {
                        player4ControllsLRS.setSelectedKlick();
                        while (player4ControllsLRS.getDisplayedIndex() != (int)controllType)
                            player4ControllsLRS.switchRight();
                        player4Controlls = controllType;
                        isPressedP4 = true;
                    }
                }
                //player ready setzen
                if (currentState.IsButtonDown(Buttons.A) && player1Controlls == controllType && !isPressedP1)
                {
                    isPressedP1 = true;
                    player1Icon.setSelected();
                }
                if (currentState.IsButtonDown(Buttons.A) && player2Controlls == controllType && !isPressedP2)
                {
                    isPressedP2 = true;
                    player2Icon.setSelected();
                }
                if (currentState.IsButtonDown(Buttons.A) && player3Controlls == controllType && !isPressedP3)
                {
                    isPressedP3 = true;
                    player3Icon.setSelected();
                }
                if (currentState.IsButtonDown(Buttons.A) && player4Controlls == controllType && !isPressedP4)
                {
                    isPressedP4 = true;
                    player4Icon.setSelected();
                }

                if (currentState.IsButtonDown(Buttons.B) &&
                    ((!player1Icon.isSelected() && player1Controlls == controllType)
                    || (!player2Icon.isSelected() && player2Controlls == controllType)
                    || (!player3Icon.isSelected() && player3Controlls == controllType)
                    || (!player4Icon.isSelected() && player4Controlls == controllType)))
                {
                    //Player zurück setzen
                    if (player1ControllsLRS.isSelected() && player1Controlls == controllType && !isPressedP1)
                    {
                        player1ControllsLRS.setNotSelected();
                        player1Controlls = Player.EPlayerControlls.none;
                        while (player1ControllsLRS.getDisplayedIndex() != (int)controllType)
                            player1ControllsLRS.switchLeft();
                        isPressedP1 = true;
                    }
                    if (player2ControllsLRS.isSelected() && player2Controlls == controllType && !isPressedP2)
                    {
                        player2ControllsLRS.setNotSelected();
                        player2Controlls = Player.EPlayerControlls.none;
                        while (player2ControllsLRS.getDisplayedIndex() != (int)controllType)
                            player2ControllsLRS.switchLeft();
                        isPressedP2 = true;
                    }
                    if (player3ControllsLRS.isSelected() && player3Controlls == controllType && !isPressedP3)
                    {
                        player3ControllsLRS.setNotSelected();
                        player3Controlls = Player.EPlayerControlls.none;
                        while (player3ControllsLRS.getDisplayedIndex() != (int)controllType)
                            player3ControllsLRS.switchLeft();
                        isPressedP3 = true;
                    }
                    if (player4ControllsLRS.isSelected() && player4Controlls == controllType && !isPressedP4)
                    {
                        player4ControllsLRS.setNotSelected();
                        player4Controlls = Player.EPlayerControlls.none;
                        while (player4ControllsLRS.getDisplayedIndex() != (int)controllType)
                            player4ControllsLRS.switchLeft();
                        isPressedP4 = true;
                    }
                }

                //alle player auf unready setzen
                if (currentState.IsButtonDown(Buttons.B) && player1Controlls == controllType && !isPressedP1)
                {
                    isPressedP1 = true;
                    player1Icon.setNotSelected();
                }
                if (currentState.IsButtonDown(Buttons.B) && player2Controlls == controllType && !isPressedP2)
                {
                    isPressedP2 = true;
                    player2Icon.setNotSelected();
                }
                if (currentState.IsButtonDown(Buttons.B) && player3Controlls == controllType && !isPressedP3)
                {
                    isPressedP3 = true;
                    player3Icon.setNotSelected();
                }
                if (currentState.IsButtonDown(Buttons.B) && player4Controlls == controllType && !isPressedP4)
                {
                    isPressedP4 = true;
                    player4Icon.setNotSelected();
                }
            }
        }
Example #2
0
        /// <summary>
        /// manages the update of the keyboard controlls
        /// </summary>
        /// <param name="set">set the keyboard contoll with this key</param>
        /// <param name="unset">set the keyboard contoll with this ke</param>
        /// <param name="controllType">the controll type to set</param>
        private void updateColtrolls(Keys set, Keys unset, Player.EPlayerControlls controllType)
        {
            keyboard = Keyboard.GetState();

            //set isPressed = false
            if (!keyboard.IsKeyDown(set) && !keyboard.IsKeyDown(unset) && player1Controlls == controllType || (player1Controlls == Player.EPlayerControlls.none))
                isPressedP1 = false;
            if (!keyboard.IsKeyDown(set) && !keyboard.IsKeyDown(unset) && player2Controlls == controllType || (player2Controlls == Player.EPlayerControlls.none))
                isPressedP2 = false;
            if (!keyboard.IsKeyDown(set) && !keyboard.IsKeyDown(unset) && player3Controlls == controllType || (player3Controlls == Player.EPlayerControlls.none))
                isPressedP3 = false;
            if (!keyboard.IsKeyDown(set) && !keyboard.IsKeyDown(unset) && player4Controlls == controllType || (player4Controlls == Player.EPlayerControlls.none))
                isPressedP4 = false;

            if (keyboard.IsKeyDown(set) && player1Controlls != controllType && player2Controlls != controllType && player3Controlls != controllType && player4Controlls != controllType)
            {
                //Player setzen falls noch kein Player ControlType besitzt
                if (!player1ControllsLRS.isSelected() && player2Controlls != controllType && player3Controlls != controllType && player4Controlls != controllType && !isPressedP1)
                {
                    player1ControllsLRS.setSelectedKlick();
                    while(player1ControllsLRS.getDisplayedIndex() != (int)controllType)
                        player1ControllsLRS.switchRight();
                    player1Controlls = controllType;
                    isPressedP1 = true;
                }
                if (!player2ControllsLRS.isSelected() && player1Controlls != controllType && player3Controlls != controllType && player4Controlls != controllType && !isPressedP2)
                {
                    player2ControllsLRS.setSelectedKlick();
                    while (player2ControllsLRS.getDisplayedIndex() != (int)controllType)
                        player2ControllsLRS.switchRight();
                    player2Controlls = controllType;
                    isPressedP2 = true;
                }
                if (!player3ControllsLRS.isSelected() && player1Controlls != controllType && player2Controlls != controllType && player4Controlls != controllType && !isPressedP3)
                {
                    player3ControllsLRS.setSelectedKlick();
                    while (player3ControllsLRS.getDisplayedIndex() != (int)controllType)
                        player3ControllsLRS.switchRight();
                    player3Controlls = controllType;
                    isPressedP3 = true;
                }
                if (!player4ControllsLRS.isSelected() && player1Controlls != controllType && player2Controlls != controllType && player3Controlls != controllType && !isPressedP4)
                {
                    player4ControllsLRS.setSelectedKlick();
                    while (player4ControllsLRS.getDisplayedIndex() != (int)controllType)
                        player4ControllsLRS.switchRight();
                    player4Controlls = controllType;
                    isPressedP4 = true;
                }
            }
            //player ready setzen
            if (keyboard.IsKeyDown(set) && player1Controlls == controllType && !isPressedP1)
            {
                isPressedP1 = true;
                player1Icon.setSelected();
            }
            if (keyboard.IsKeyDown(set) && player2Controlls == controllType && !isPressedP2)
            {
                isPressedP2 = true;
                player2Icon.setSelected();
            }
            if (keyboard.IsKeyDown(set) && player3Controlls == controllType && !isPressedP3)
            {
                isPressedP3 = true;
                player3Icon.setSelected();
            }
            if (keyboard.IsKeyDown(set) && player4Controlls == controllType && !isPressedP4)
            {
                isPressedP4 = true;
                player4Icon.setSelected();
            }

            if (keyboard.IsKeyDown(unset) &&
                ((!player1Icon.isSelected() && player1Controlls == controllType)
                || (!player2Icon.isSelected() && player2Controlls == controllType)
                || (!player3Icon.isSelected() && player3Controlls == controllType)
                || (!player4Icon.isSelected() && player4Controlls == controllType)))
            {
                //Player zurück setzen
                if (player1ControllsLRS.isSelected() && player1Controlls == controllType && !isPressedP1)
                {
                    player1ControllsLRS.setNotSelected();
                    player1Controlls = Player.EPlayerControlls.none;
                    while (player1ControllsLRS.getDisplayedIndex() != (int)controllType)
                        player1ControllsLRS.switchLeft();
                    isPressedP1 = true;
                }
                if (player2ControllsLRS.isSelected() && player2Controlls == controllType && !isPressedP2)
                {
                    player2ControllsLRS.setNotSelected();
                    player2Controlls = Player.EPlayerControlls.none;
                    while (player2ControllsLRS.getDisplayedIndex() != (int)controllType)
                        player2ControllsLRS.switchLeft();
                    isPressedP2 = true;
                }
                if (player3ControllsLRS.isSelected() && player3Controlls == controllType && !isPressedP3)
                {
                    player3ControllsLRS.setNotSelected();
                    player3Controlls = Player.EPlayerControlls.none;
                    while (player3ControllsLRS.getDisplayedIndex() != (int)controllType)
                        player3ControllsLRS.switchLeft();
                    isPressedP3 = true;
                }
                if (player4ControllsLRS.isSelected() && player4Controlls == controllType && !isPressedP4)
                {
                    player4ControllsLRS.setNotSelected();
                    player4Controlls = Player.EPlayerControlls.none;
                    while (player4ControllsLRS.getDisplayedIndex() != (int)controllType)
                        player4ControllsLRS.switchLeft();
                    isPressedP4 = true;
                }
            }

            //alle player auf unready setzen
            if (keyboard.IsKeyDown(unset) && player1Controlls == controllType && !isPressedP1)
            {
                isPressedP1 = true;
                player1Icon.setNotSelected();
            }
            if (keyboard.IsKeyDown(unset) && player2Controlls == controllType && !isPressedP2)
            {
              isPressedP2 = true;
              player2Icon.setNotSelected();
            }
            if (keyboard.IsKeyDown(unset) && player3Controlls == controllType && !isPressedP3)
            {
                isPressedP3 = true;
                player3Icon.setNotSelected();
            }
            if (keyboard.IsKeyDown(unset) && player4Controlls == controllType && !isPressedP4)
            {
                isPressedP4 = true;
                player4Icon.setNotSelected();
            }
        }