Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
58
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(vk_space);
  7. KEY_FALL=keyboard_check_released(vk_up); //This one's for variable jump height:
  8.  
  9.  
  10. //Vertical movements.
  11.  
  12. //Is the player in the air?
  13. if (place_meeting(x,y+1,objBlock)) grounded=1;
  14. else grounded=0;
  15.  
  16. //Jump with the up key when on the ground.
  17. if (KEY_JUMP and grounded)
  18. {
  19.     vsp=jumpsp;
  20. }
  21.  
  22. //If we're in air moving up and jump key is released, we remove
  23. //upward motion (So we fall and get variable jump height.)
  24. if (KEY_FALL and !grounded and vsp<-1) vsp=-1;
  25.  
  26. //Fall with gravity.
  27. if (!grounded) vsp+=grav;
  28.  
  29. //Now it's more complicated.
  30. //When hitting the ceiling, vertical speed must stop.
  31. //The if statement says, "if we hit the ceiling and are moving up"
  32.  
  33.  
  34. if (place_meeting(x,y+vsp,objBlock) && vsp<0)
  35. {
  36.     //We must move up until contact with the ceiling.
  37.     while (!place_meeting(x,y+sign(vsp),objBlock)) y+=sign(vsp);
  38.     vsp=0;
  39. }
  40.  
  41. //But if we are moving down and hit the floor, we have to land.
  42. if (place_meeting(x,y+vsp,objBlock) and vsp>0)
  43. {
  44.     //Move so we hit the ground.
  45.     var cc;
  46.     cc=vsp+1; //A counter, so we don't get an infinite loop
  47.  
  48.      //Move down until we hit the floor.
  49.     while (!place_meeting(x,y+1,objBlock) and cc>=0) y+=1;
  50.  
  51.      //Now ground the player.
  52.     grounded=1;
  53.  
  54.     vsp=0;
  55. }
  56.  
  57. //Again, we're not using vspeed, so we have to move ourselves.
  58. y+=vsp;
  59.  
  60. //Now for horizontal movements.
  61.  
  62. //Now check if the player pressed left or right and move.
  63. if (KEY_RIGHT)
  64. {
  65.     hsp=walksp; //Walk right.
  66.     image_xscale=1; //Face right.
  67. }
  68.  
  69. if (KEY_LEFT)
  70. {
  71.     hsp=-walksp; //Walk left.
  72.     image_xscale=-1; //Face left.
  73. }
  74.  
  75. //Stop moving when no keys are pressed.
  76. if (!KEY_RIGHT and !KEY_LEFT) hsp=0 stand=1;
  77.  
  78. //Make sure we don't hit a wall.
  79. if (place_meeting(x+hsp,y,objBlock))
  80. {
  81.     //Move until contact with the wall.
  82.     if (hsp!=0)
  83.         while (!place_meeting(x+sign(hsp),y,objBlock))
  84.             x+=sign(hsp);
  85.     hsp=0;
  86. }
  87.  
  88. //Because we don't use hspeed, we got to move ourselves.
  89. x+=hsp;
  90.  
  91.  
  92. //Animation time! Let's set up some images.
  93.  
  94. //Check if on the ground and standing, then set the standing sprite.
  95. if (grounded and stand=1 and global.attack=0)
  96. {
  97.     sprite_index=MaleBasicWhiteHairStand;
  98.     image_speed=0.5; // Animation speed.
  99. }
  100.  
  101. //Check if you're pressing right or left keys, then change sprite accordingly.
  102.  
  103. if (grounded and global.attack=0 and (KEY_LEFT or KEY_RIGHT))
  104. {
  105.     stand=0;
  106.     sprite_index=MaleBasicWhiteHairWalk;
  107.     image_speed=0.3; //Animation speed.
  108. }
  109.  
  110. //If we're not grounded, change to in air sprite.
  111. if (!grounded)  
  112. {
  113.   sprite_index=MaleBasicWhiteHairJump;
  114.   image_speed=0; //Don't animate
  115. }
  116.  
  117. // Now we need to make it so it knows when to attack.
  118.  
  119. if keyboard_check_released(vk_space)
  120. {
  121.  if (grounded and stand=1 and punchcooldown=0) // We use so many conditions so it prevents spam.
  122. {{
  123.     global.attack=1;
  124.     global.basicpunch=1;
  125.     punchcooldown=1;
  126.     sprite_index = MaleBasicWhiteHairPunch;
  127. }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement