Advertisement
xolta

platfromer movement

Feb 7th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. Crate event
  2.  
  3. ///player variables
  4. grav = 0.3;
  5. hsp = 0;
  6. vsp = 0;
  7. movespeed = 4;
  8.  
  9. jumpspeed_normal = 7;
  10. jumspeed_powerup = 10;
  11.  
  12. jumpspeed = jumpspeed_normal;
  13. gamepad_set_axis_deadzone(0,0.7);
  14.  
  15.  
  16.  
  17. Step event
  18.  
  19. ///movement
  20. // Player input
  21. key_right = keyboard_check(vk_right) || (gamepad_axis_value(0,gp_axislh) > 0);
  22. key_left = -(keyboard_check(vk_left) || (gamepad_axis_value(0,gp_axislh) < 0));
  23. key_jump = keyboard_check_pressed(vk_space) || gamepad_button_check_pressed(0,gp_face1);
  24.  
  25. //React to inputs
  26. move = key_left + key_right;
  27. hsp = move * movespeed;
  28. if (vsp < 10) vsp += grav;
  29.  
  30. if (place_meeting(x,y+1,obj_platfroms))
  31. {
  32. vsp = key_jump * -jumpspeed;
  33. }
  34.  
  35. //horzontial colsion
  36. if (place_meeting(x+hsp,y,obj_platfroms))
  37. {
  38. while(!place_meeting(x+sign(hsp),y,obj_platfroms))
  39. {
  40. x += sign(hsp);
  41. }
  42. hsp = 0;
  43. }
  44. x += hsp;
  45.  
  46. //vertical colsion
  47. if (place_meeting(x,y+vsp,obj_platfroms))
  48. {
  49. while(!place_meeting(x,y+sign(vsp),obj_platfroms))
  50. {
  51. y += sign(vsp);
  52. }
  53. vsp = 0;
  54. }
  55. y += vsp;
  56.  
  57.  
  58. wasd movement
  59.  
  60. //movement
  61.  
  62. var xDirection, yDirection;
  63. xDirection = keyboard_check(ord("D"))- keyboard_check(ord("A"));
  64. yDirection = keyboard_check(ord("S"))- keyboard_check(ord("W"));
  65.  
  66. x += xDirection * 3
  67. y += yDirection * 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement