Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. /// @description movement
  2. // input
  3.  
  4. /*
  5. var rkey = keyboard_check(vk_right);
  6. var lkey = keyboard_check(vk_left);
  7.  
  8. // move right
  9. if (rkey) {
  10. if (hsp < max_speed) {
  11. hsp += acc;
  12. } else {
  13. hsp = max_speed;
  14. }
  15. }
  16.  
  17. // move left
  18. if (lkey) {
  19. if (hsp > max_speed) {
  20. hsp -= acc;
  21. } else {
  22. hsp = -max_speed;
  23. }
  24. }
  25.  
  26. */
  27.  
  28.  
  29.  
  30.  
  31.  
  32. /*
  33. // acceleration
  34. if (move !=0)
  35. {
  36.  
  37. if (walksp < max_speed)
  38. {
  39. walksp += acc;
  40. }
  41.  
  42. else
  43. {
  44. walksp = max_speed;
  45. }
  46.  
  47.  
  48.  
  49. if (walksp > -max_speed)
  50. {
  51. walksp -= acc;
  52. }
  53.  
  54. else
  55. {
  56. walksp = -max_speed;
  57. }
  58.  
  59. }
  60.  
  61.  
  62.  
  63. if (move = 0)
  64. {
  65. if (walksp != 0)
  66. {
  67. if (walksp < 0)
  68. {
  69. walksp += acc;
  70. }
  71. else
  72. {
  73. walksp -= acc;
  74. }
  75. }
  76. }
  77. */
  78.  
  79.  
  80. // check if keys are pressed
  81. key_left = keyboard_check(vk_left) || keyboard_check(ord("A"));
  82. key_right = keyboard_check(vk_right) || keyboard_check(ord("D"));
  83. key_jump = keyboard_check_pressed(vk_space);
  84. key_jump_held = keyboard_check(vk_space);
  85.  
  86.  
  87.  
  88. // movement
  89. var move = key_right - key_left;
  90.  
  91.  
  92. // acceleration
  93. if (move == -1 || move == 1)
  94. {
  95. if (walksp < max_speed)
  96. {
  97. walksp += acc;
  98. }
  99. }
  100.  
  101. else
  102. {
  103. //walksp = 0;
  104. if (walksp > 0)
  105. walksp -= acc;
  106. }
  107.  
  108. //if (move == 0)
  109. // hsp = 0;
  110.  
  111. // deceleration
  112. if (move != 0)
  113. hsp = move * walksp
  114.  
  115. else
  116. {
  117. if (hsp > 0)
  118. hsp = walksp;
  119. else
  120. {
  121. if (hsp < 0)
  122. hsp = -walksp;
  123. }
  124. }
  125. //show_debug_message(hsp);
  126.  
  127.  
  128.  
  129. // gravity
  130. vsp = vsp + grv;
  131.  
  132.  
  133.  
  134. // jump
  135. if (place_meeting(x,y+1,oWall)) && (key_jump)
  136. {
  137. vsp = -7;
  138. }
  139.  
  140. if (vsp < 0) && (!key_jump_held) vsp = max(vsp,-2)
  141.  
  142.  
  143.  
  144. // horizontal collision
  145. if (place_meeting(x+hsp,y,oWall))
  146. {
  147. while (!place_meeting(x+sign(hsp),y,oWall))
  148. {
  149. x = x + sign(hsp);
  150. }
  151. hsp = 0;
  152. }
  153. x = x + hsp;
  154.  
  155.  
  156. // vertical collision
  157. if (place_meeting(x,y+vsp,oWall))
  158. {
  159. while (!place_meeting(x,y+sign(vsp),oWall))
  160. {
  161. y = y + sign(vsp);
  162. }
  163. vsp = 0;
  164. }
  165. y = y + vsp;
  166.  
  167.  
  168.  
  169. // animation
  170. if (!place_meeting(x,y+1,oWall))
  171. {
  172. sprite_index = sPlayerA;
  173. image_speed = 0;
  174. if (sign(vsp) > 0) image_index = 1; else image_index = 0;
  175. }
  176.  
  177. else
  178. {
  179. image_speed = 1;
  180. if (hsp == 0)
  181. {
  182. sprite_index = sPlayer;
  183. }
  184. else
  185. {
  186. sprite_index = sPlayerR;
  187. }
  188. }
  189.  
  190. if (hsp != 0) image_xscale = sign(hsp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement