Guest User

Untitled

a guest
Nov 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace Game_deel1
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18. bool hoogte = true;
  19. bool breedte = true;
  20.  
  21. private void Form1_KeyDown(object sender, KeyEventArgs e)
  22. {
  23. this.Text = (e.KeyCode.ToString());
  24. int x = pbPlayer.Location.X;
  25. int y = pbPlayer.Location.Y;
  26.  
  27. switch (e.KeyCode.ToString())
  28. {
  29. case "A":
  30. x -= 10;
  31. if (x < 0)
  32. {
  33. x = 0;
  34. }
  35. break;
  36. case "S":
  37. y += 10;
  38. if (y > 300 - pbPlayer.Height)
  39. {
  40. y = 300 - pbPlayer.Height;
  41. }
  42. break;
  43. case "D":
  44. x += 10;
  45. if (x > 600 - pbPlayer.Width - 16)
  46. {
  47. x = 600 - pbPlayer.Width - 16;
  48. }
  49. break;
  50. case "W":
  51. y -= 10;
  52. if (y < 0)
  53. {
  54. y = 0;
  55. }
  56. break;
  57. default:
  58. break;
  59. }
  60. pbPlayer.Location = new System.Drawing.Point(x, y);
  61. }
  62.  
  63. private void timer1_Tick(object sender, EventArgs e)
  64. {
  65. if (breedte == true && hoogte == true)
  66. {
  67. pbBal.Location = new Point(pbBal.Location.X +1, pbBal.Location.Y +1);
  68. if (pbBal.Location.Y > 350 - pbBal.Height - 40)
  69. {
  70. hoogte = false;
  71. this.Text = "Dood";
  72. }
  73. if (pbBal.Location.X > 600 - pbBal.Width - 16)
  74. {
  75. breedte = false;
  76. }
  77. }
  78. if (breedte == true && hoogte == false)
  79. {
  80. pbBal.Location = new Point(pbBal.Location.X +1, pbBal.Location.Y -1);
  81. if (pbBal.Location.Y < 0)
  82. {
  83. hoogte = true;
  84. }
  85. if (pbBal.Location.X > 600 - pbBal.Width - 16)
  86. {
  87. breedte = false;
  88. }
  89. }
  90. if (breedte == false && hoogte == true)
  91. {
  92. pbBal.Location = new Point(pbBal.Location.X -1, pbBal.Location.Y +1);
  93. if (pbBal.Location.Y > 350 - pbBal.Height - 40)
  94. {
  95. hoogte = false;
  96. this.Text = "Dood";
  97. }
  98. if (pbBal.Location.X <0)
  99. {
  100. breedte = true;
  101. }
  102. }
  103. if (breedte == false && hoogte == false)
  104. {
  105. pbBal.Location = new Point(pbBal.Location.X -1, pbBal.Location.Y -1);
  106. if (pbBal.Location.Y < 0)
  107. {
  108. hoogte = true;
  109. }
  110. if (pbBal.Location.X < 0)
  111. {
  112. breedte = true;
  113. }
  114. }
  115. if ((pbBal.Location.Y + pbBal.Height == pbPlayer.Location.Y) &&
  116. (pbBal.Location.X + pbBal.Width > pbPlayer.Location.X) &&
  117. (pbBal.Location.X + pbBal.Width < pbPlayer.Location.X + pbPlayer.Width))
  118. {
  119. hoogte = false;
  120. }
  121. // if ()
  122. }
  123. }
  124. }
Add Comment
Please, Sign In to add comment