Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Input and Keyboard Events
- /// <summary>
- /// Handle player movement on screen, as well as some extra collision detection.
- /// </summary>
- public void HandleMovement()
- {
- if (isWKeyDown)
- {
- player.Move(Direction.NORTH);
- }
- if (isSKeyDown)
- {
- player.Move(Direction.SOUTH);
- }
- if (isAKeyDown)
- {
- player.Move(Direction.WEST);
- }
- if (isDKeyDown)
- {
- player.Move(Direction.EAST);
- }
- // Check for wall collision in player input.
- if (playerRectangle.IntersectsWith(winRectangle))
- {
- var dialog = MessageBox.Show("Congratulations! You have won! Play again?", TITLE, MessageBoxButtons.YesNo);
- if (dialog == DialogResult.Yes)
- {
- // restart the game here.
- }
- else if (dialog == DialogResult.No)
- {
- isRunning = false;
- Application.Exit();
- }
- }
- }
- protected override void OnKeyDown(KeyEventArgs e)
- {
- base.OnKeyDown(e);
- switch (e.KeyCode)
- {
- case (Keys.W):
- isWKeyDown = true;
- break;
- case (Keys.S):
- isSKeyDown = true;
- break;
- case (Keys.A):
- isAKeyDown = true;
- break;
- case (Keys.D):
- isDKeyDown = true;
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment