Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Movement
- var ss,success;
- collidedAbove = place_meeting(x, y-1, objSolid);
- //
- // player update horizontal speed
- if (keyR==true and keyL==false)
- {
- vHspeed += vHspeedAcc
- //
- // restrict the hspeed variable
- if (vHspeed > vHspeedMax)
- {
- vHspeed = vHspeedMax;
- }
- }
- else if (keyR==false and keyL==true)
- {
- vHspeed -= vHspeedAcc;
- //
- // restrict the hspeed variable
- if (vHspeed < -vHspeedMax)
- {
- vHspeed = -vHspeedMax;
- }
- }
- else
- {
- //
- // when no key is pressed or both are pressed
- if (vHspeed > 0)
- {
- if vGround
- vHspeed -= vHspeedDec;
- if (vHspeed < 0)
- {
- vHspeed = 0;
- }
- }
- if (vHspeed < 0)
- {
- if vGround
- vHspeed += vHspeedDec;
- if (vHspeed > 0)
- {
- vHspeed = 0;
- }
- }
- }
- //
- // player update vertical speed
- if (vGround == false){
- vVspeed += vVspeedGrav;
- //
- // restrict the vspeed variable
- if (vVspeed > vVspeedMax){
- vVspeed = vVspeedMax;
- }
- }
- //
- // player event handling
- //
- // player jumping
- if keyJump {
- if (vGround == true){
- vVspeed = -2.90;
- vGround = false;
- }
- }
- else if (!keyJump && vVspeed <= -2.90/2)
- vVspeed = -2.90/2;
- //
- // player vertical movement
- vfyspeed += abs(vVspeed);
- ss = sign(vVspeed);
- if (vfyspeed >= 0.5){
- while(vfyspeed >= 0.5){
- vfyspeed -= 1;
- success = false;
- //
- // choose between the bottom or top movement
- switch(ss){
- case 1:
- if (place_meeting(x,y+1,objSolid)==false)
- {
- y += 1;
- success = true;
- }
- break;
- case -1:
- if (place_meeting(x,y-1,objSolid)==false)
- {
- y -= 1;
- success = true;
- }
- break;
- }
- if collidedAbove //colliding above for particles
- {
- if !instance_exists(objHeadBangParticle)
- {
- instance_create(x,y-12,objHeadBangParticle);
- instance_create(x,y-12,objHeadBangParticle);
- }
- }
- //
- // when there is a collision
- if (success == false){
- vfyspeed = 0;
- if (vVspeed > 0) vGround = true;
- vVspeed = 0;
- break;
- }
- }
- }
- //
- // player horizontal movement
- vfxspeed += abs(vHspeed);
- ss = sign(vHspeed);
- if (vfxspeed >= 0.5){
- while(vfxspeed >= 0.5){
- vfxspeed -= 1;
- success = false;
- //
- // choose between right or left movement
- switch(ss)
- {
- case 1:
- if (place_meeting(x+1,y,objSolid)==false)
- {
- x += 1;
- success = true;
- }
- else
- {
- //
- // use a 'for loop' if you want higher slope handling
- if (vGround==true && place_meeting(x+1,y-1,objSolid)==false)
- {
- x += 1;
- y -= 1;
- success = true;
- }
- }
- break;
- case -1:
- if (place_meeting(x-1,y,objSolid)==false)
- {
- x -= 1;
- success = true;
- }
- else
- {
- //
- // use a 'for loop' if you want higher slope handling
- if (vGround==true && place_meeting(x-1,y-1,objSolid)==false)
- {
- x -= 1;
- y -= 1;
- success = true;
- }
- }
- break;
- }
- //
- // when there is a collision
- if (success == false){
- vfxspeed = 0;
- if (vHspeed > 0) if (place_meeting(x+1,y-1,objSolid)==true)
- vHspeed = 0;
- if (vHspeed < 0) if (place_meeting(x-1,y-1,objSolid)==true)
- vHspeed = 0;
- break;
- }
- //
- // going down slopes
- if (vGround == true){
- if (place_meeting(x,y+1,objSolid)==false){
- y += 1;
- //
- // check if we are NOT touching the ground anymore
- if (place_meeting(x,y+1,objSolid)==false) vGround = false;
- }
- }
- }
- }
- //
- // check if we are on the ground
- if (place_meeting(x,y+1,objSolid)==false)
- vGround = false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement