Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.36 KB | None | 0 0
  1. app.KeyPressed += (sender, e) =>
  2. {
  3. if (a == 3)
  4. {
  5. if (Mark.GetGlobalBounds().Intersects(Ball.GetGlobalBounds()))
  6. {
  7. if (!dictionary.ContainsKey("ball"))
  8. {
  9. dictionary.Add("ball", Ball);
  10. }
  11. //the same with the A, S and D
  12. } // I don't know if is Global or Local
  13. /*if (e.Code == Keyboard.Key.W && Mark.Position.Y == Ball.Position.Y - 40 && Mark.Position.X <= Ball.Position.X + 30 && Mark.Position.X >= Ball.Position.X - 30)
  14. {
  15. Ball.Position = new Vector2f(Mark.Position.X + 10, Ball.Position.Y - 60);
  16. }
  17. if (e.Code == Keyboard.Key.S && Mark.Position.Y == Ball.Position.Y - 80 && Mark.Position.X <= Ball.Position.X + 40 && Mark.Position.X >= Ball.Position.X - 40)
  18. {
  19. Ball.Position = new Vector2f(Mark.Position.X + 10, Ball.Position.Y + 100);
  20. }
  21. if (e.Code == Keyboard.Key.D && Mark.Position.X >= Ball.Position.X - 40 && Mark.Position.X <= Ball.Position.X && Mark.Position.Y == Ball.Position.Y - 60)
  22. {
  23. Ball.Position = new Vector2f(Ball.Position.X + 60, Ball.Position.Y);
  24. }
  25. if (e.Code == Keyboard.Key.A && Mark.Position.X >= Ball.Position.X - 20 && Mark.Position.X <= Ball.Position.X + 20 && Mark.Position.Y == Ball.Position.Y - 60)
  26. {
  27. Ball.Position = new Vector2f(Ball.Position.X - 40, Ball.Position.Y);
  28. }*/
  29. if (e.Code == Keyboard.Key.W)
  30. {
  31. if (Keyboard.IsKeyPressed(Keyboard.Key.W))
  32. {
  33. UpPressed = true;
  34. }
  35. target = MarkUp;
  36. if (frametimer > 1)
  37. {//Change texture every second. Use smaller number if it should be faster
  38. frame = ++frame % target.Length;//Keep frame between 0 and target.Length
  39. Mark.Texture = target[frame];
  40. frametimer %= 1;
  41. }
  42. if (DownPressed == true)
  43. {
  44. Ball.Position = new Vector2f(Mark.Position.X, Mark.Position.Y - 32);
  45. DownPressed = false;
  46. RightPressed = false;
  47. LeftPressed = false;
  48. }
  49. if (RightPressed == true)
  50. {
  51. Ball.Position = new Vector2f(Mark.Position.X, Mark.Position.Y - 32);
  52. DownPressed = false;
  53. RightPressed = false;
  54. LeftPressed = false;
  55. }
  56. if (LeftPressed == true)
  57. {
  58. Ball.Position = new Vector2f(Mark.Position.X, Mark.Position.Y - 32);
  59. DownPressed = false;
  60. RightPressed = false;
  61. LeftPressed = false;
  62. }
  63. view.Center = new Vector2f(Mark.Position.X, Mark.Position.Y - 10);
  64. app.SetView(view);
  65. //view.Move(new Vector2f(view.Center.X, view.Center.Y - 20));
  66. }
  67. if (e.Code == Keyboard.Key.S)
  68. {
  69. if (Keyboard.IsKeyPressed(Keyboard.Key.S))
  70. {
  71. DownPressed = true;
  72. }
  73. target = MarkDown;
  74. if (frametimer > 1)
  75. {//Change texture every second. Use smaller number if it should be faster
  76. frame = ++frame % target.Length;//Keep frame between 0 and target.Length
  77. Mark.Texture = target[frame];
  78. frametimer %= 1;
  79. }
  80. if (UpPressed == true)
  81. {
  82. Ball.Position = new Vector2f(Mark.Position.X, Mark.Position.Y + 128);
  83. UpPressed = false;
  84. RightPressed = false;
  85. LeftPressed = false;
  86. }
  87. if (RightPressed == true)
  88. {
  89. Ball.Position = new Vector2f(Mark.Position.X, Mark.Position.Y + 128);
  90. DownPressed = false;
  91. RightPressed = false;
  92. LeftPressed = false;
  93. }
  94. if (LeftPressed == true)
  95. {
  96. Ball.Position = new Vector2f(Mark.Position.X, Mark.Position.Y + 128);
  97. DownPressed = false;
  98. RightPressed = false;
  99. LeftPressed = false;
  100. }
  101. view.Center = new Vector2f(Mark.Position.X, Mark.Position.Y + 10);
  102. app.SetView(view);
  103. }
  104.  
  105. int i = 0;
  106. if (e.Code == Keyboard.Key.A)
  107. {
  108. if (Keyboard.IsKeyPressed(Keyboard.Key.A))
  109. {
  110. LeftPressed = true;
  111. }
  112. target = MarkRight;
  113. if (frametimer > 1)
  114. {//Change texture every second. Use smaller number if it should be faster
  115. frame = ++frame % target.Length;//Keep frame between 0 and target.Length
  116. Mark.Texture = target[frame];
  117. frametimer %= 1;
  118. }
  119. if (DownPressed == true)
  120. {
  121. Ball.Position = new Vector2f(Mark.Position.X - 72, Mark.Position.Y + 60);
  122. DownPressed = false;
  123. RightPressed = false;
  124. UpPressed = false;
  125. }
  126. if (RightPressed == true)
  127. {
  128. Ball.Position = new Vector2f(Mark.Position.X - 64, Mark.Position.Y + 72);
  129. DownPressed = false;
  130. RightPressed = false;
  131. UpPressed = false;
  132. }
  133. if (UpPressed == true)
  134. {
  135. Ball.Position = new Vector2f(Mark.Position.X - 32, Mark.Position.Y + 32 + 32);
  136. DownPressed = false;
  137. RightPressed = false;
  138. UpPressed = false;
  139. }
  140. view.Center = new Vector2f(Mark.Position.X - 5, Mark.Position.Y);
  141. app.SetView(view);
  142. }
  143. if (e.Code == Keyboard.Key.D)
  144. {
  145. if (Keyboard.IsKeyPressed(Keyboard.Key.D))
  146. {
  147. RightPressed = true;
  148. }
  149. target = MarkLeft;
  150. if (frametimer > 1)
  151. {//Change texture every second. Use smaller number if it should be faster
  152. frame = ++frame % target.Length;//Keep frame between 0 and target.Length
  153. Mark.Texture = target[frame];
  154. frametimer %= 1;
  155. }
  156. if (UpPressed == true)
  157. {
  158. Ball.Position = new Vector2f(Mark.Position.X + 32, Mark.Position.Y + 96);
  159. DownPressed = false;
  160. LeftPressed = false;
  161. UpPressed = false;
  162. }
  163. if (DownPressed == true)
  164. {
  165. Ball.Position = new Vector2f(Mark.Position.X + 32, Mark.Position.Y + 50);
  166. DownPressed = false;
  167. LeftPressed = false;
  168. UpPressed = false;
  169. }
  170. if (LeftPressed == true)
  171. {
  172. Ball.Position = new Vector2f(Mark.Position.X + 32, Mark.Position.Y + 64);
  173. DownPressed = false;
  174. LeftPressed = false;
  175. UpPressed = false;
  176. }
  177. view.Center = new Vector2f(Mark.Position.X + 5, Mark.Position.Y);
  178. app.SetView(view);
  179. }
  180. foreach (KeyValuePair<string, Sprite> pair in dictionary)
  181. {
  182. if (Keyboard.IsKeyPressed(Keyboard.Key.W))
  183. {
  184. pair.Value.Position = new Vector2f(pair.Value.Position.X, pair.Value.Position.Y - 20);
  185. }
  186. if (Keyboard.IsKeyPressed(Keyboard.Key.A))
  187. {
  188. pair.Value.Position = new Vector2f(pair.Value.Position.X - 20, pair.Value.Position.Y);
  189. }
  190. if (Keyboard.IsKeyPressed(Keyboard.Key.S))
  191. {
  192. pair.Value.Position = new Vector2f(pair.Value.Position.X, pair.Value.Position.Y + 20);
  193. }
  194. if (Keyboard.IsKeyPressed(Keyboard.Key.D))
  195. {
  196. pair.Value.Position = new Vector2f(pair.Value.Position.X + 20, pair.Value.Position.Y);
  197. }
  198. }
  199. }
  200. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement