示例#1
0
        public void ProcessKeyboard()
        {
            KeyboardState boardState = Keyboard.GetState();

            // Player Movement //

            Player player1 = playerList[0];

            if (player1.isAlive)
            {
                //PFEILE//
                if (boardState.IsKeyDown(Keys.Left))
                {
                    if (player1.directionX != 1 && player1.directionY != 0)
                    {
                        player1.directionX = -1;
                        player1.directionY = 0;
                        player1.changeRotation();
                    }
                }
                if (boardState.IsKeyDown(Keys.Right))
                {
                    if (player1.directionX != -1 && player1.directionY != 0)
                    {
                        player1.directionX = 1;
                        player1.directionY = 0;
                        player1.changeRotation();
                    }
                }
                if (boardState.IsKeyDown(Keys.Up))
                {
                    if (player1.directionX != 0 && player1.directionY != 1)
                    {
                        player1.directionX = 0;
                        player1.directionY = -1;
                        player1.changeRotation();
                    }
                }
                if (boardState.IsKeyDown(Keys.Down))
                {
                    if (player1.directionX != 0 && player1.directionY != -1)
                    {
                        player1.directionX = 0;
                        player1.directionY = 1;
                        player1.changeRotation();
                    }
                }
            }

            if (playerList.Count >= 2 && gameMode == 1)
            {
                Player player2 = playerList[1];
                if (player2.isAlive)
                {
                    //WASD//
                    if (boardState.IsKeyDown(Keys.A))
                    {
                        if (player2.directionX != 1 && player2.directionY != 0)
                        {
                            player2.directionX = -1;
                            player2.directionY = 0;
                            player2.changeRotation();
                        }
                    }
                    if (boardState.IsKeyDown(Keys.D))
                    {
                        if (player2.directionX != -1 && player2.directionY != 0)
                        {
                            player2.directionX = 1;
                            player2.directionY = 0;
                            player2.changeRotation();
                        }
                    }
                    if (boardState.IsKeyDown(Keys.W))
                    {
                        if (player2.directionX != 0 && player2.directionY != 1)
                        {
                            player2.directionX = 0;
                            player2.directionY = -1;
                            player2.changeRotation();
                        }
                    }
                    if (boardState.IsKeyDown(Keys.S))
                    {
                        if (player2.directionX != 0 && player2.directionY != -1)
                        {
                            player2.directionX = 0;
                            player2.directionY = 1;
                            player2.changeRotation();
                        }
                    }
                }
            }

            if (playerList.Count >= 3 && gameMode == 1)
            {
                Player player3 = playerList[2];
                if (player3.isAlive)
                {
                    //WASD//
                    if (boardState.IsKeyDown(Keys.NumPad1))
                    {
                        if (player3.directionX != 1 && player3.directionY != 0)
                        {
                            player3.directionX = -1;
                            player3.directionY = 0;
                            player3.changeRotation();
                        }
                    }
                    if (boardState.IsKeyDown(Keys.NumPad3))
                    {
                        if (player3.directionX != -1 && player3.directionY != 0)
                        {
                            player3.directionX = 1;
                            player3.directionY = 0;
                            player3.changeRotation();
                        }
                    }
                    if (boardState.IsKeyDown(Keys.NumPad5))
                    {
                        if (player3.directionX != 0 && player3.directionY != 1)
                        {
                            player3.directionX = 0;
                            player3.directionY = -1;
                            player3.changeRotation();
                        }
                    }
                    if (boardState.IsKeyDown(Keys.NumPad2))
                    {
                        if (player3.directionX != 0 && player3.directionY != -1)
                        {
                            player3.directionX = 0;
                            player3.directionY = 1;
                            player3.changeRotation();
                        }
                    }
                }
            }

            if (playerList.Count >= 4 && gameMode == 1)
            {
                Player player4 = playerList[3];
                if (player4.isAlive)
                {
                    //WASD//
                    if (boardState.IsKeyDown(Keys.J))
                    {
                        if (player4.directionX != 1 && player4.directionY != 0)
                        {
                            player4.directionX = -1;
                            player4.directionY = 0;
                            player4.changeRotation();
                        }
                    }
                    if (boardState.IsKeyDown(Keys.L))
                    {
                        if (player4.directionX != -1 && player4.directionY != 0)
                        {
                            player4.directionX = 1;
                            player4.directionY = 0;
                            player4.changeRotation();
                        }
                    }
                    if (boardState.IsKeyDown(Keys.I))
                    {
                        if (player4.directionX != 0 && player4.directionY != 1)
                        {
                            player4.directionX = 0;
                            player4.directionY = -1;
                            player4.changeRotation();
                        }
                    }
                    if (boardState.IsKeyDown(Keys.K))
                    {
                        if (player4.directionX != 0 && player4.directionY != -1)
                        {
                            player4.directionX = 0;
                            player4.directionY = 1;
                            player4.changeRotation();
                        }
                    }
                }
            }
        }