Advertisement
Guest User

Untitled

a guest
Apr 14th, 2014
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Create Event
  2. grav = 0.2;
  3. hsp = 0;
  4. vsp = 0;
  5. jumpspeed = 7;
  6. movespeed = 4;
  7. djump=0;
  8. fric=2;
  9.  
  10.  
  11. ///Step Event
  12. key_right = keyboard_check(vk_right);
  13. key_left = -keyboard_check(vk_left);
  14. key_jump = keyboard_check_pressed(vk_space);
  15.  
  16. //Sprite direction
  17. if hsp < 0
  18. {
  19.     image_xscale = -1
  20. }
  21.  
  22. if hsp > 0
  23. {
  24.     image_xscale = 1
  25. }
  26.  
  27. //React to inputs
  28. move = key_left + key_right; //Because left or right can only be 1 or -1 then adding both makes move = 0
  29. if(move!=0){hsp = move * movespeed; }
  30.  
  31. if (vsp < 10) vsp += grav;
  32.  
  33. //Friction
  34. var fricActive;
  35. fricActive = fric * (key_left + key_right != 0) * place_meeting(x,y+1,par_wall)
  36.    
  37. //Applies Friction fricActive represents how much friction we apply while fric represents the baseline amount of friction
  38. hsp = max(abs(hsp) - fricActive, 0) * sign(hsp);
  39.  
  40. //for Jumping
  41. if(key_jump)
  42. {
  43. if(place_meeting(x,y+1,par_wall))
  44.     {
  45.     vsp=key_jump * -jumpspeed;
  46.     djump=1;
  47.     }
  48.     else
  49.     {
  50.     if(djump=1)
  51.     {
  52.         vsp=key_jump * -jumpspeed+1;
  53.         djump=0;
  54.         }
  55.     }
  56. }
  57.    
  58. //Horizontal Collision
  59. if (place_meeting(x+hsp,y,par_wall))
  60. {
  61.     while(!place_meeting(x+sign(hsp),y,par_wall))
  62.     {
  63.         x += sign(hsp);
  64.     }
  65.     hsp = 0;
  66. }
  67. else
  68. x += hsp;
  69.  
  70. //Vertical Collision
  71. if (place_meeting(x,y+vsp,par_wall))
  72. {
  73.     while(!place_meeting(x,y+sign(vsp),par_wall)) y += sign(vsp);
  74.     {
  75.     vsp=0;
  76.     }
  77. }
  78. else
  79. y += vsp;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement