Advertisement
Ensphere

Untitled

Jan 23rd, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. ///CREATE EVENT ///
  2. ///Player Variables
  3.  
  4. // PLAYER MOVEMENT //
  5. dashing = false
  6.  
  7.  
  8. //speeds
  9. max_speed = 30;
  10. min_speed = 0;
  11. acc_speed = 2;
  12. //final speeds
  13. final_xspeed = 0;
  14. final_yspeed = 0;
  15. image_speed = 0;
  16.  
  17. _start_x = x;
  18. _start_y = y;
  19. _move_speed = 8;
  20.  
  21.  
  22. mx = mouse_x;
  23. my = mouse_y;
  24.  
  25. _movement_direction = point_direction(_start_x, _start_y, mx, my)
  26.  
  27.  
  28. /// STEP EVENT ///
  29.  
  30. /// PLAYER MOVMENT ///
  31.  
  32.  
  33. //dashing (copy to script later)
  34. m_pressD = mouse_check_button_pressed(mb_left);
  35. m_pressR = mouse_check_button_released(mb_left);
  36. debr =keyboard_check(vk_space); /// just for testing
  37. if m_pressD && !dashing
  38. {
  39. /// LANDING CALCULATION GOES HERE LATER ///
  40. mx = mouse_x;
  41. my = mouse_y;
  42.  
  43. _movement_direction = point_direction(_start_x, _start_y, mx, my)
  44.  
  45. }else if m_pressR
  46. {
  47. dashing = true;
  48. image_index = 1;
  49. }
  50.  
  51. if dashing
  52. {
  53.  
  54. _move_speed += acc_speed;
  55.  
  56. final_xspeed = lengthdir_x(clamp(_move_speed,min_speed,max_speed), _movement_direction)
  57.  
  58. final_yspeed = lengthdir_y(clamp(_move_speed,min_speed,max_speed), _movement_direction)
  59.  
  60.  
  61.  
  62.  
  63.  
  64. }else
  65. {
  66. final_xspeed = 0;
  67. final_yspeed = 0;
  68. }
  69.  
  70.  
  71. x += final_xspeed;
  72.  
  73. y += final_yspeed;
  74.  
  75.  
  76.  
  77.  
  78.  
  79. if debr dashing = false;
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. /// COLLISION STUFF ///
  87.  
  88.  
  89.  
  90. sprite_bbox_top = bbox_top - y;
  91. sprite_bbox_bottom = bbox_bottom - y;
  92. sprite_bbox_right = bbox_right - x;
  93. sprite_bbox_left = bbox_left - x;
  94.  
  95. //Horizontal collisions
  96. x += final_xspeed;
  97.  
  98. //Snap
  99. if place_meeting(x, y, obj_solid) {
  100. var wall = instance_place(x,y,obj_solid);
  101. if (final_xspeed > 0) { //right
  102.  
  103. x = (wall.bbox_left-1) - sprite_bbox_right;
  104. } else if (final_xspeed < 0) { //left
  105. x = (wall.bbox_right+1)-sprite_bbox_left;
  106. }
  107.  
  108. dashing = false;
  109. final_xspeed = -_move_speed
  110.  
  111.  
  112.  
  113.  
  114.  
  115. }
  116.  
  117. //Vertical collisions
  118. y += final_yspeed;
  119.  
  120. //Snap
  121. if place_meeting(x, y, obj_solid) {
  122. var wall = instance_place(x, y, obj_solid);
  123. if (final_yspeed > 0) { //down
  124. y = (wall.bbox_top-1) - sprite_bbox_bottom;
  125. } else if (final_yspeed < 0) { //up
  126. y = (wall.bbox_bottom+1) - sprite_bbox_top;
  127. }
  128. if (coll)
  129. {
  130. dashing = false;
  131. final_yspeed = -_move_speed
  132.  
  133.  
  134. }
  135.  
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement