SirCumferance

Movement

May 4th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /Player movement  
  2. key_left = keyboard_check(vk_left);
  3. key_right = keyboard_check(vk_right);
  4. key_jump = keyboard_check(vk_space);
  5.  
  6. // Calculate movement
  7. var move = key_right - key_left;
  8.  
  9. hsp = move * walkspd;
  10.  
  11. vsp = vsp + grv;
  12.  
  13. if (place_meeting(x, y+1,oWall)) && (key_jump)
  14. {
  15.     vsp = -7;
  16.      show_debug_message("Jumping from wall!");
  17. }
  18.  
  19. if (place_meeting(x, y+1,oFloor)) && (key_jump)
  20. {
  21.     vsp = -7;
  22.     show_debug_message("Jumping from floor!");
  23. }
  24.  
  25. if (place_meeting(x, y+1,oDirt)) && (key_jump)
  26. {
  27.     vsp = -7;
  28.     show_debug_message("Jumping from floor!");
  29. }
  30.  
  31. //horizontal collision
  32. if (place_meeting(x + hsp,y,oFloor))
  33. {
  34.     while (!place_meeting(x+sign(hsp),y,oFloor))
  35.     {
  36.         x = x + sign(hsp);
  37.     }
  38.     hsp = 0
  39. }
  40.  
  41. if (place_meeting(x + hsp,y,oDirt))
  42. {
  43.     while (!place_meeting(x+sign(hsp),y,oDirt))
  44.     {
  45.         x = x + sign(hsp);
  46.     }
  47.     hsp = 0
  48. }
  49.  
  50. if (place_meeting(x + hsp, y, oWall))
  51. {
  52.     while (!place_meeting(x+sign(hsp), y, oWall))
  53.     {
  54.         x = x + sign(hsp);
  55.     }
  56.     hsp = 0;
  57. }
  58.  
  59. if (place_meeting(x + hsp, y, oStone))
  60. {
  61.     while (!place_meeting(x+sign(hsp), y, oStone))
  62.     {
  63.         x = x + sign(hsp);
  64.     }
  65.     hsp = 0;
  66. }
  67.  
  68. x = x + hsp;
  69.  
  70. //vertical collision
  71. if (place_meeting(x,y + vsp,oFloor))
  72. {
  73.     while (!place_meeting(x,y+sign(vsp),oFloor))
  74.     {
  75.         y = y + sign(vsp);
  76.     }
  77.     vsp = 0;
  78. }
  79.  
  80. if (place_meeting(x,y + vsp,oStone))
  81. {
  82.     while (!place_meeting(x,y+sign(vsp),oStone))
  83.     {
  84.         y = y + sign(vsp);
  85.     }
  86.     vsp = 0;
  87. }
  88.  
  89. if (place_meeting(x,y + vsp,oDirt))
  90. {
  91.     while (!place_meeting(x,y+sign(vsp),oDirt))
  92.     {
  93.         y = y + sign(vsp);
  94.     }
  95.     vsp = 0;
  96. }
  97.  
  98.  
  99. if (place_meeting(x,y + vsp, oWall))
  100. {
  101.     while (!place_meeting(x,y+sign(vsp),oWall))
  102.     {
  103.         y = y + sign(vsp);
  104.     }
  105.     vsp = 0;
  106. }
  107. y = y + vsp;
  108.  
  109. //animation
  110. if (!place_meeting(x,y+1,oWall))
  111. {
  112.     sprite_index = sPlayerW;
  113.     image_speed = 0;
  114.     if (sign(vsp) > 0) image_index = 1; else image_index = 0;
  115. }
  116.  
  117. else {
  118.     image_speed = 1
  119.     if (hsp == 0)
  120.     {
  121.         sprite_index = sPlayer;
  122.     }
  123.     else
  124.     {
  125.         sprite_index = sPlayerA;
  126.     }
  127.    
  128. }
  129.  
  130. if (!place_meeting(x,y+1,oFloor))
  131. {
  132.     sprite_index = sPlayerW;
  133.     image_speed = 0;
  134.     if (sign(vsp) > 0) image_index = 1; else image_index = 0;
  135. }
  136.  
  137. else {
  138.     image_speed = 1
  139.     if (hsp == 0)
  140.     {
  141.         sprite_index = sPlayer;
  142.     }
  143.     else
  144.     {
  145.         sprite_index = sPlayerA;
  146.     }
  147.    
  148. }
  149.  
  150. if (!place_meeting(x,y+1,oStone))
  151. {
  152.     sprite_index = sPlayerW;
  153.     image_speed = 0;
  154.     if (sign(vsp) > 0) image_index = 1; else image_index = 0;
  155. }
  156.  
  157. else {
  158.     image_speed = 1
  159.     if (hsp == 0)
  160.     {
  161.         sprite_index = sPlayer;
  162.     }
  163.     else
  164.     {
  165.         sprite_index = sPlayerA;
  166.     }
  167.    
  168. }
Add Comment
Please, Sign In to add comment