Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //We use these so we can just type the variables.
  2. //Instead of "keyboard_check(*)".
  3. KEY_RIGHT=keyboard_check(vk_right);
  4. KEY_LEFT=keyboard_check(vk_left);
  5. KEY_JUMP=keyboard_check_pressed(vk_up);
  6. KEY_ATTACK=keyboard_check_pressed(ord("A"));
  7. KEY_FALL=keyboard_check_released(vk_up); //This one's for variable jump height:
  8.  
  9. //Vertical movements.
  10. //Is the player in the air?
  11. if (place_meeting(x,y+1,objBlock)) grounded=1;
  12. else grounded=0;
  13.  
  14. //Jump with the up key when on the ground.
  15. if (KEY_JUMP and grounded)
  16. {
  17.     vsp=jumpsp;
  18. }
  19.  
  20. //If we're in air moving up and jump key is released, we remove
  21. //upward motion (So we fall and get variable jump height.)
  22. if (KEY_FALL and !grounded and vsp<-1) vsp=-1;
  23.  
  24. //Fall with gravity.
  25. if (!grounded) vsp+=grav;
  26.  
  27. //Now it's more complicated.
  28. //When hitting the ceiling, vertical speed must stop.
  29. //The if statement says, "if we hit the ceiling and are moving up"
  30.  
  31.  
  32. if (place_meeting(x,y+vsp,objBlock) && vsp<0)
  33. {
  34.     //We must move up until contact with the ceiling.
  35.     while (!place_meeting(x,y+sign(vsp),objBlock)) y+=sign(vsp);
  36.     vsp=0;
  37. }
  38.  
  39. //But if we are moving down and hit the floor, we have to land.
  40. if (place_meeting(x,y+vsp,objBlock) and vsp>0)
  41. {
  42.     //Move so we hit the ground.
  43.     var cc;
  44.     cc=vsp+1; //A counter, so we don't get an infinite loop
  45.  
  46.      //Move down until we hit the floor.
  47.     while (!place_meeting(x,y+1,objBlock) and cc>=0) y+=1;
  48.  
  49.      //Now ground the player.
  50.     grounded=1;
  51.  
  52.     vsp=0;
  53. }
  54.  
  55. //Again, we're not using vspeed, so we have to move ourselves.
  56. y+=vsp;
  57.  
  58. //Now for horizontal movements.
  59.  
  60. //Now check if the player pressed left or right and move.
  61. if (KEY_RIGHT)
  62. {
  63.     hsp=walksp; //Walk right.
  64.     image_xscale=1; //Face right.
  65. }
  66.  
  67. if (KEY_LEFT)
  68. {
  69.     hsp=-walksp; //Walk left.
  70.     image_xscale=-1; //Face left.
  71. }
  72.  
  73. //Stop moving when no keys are pressed.
  74. if (!KEY_RIGHT and !KEY_LEFT) hsp=0 stand=1;
  75.  
  76. //Make sure we don't hit a wall.
  77. if (place_meeting(x+hsp,y,objBlock))
  78. {
  79.     //Move until contact with the wall.
  80.     if (hsp!=0)
  81.         while (!place_meeting(x+sign(hsp),y,objBlock))
  82.             x+=sign(hsp);
  83.     hsp=0;
  84. }
  85.  
  86. //Because we don't use hspeed, we got to move ourselves.
  87. x+=hsp;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement