Advertisement
buttercupirl

Untitled

Feb 18th, 2021
1,114
0
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_jump_held = keyboard_check(vk_space);
  5. key_down_held = keyboard_check(vk_down);
  6. key_interact = keyboard_check_pressed(ord("E"));
  7.  
  8. //check if moving left or right
  9. var horizontal_input = key_right - key_left;
  10.  
  11. //grounded check
  12. if ((place_meeting(x,y+1,oSolidTile) || place_meeting(x,y+1,oPlatform)) && !grounded){
  13.     grounded = true;
  14.     coyote_time = max_coyote_time;
  15.     land_time = max_land_time;
  16. }
  17. if (land_time){
  18.     land_time--;   
  19. }
  20. if (!place_meeting(x,y+1,oSolidTile) && !place_meeting(x,y+1,oPlatform)){
  21.     if (coyote_time){
  22.         coyote_time--;     
  23.     }
  24.     else{
  25.     }
  26.     grounded = false;
  27. }
  28. //applying jump if grounded
  29. if ((grounded || coyote_time) && key_jump){
  30.     if (key_down_held && place_meeting(x,y+1,oPlatform)){
  31.         vsp = -jump_speed; 
  32.     }
  33.     else{
  34.         vsp = jump_speed;
  35.         jump_time = max_jump_time;
  36.     }
  37.     coyote_time = 0;
  38.     hsp += jump_boost * horizontal_input;  
  39. }
  40. if (!grounded){
  41.     if (key_jump_held){
  42.         if (abs(vsp) <= half_gravity_threshold){
  43.             grav_mult = 0.5;
  44.         }
  45.         else{
  46.             grav_mult = 1; 
  47.         }  
  48.         if (jump_time){
  49.             vsp = jump_speed;
  50.         }
  51.     }
  52.     jump_time--;
  53.     if (coyote_time < 2){
  54.         vsp = clamp((vsp + (gravity_speed * grav_mult)), -infinity, max_fall);
  55.     }
  56. }
  57.  
  58. //horizontal movement
  59. if (horizontal_input != 0){
  60.     if (grounded){
  61.         hsp = clamp((hsp + horizontal_input * walk_accel), -walk_speed, walk_speed);
  62.     }
  63.     else{
  64.         hsp = clamp((hsp + horizontal_input * air_accel), -air_max_speed, air_max_speed);  
  65.     }
  66. }
  67. else{ //friction
  68.     if (grounded){
  69.         hsp *= 1 - ground_friction;
  70.     }
  71.     else{
  72.         hsp *= 1 - air_friction;
  73.     }
  74. }
  75. if (cam.new_room != noone){
  76.     can_move = false;
  77. }
  78. else{
  79.     can_move = true;
  80. }
  81.  
  82. //horizontal collision
  83. if (place_meeting(x+hsp,y,oSolidTile)){
  84.     while(!place_meeting(x+sign(hsp),y,oSolidTile)){
  85.         x += sign(hsp);
  86.     }
  87.     hsp = 0;
  88. }
  89. if (can_move){
  90.     x += hsp;
  91. }
  92.  
  93. //vertical collision
  94. if (place_meeting(x,y+vsp,oSolidTile)){
  95.     while(!place_meeting(x,y+sign(vsp),oSolidTile)){
  96.         y += sign(vsp);
  97.     }
  98.     vsp = 0;
  99. }
  100. with (oPlatform){
  101.     if (place_meeting(x,y+other.vsp,other) && other.bbox_bottom < bbox_top){
  102.         with (other){
  103.             while(!place_meeting(x,y+sign(vsp),other)){
  104.                 y += sign(vsp);
  105.             }
  106.             vsp = 0;
  107.         }
  108.     }
  109. }
  110. if (can_move){
  111.     y += vsp;
  112. }
  113. //squash and stretch
  114. if (vsp < 0){  
  115.     draw_xscale = 1 + 0.05 * vsp;
  116.     draw_yscale = 1 - 0.1 * vsp;
  117. }
  118. else if (land_time){
  119.     draw_xscale = 1 + 0.075 * land_time;
  120.     draw_yscale = 1 - 0.025 * land_time;
  121. }
  122. else{
  123.     draw_xscale = 1;
  124.     draw_yscale = 1;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement