Guest User

Untitled

a guest
Dec 15th, 2013
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         #region Input and Keyboard Events
  2.        
  3.         /// <summary>
  4.         /// Handle player movement on screen, as well as some extra collision detection.
  5.         /// </summary>
  6.         public void HandleMovement()
  7.         {
  8.             if (isWKeyDown)
  9.             {
  10.                 player.Move(Direction.NORTH);
  11.             }
  12.             if (isSKeyDown)
  13.             {
  14.                 player.Move(Direction.SOUTH);
  15.             }
  16.             if (isAKeyDown)
  17.             {
  18.                 player.Move(Direction.WEST);
  19.             }
  20.             if (isDKeyDown)
  21.             {
  22.                 player.Move(Direction.EAST);
  23.             }
  24.  
  25.             // Check for wall collision in player input.
  26.             if (playerRectangle.IntersectsWith(winRectangle))
  27.             {
  28.                 var dialog = MessageBox.Show("Congratulations! You have won! Play again?", TITLE, MessageBoxButtons.YesNo);
  29.                 if (dialog == DialogResult.Yes)
  30.                 {
  31.                     // restart the game here.
  32.                 }
  33.                 else if (dialog == DialogResult.No)
  34.                 {
  35.                     isRunning = false;
  36.                     Application.Exit();
  37.                 }    
  38.             }
  39.         }
  40.  
  41.         protected override void OnKeyDown(KeyEventArgs e)
  42.         {
  43.             base.OnKeyDown(e);
  44.             switch (e.KeyCode)
  45.             {
  46.                 case (Keys.W):
  47.                     isWKeyDown = true;
  48.                     break;
  49.                 case (Keys.S):
  50.                     isSKeyDown = true;
  51.                     break;
  52.                 case (Keys.A):
  53.                     isAKeyDown = true;
  54.                     break;
  55.                 case (Keys.D):
  56.                     isDKeyDown = true;
  57.                     break;
  58.             }
  59.         }
Advertisement
Add Comment
Please, Sign In to add comment