SHARE
TWEET

NOT WORKING - movement, running, jumping and gravity

P101 Aug 20th, 2017 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. key_left = keyboard_check(vk_left);
  2. key_right = keyboard_check(vk_right);
  3. key_jump = keyboard_check_pressed(vk_space);
  4. key_run = keyboard_check(vk_shift);
  5.  
  6. // HORIZONTAL MOVEMENT
  7. var move = key_right - key_left;
  8.  
  9. hspd = move * (key_run ? runSpeed : walkSpeed);
  10.  
  11. if (move == 0) {
  12.     sprite_index = spr_beast_stand_right;
  13. } else if (move == 1) {
  14.     sprite_index = key_run ? spr_beast_run_right : spr_beast_walk_right;
  15. } else {
  16.     sprite_index = key_run ? spr_beast_run_left : spr_beast_walk_left;
  17. }
  18.  
  19. // Horizontal collision
  20. if (place_meeting(x+hspd, y, objNormalWall)) {
  21.     while (!place_meeting(x+sign(hspd),y, objNormalWall)) {
  22.         x+=sign(hspd);
  23.     }
  24.     hspd = 0;
  25. }
  26. x+=hspd;
  27.  
  28. // GRAVITY AND JUMP
  29.  
  30. if (place_meeting(x,y+1,objNormalWall) && key_jump) {
  31.     vspd = -jumpspeed;
  32. }
  33.  
  34. vspd = vspd + grv;
  35.  
  36. if (place_meeting(x, y+vspd, objNormalWall)) {
  37.     while (!place_meeting(x,y+sign(vspd), objNormalWall)) {
  38.         y+=sign(vspd);
  39.     }
  40.     vspd = 0;
  41. }
  42. y+=vspd;
RAW Paste Data
Top