Advertisement
Guest User

Untitled

a guest
Dec 1st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///Movement
  2.  
  3. var ss,success;
  4. collidedAbove = place_meeting(x, y-1, objSolid);
  5. //
  6. // player update horizontal speed
  7. if (keyR==true and keyL==false)
  8. {
  9.     vHspeed += vHspeedAcc
  10.     //
  11.     // restrict the hspeed variable
  12.     if (vHspeed > vHspeedMax)
  13.     {
  14.         vHspeed = vHspeedMax;
  15.     }
  16. }
  17. else if (keyR==false and keyL==true)
  18. {
  19.     vHspeed -= vHspeedAcc;
  20.     //
  21.     // restrict the hspeed variable
  22.     if (vHspeed < -vHspeedMax)
  23.     {
  24.         vHspeed = -vHspeedMax;
  25.     }
  26. }
  27. else
  28. {
  29.     //
  30.     // when no key is pressed or both are pressed
  31.     if (vHspeed > 0)
  32.     {
  33.         if vGround
  34.             vHspeed -= vHspeedDec;
  35.         if (vHspeed < 0)
  36.         {
  37.             vHspeed = 0;
  38.         }
  39.     }
  40.     if (vHspeed < 0)
  41.     {
  42.         if vGround
  43.             vHspeed += vHspeedDec;
  44.         if (vHspeed > 0)
  45.         {
  46.             vHspeed = 0;
  47.         }
  48.     }
  49. }
  50.  
  51. //
  52. // player update vertical speed
  53. if (vGround == false){
  54.     vVspeed += vVspeedGrav;
  55.     //
  56.     // restrict the vspeed variable
  57.     if (vVspeed > vVspeedMax){
  58.         vVspeed = vVspeedMax;
  59.     }
  60. }
  61.  
  62. //
  63. // player event handling
  64.  
  65. //
  66. // player jumping
  67. if keyJump {
  68.     if (vGround == true){
  69.         vVspeed = -2.90;
  70.         vGround = false;
  71.     }
  72. }
  73. else if (!keyJump && vVspeed <= -2.90/2)
  74.     vVspeed = -2.90/2;
  75.  
  76. //
  77. // player vertical movement
  78. vfyspeed += abs(vVspeed);
  79. ss = sign(vVspeed);
  80.  
  81. if (vfyspeed >= 0.5){
  82.     while(vfyspeed >= 0.5){
  83.         vfyspeed -= 1;
  84.         success = false;
  85.         //
  86.         // choose between the bottom or top movement
  87.         switch(ss){
  88.             case 1:
  89.             if (place_meeting(x,y+1,objSolid)==false)
  90.             {
  91.                 y += 1;
  92.                 success = true;
  93.             }
  94.             break;
  95.            
  96.             case -1:
  97.             if (place_meeting(x,y-1,objSolid)==false)
  98.             {
  99.                 y -= 1;
  100.                 success = true;
  101.             }
  102.             break;
  103.         }
  104.        
  105.         if collidedAbove //colliding above for particles
  106.         {
  107.             if !instance_exists(objHeadBangParticle)
  108.             {
  109.                 instance_create(x,y-12,objHeadBangParticle);
  110.                 instance_create(x,y-12,objHeadBangParticle);
  111.             }
  112.         }
  113.         //
  114.         // when there is a collision
  115.         if (success == false){
  116.             vfyspeed = 0;
  117.             if (vVspeed > 0) vGround = true;
  118.             vVspeed = 0;
  119.             break;
  120.         }
  121.     }
  122. }
  123.  
  124. //
  125. // player horizontal movement
  126. vfxspeed += abs(vHspeed);
  127. ss = sign(vHspeed);
  128.  
  129. if (vfxspeed >= 0.5){
  130.     while(vfxspeed >= 0.5){
  131.         vfxspeed -= 1;
  132.         success = false;
  133.         //
  134.         // choose between right or left movement
  135.         switch(ss)
  136.         {
  137.             case 1:
  138.             if (place_meeting(x+1,y,objSolid)==false)
  139.             {
  140.                 x += 1;
  141.                 success = true;
  142.             }
  143.             else
  144.             {
  145.                 //
  146.                 // use a 'for loop' if you want higher slope handling
  147.                 if (vGround==true && place_meeting(x+1,y-1,objSolid)==false)
  148.                 {
  149.                     x += 1;
  150.                     y -= 1;
  151.                     success = true;
  152.                 }
  153.             }
  154.             break;
  155.            
  156.             case -1:
  157.             if (place_meeting(x-1,y,objSolid)==false)
  158.             {
  159.                 x -= 1;
  160.                 success = true;
  161.             }
  162.             else
  163.             {
  164.                 //
  165.                 // use a 'for loop' if you want higher slope handling
  166.                 if (vGround==true && place_meeting(x-1,y-1,objSolid)==false)
  167.                 {
  168.                     x -= 1;
  169.                     y -= 1;
  170.                     success = true;
  171.                 }
  172.             }
  173.             break;
  174.         }
  175.         //
  176.         // when there is a collision
  177.         if (success == false){
  178.             vfxspeed = 0;
  179.             if (vHspeed > 0) if (place_meeting(x+1,y-1,objSolid)==true)
  180.                 vHspeed = 0;
  181.             if (vHspeed < 0) if (place_meeting(x-1,y-1,objSolid)==true)
  182.                 vHspeed = 0;
  183.             break;
  184.         }
  185.         //
  186.         // going down slopes
  187.         if (vGround == true){
  188.             if (place_meeting(x,y+1,objSolid)==false){
  189.                 y += 1;
  190.                 //
  191.                 // check if we are NOT touching the ground anymore
  192.                 if (place_meeting(x,y+1,objSolid)==false) vGround = false;
  193.             }
  194.         }
  195.     }
  196. }
  197.  
  198. //
  199. // check if we are on the ground
  200. if (place_meeting(x,y+1,objSolid)==false)
  201.     vGround = false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement