public Pause(Player.EPlayerControlls _controlls) { controlls = _controlls; count = 0; isPressed = true; Vector2 position = new Vector2(0, 0); gresScreen = new Icon( position, "Textures/Pause/greyScreen"); float distY = 100 * Settings.getInterfaceScale(); resume = new Button(position, "Textures/Pause/resumeNot", "Textures/Pause/resumeSelected"); exit = new Button(position, "Textures/Pause/exitNot", "Textures/Pause/exitSelected"); position = new Vector2(Settings.getResolutionX() / 2 - resume.getWidth()/2, Settings.getResolutionY() / 2 - resume.getHeight() - distY); resume.setPosition(position); position = new Vector2(Settings.getResolutionX() / 2 - exit.getWidth() / 2, Settings.getResolutionY() / 2 + distY); exit.setPosition(position); }
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(); } } }
/// <summary> /// outsources the update process of the player 1 - 4 to prevent spagetti code /// </summary> private void updatePlayer() { //KeyboardControlls updateColtrolls(Keys.S, Keys.W, Player.EPlayerControlls.Keyboard1); //updateColtrolls(Keys.G, Keys.T, Player.EPlayerControlls.Keyboard2); //updateColtrolls(Keys.K, Keys.I, Player.EPlayerControlls.Keyboard3); //updateColtrolls(Keys.NumPad2, Keys.NumPad5, Player.EPlayerControlls.KeyboardNumPad); updateColtrolls(Keys.K, Keys.I, Player.EPlayerControlls.KeyboardNumPad); //gamepad Controlls GamePadState currentState = GamePad.GetState(PlayerIndex.One); updateColtrolls(currentState, Player.EPlayerControlls.Gamepad1); currentState = GamePad.GetState(PlayerIndex.Two); updateColtrolls(currentState, Player.EPlayerControlls.Gamepad2); currentState = GamePad.GetState(PlayerIndex.Three); updateColtrolls(currentState, Player.EPlayerControlls.Gamepad3); currentState = GamePad.GetState(PlayerIndex.Four); updateColtrolls(currentState, Player.EPlayerControlls.Gamepad4); //delete all player playerList.Clear(); //now create all needet Player Objects //player updaten und in playerList einfügen if (player1ControllsLRS.isSelected()) {//Player1 player1 = new Player(player1Controlls, Player.EPlayerIndex.one); playerList.Add(player1); } else player1 = null; if (player2ControllsLRS.isSelected()) {//Player2 player2 = new Player(player2Controlls, Player.EPlayerIndex.two); playerList.Add(player2); } else player2 = null; if (player3ControllsLRS.isSelected()) {//Player3 player3 = new Player(player3Controlls, Player.EPlayerIndex.three); playerList.Add(player3); } else player3 = null; if (player4ControllsLRS.isSelected()) {//Player4 player4 = new Player(player4Controlls, Player.EPlayerIndex.vour); playerList.Add(player4); } else player4 = null; //Check if list is too big if (playerList.Count > 4 || playerList == null) throw new IndexOutOfRangeException(); }
/// <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(); } }