Advertisement
Guest User

game maker code

a guest
Dec 1st, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1.  
  2.  
  3. jump_grav = -9;
  4. if !place_meeting(x,y+1,block_items) // if I am in the air
  5. {
  6. grav = .5; // set the gravity to .5
  7. vspd += grav; // add .5 to our vspd once every step
  8. }
  9. else // else if I am on the ground
  10. {
  11. grav = 0; // set the gravity to 0
  12. vspd = 0; // set vspd to 0 to stop moving
  13. if keyboard_check_pressed(vk_up) // since I am on the ground, I can handle jumping here, so check if I pressed up
  14. {
  15. vspd = jump_grav; // set the vspd to a negative number, which will make us jump
  16. }
  17. }
  18. if keyboard_check_released(vk_up) // if I released the up button while in the in air
  19. {
  20. vspd *= .5; // divide our vspd by 2, creating a smooth type of variable jumping
  21. }
  22. if vspd > 8 // I don't want to fall too fast, so lets limit our vspd
  23. {
  24. vspd = 8; // note that if you want to be able to fall fast, you can remove this without affecting the code (but I wouldn't)
  25. }
  26. repeat(abs(vspd)) // I want to check for a collision every pixel, so I use a repeat() function to check every pixel while falling
  27. {
  28. if !place_meeting(x,y+sign(vspd),block_items) // vspd can be negative or positive, so I check 1 pixel above or below, depending on which direction I am going
  29. {
  30. y += sign(vspd); // add to our y value 1 pixel at a time, letting use check for a collision every pixel
  31. }
  32. else // else if I hit a block
  33. {
  34. vspd = 0; // stop moving vertically
  35. }
  36. }
  37. hspd = (keyboard_check(vk_right)-keyboard_check(vk_left))*4; // a nice little trick that will set our hspd to +4 or -4 depending what button I am holding
  38. repeat(abs(hspd)) // same as the vspd, I want to check for a collision at every pixel I move
  39. {
  40. if !place_meeting(x+sign(hspd),y,block_items) // if there is no block to our left or right
  41. {
  42. x += sign(hspd); // add to our x value depending on which way I am going
  43. } else if place_meeting(x+sign(hspd),y,bi_allow_colide){
  44. x += sign(hspd);
  45. hspd = 0;
  46. }
  47. if (hspd==-4)
  48. {
  49. lastwalk = 1;
  50. }
  51. if (hspd==4)
  52. {
  53. lastwalk = 2;
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement