Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Step
- //Main Actions
- //Movement
- move = input.left + input.right;
- //Move right
- if (move == 1)
- {
- hsp += acc;
- if (hsp >= maxSpeed) hsp = maxSpeed;
- }
- else if (hsp > 0)
- {
- hsp -= acc;
- if (hsp <= 0) hsp = 0;
- }
- //Move left
- if (move == -1)
- {
- hsp -= acc;
- if (hsp <= -maxSpeed) hsp = -maxSpeed;
- }
- else if (hsp < 0)
- {
- hsp += acc;
- if (hsp >= 0) hsp = 0;
- }
- //Jumping
- if (vsp < 5) vsp += grv; //Gravity
- if (input.a)
- {
- jumpTime += 1;
- if(jumpTime < 8) vsp = -jumpSpeed;
- }
- else if (place_meeting(x, y+1, obj_wall)) jumpTime = 0;
- else jumpTime = 20;
- //Collisions
- //Horizontal
- if (place_meeting(x+hsp, y, obj_wall))
- {
- while (!place_meeting(x+sign(hsp), y, obj_wall))
- {
- x += sign(hsp)
- }
- hsp = 0;
- }
- x += hsp;
- //Vertical
- if (place_meeting(x, y+vsp, obj_wall))
- {
- while (!place_meeting(x, y+sign(vsp), obj_wall))
- {
- y += sign(vsp)
- }
- vsp = 0;
- }
- y += vsp;
- //Create
- ///Set variables
- //Movement
- hsp = 0;
- vsp = 0;
- maxSpeed = 10;
- acc = 0.05;
- //Jumping
- grv = 0.3;
- jumpSpeed = 5;
- jumpTime = 0;
- /////Sonic.gmk
- //Create
- acc = 0.1;
- global.vel = 0;
- maxSpeed = 10;
- ground = true;
- ducking = false;
- rolling = false;
- canMove = true;
- spindash = false;
- spindashTimer = 0;
- drawAngle = 0;
- canHit = true;
- canSpriteChange = true;
- start_x = x;
- start_y = y;
- lives = 5;
- //Step
- //Movement
- if keyboard_check(vk_left) && !place_meeting(x+(abs(global.vel)*-1)-1, y, objSolid) && (canMove == true or (rolling == true && global.vel > 0))
- {
- global.vel -= acc * (1+ground);
- if global.vel > 0 && ground == false
- global.vel -= acc;
- if rolling == false
- image_xscale = -1;
- }
- if keyboard_check(vk_right) && !place_meeting(x+abs(global.vel)+1, y, objSolid) && (canMove == true or (rolling == true && global.vel < 0))
- {
- global.vel += acc * (1+ground);
- if global.vel < 0 && ground == false
- global.vel += acc;
- if rolling == false
- image_xscale = 1;
- }
- //Deacceleration
- if ground == true
- {
- if global.vel > 0
- global.vel -= acc/(rolling+1);
- else if global.vel < 0
- global.vel += acc/(rolling+1);
- }
- closestSolid1 = instance_place(x+abs(global.vel)+1, y, objSolid);
- closestSolid2 = instance_place(x+(abs(global.vel)*-1)-1, y, objSolid);
- if (global.vel > 0 && closestSolid1 > 0) or (global.vel < 0 && closestSolid2 > 0)
- {
- if closestSolid1 > 0
- {
- if closestSolid1.canWall == true
- global.vel = 0;
- }
- else if closestSolid2 > 0
- {
- if closestSolid2.canWall == true
- global.vel = 0;
- }
- }
- //Speed Limit
- if global.vel > maxSpeed
- global.vel = maxSpeed;
- else if global.vel < -maxSpeed
- global.vel = -maxSpeed;
- if global.vel > -acc && global.vel < acc
- {
- global.vel = 0;
- rolling = false;
- }
- x += global.vel;
- //Gravity
- if (place_meeting(x, y+vspeed+1, objSolid) or place_meeting(x, y+vspeed+1, objSlopeParent)) && vspeed >= 0
- {
- ground = true;
- gravity = 0;
- }
- else
- {
- ground = false;
- gravity = 0.25;
- if vspeed > 8
- vspeed = 8;
- }
- //Handle Sprites
- if sprite_index == sprSonicHit
- {
- if image_index < 1
- image_speed = 0.1;
- }
- if canSpriteChange == true
- {
- if ground == true && ducking == false && rolling == false && spindash == false
- {
- if global.vel == 0
- sprite_index = sprSonicStand;
- else if global.vel > -8 && global.vel < 8
- sprite_index = sprSonicWalk;
- else
- sprite_index = sprSonicRun;
- image_speed = abs(global.vel / 20);
- }
- else if sprite_index == sprSonicJump
- {
- image_speed = 0.2 + abs(global.vel / 20);
- }
- }
- //Jumping
- if ground == true && keyboard_check_pressed(ord('Z')) && ducking == false && canMove == true
- {
- vspeed = -7;
- sprite_index = sprSonicJump;
- }
- if rolling == true && keyboard_check_pressed(ord('Z'))
- {
- vspeed = -7;
- }
- else if rolling == false
- {
- canMove = true;
- }
- //Ducking
- if global.vel == 0 && ground == true && ducking == false && rolling == false && keyboard_check(vk_down)
- {
- ducking = true;
- image_index = 0;
- }
- //Rolling
- else if global.vel != 0 && ground == true && ducking == false && rolling == false && keyboard_check(vk_down)
- {
- rolling = true;
- }
- if ducking == true && (!keyboard_check(vk_down) or ground == false)
- {
- ducking = false;
- canMove = true;
- }
- if rolling == true && (ground == false or global.vel == 0)
- {
- rolling = false;
- canMove = true;
- }
- if ducking == true && spindash == false
- {
- mask_index = sprSonicDuckMask;
- sprite_index = sprSonicDuck;
- if image_index < 1
- image_speed = 0.1;
- else
- image_speed = 0;
- canMove = false;
- }
- else if rolling == true
- {
- mask_index = sprSonicRollMask;
- sprite_index = sprSonicJump;
- canMove = false;
- }
- else if spindash == true
- {
- mask_index = sprSonicRollMask;
- sprite_index = sprSonicSpindash;
- image_speed = 0.25;
- canMove = false;
- }
- else
- {
- mask_index = sprSonicMask;
- }
- //Ducking Animation in the Air Fix
- if ground == false && sprite_index == sprSonicDuck
- sprite_index = sprSonicJump;
- //Spindash
- if ground == true && ducking == true && keyboard_check_pressed(ord('Z'))
- {
- spindash = true;
- if spindashTimer < 64
- spindashTimer += 8;
- if spindashTimer > 64
- spindashTimer = 24;
- sprite_index = sprSonicSpindash;
- }
- spindashTimer = spindashTimer - ((spindashTimer div 0.125) / 256);
- if ground == true && spindash == true && keyboard_check_released(vk_down)
- {
- rolling = true;
- global.vel = image_xscale * (2 + spindashTimer);
- spindash = false;
- spindashTimer = 0;
- }
- //Slope Collision
- collideSlopes();
- //Return control when player falls on the ground when getting hit
- if (place_meeting(x, y+2*vspeed+2, objSolid) or place_meeting(x, y+2*vspeed+2, objSlopeParent)) && sprite_index == sprSonicHit
- {
- canMove = false;
- canSpriteChange = true;
- image_alpha = 0.5;
- alarm[0] = 90;
- global.vel = 0;
- }
- //Look Up
- if ground == false && sprite_index == sprSonicLookUp
- sprite_index = sprSonicJump;
- if keyboard_check(vk_up) && ground == true
- {
- sprite_index = sprSonicLookUp;
- }
- if keyboard_check(vk_up) && sprite_index == sprSonicLookUp
- {
- canMove = false;
- global.vel = 0;
- }
- if rolling == true && keyboard_check(vk_up)
- {
- rolling = true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement