rooksword

Platformer Movement Code

Nov 29th, 2020
707
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///Movement
  2.  
  3. // Get input
  4. keyboard_set_map(ord("W"), vk_up);
  5. keyboard_set_map(ord("A"), vk_left);
  6. keyboard_set_map(ord("D"), vk_right);
  7.  
  8. key_right = keyboard_check(vk_right);
  9. key_left = -keyboard_check(vk_left);
  10. key_jump += buffer*keyboard_check_pressed(vk_up);
  11. if key_jump > 0 key_jump--;
  12.  
  13. move = key_left + key_right;
  14. hsp = lerp(hsp,move * spd, acc);
  15.  
  16. if vsp < 10 vsp += grav;
  17.  
  18. if place_meeting(x, y + 1, obj_wall)
  19. {
  20.     if key_jump > 0
  21.     {
  22.         vsp = sign(key_jump) * -jspd;
  23.         key_jump = 0;
  24.     }
  25. }
  26.  
  27. //Collisions
  28. if place_meeting(x + hsp, y, obj_wall)
  29. {
  30.     while (!place_meeting(x+sign(hsp),y, obj_wall))
  31.     {
  32.         x += sign(hsp);
  33.     }
  34.     hsp = 0;
  35. }
  36. x += hsp;
  37.  
  38. if place_meeting(x, y + vsp, obj_wall)
  39. {
  40.     while !place_meeting(x, y + sign(vsp), obj_wall)
  41.     {
  42.         y += sign(vsp);
  43.     }
  44.     vsp = 0;
  45. }
  46. y += vsp;
RAW Paste Data