Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Create Event
- grav = 0.2;
- hsp = 0;
- vsp = 0;
- jumpspeed = 7;
- movespeed = 4;
- djump=0;
- fric=2;
- ///Step Event
- key_right = keyboard_check(vk_right);
- key_left = -keyboard_check(vk_left);
- key_jump = keyboard_check_pressed(vk_space);
- //Sprite direction
- if hsp < 0
- {
- image_xscale = -1
- }
- if hsp > 0
- {
- image_xscale = 1
- }
- //React to inputs
- move = key_left + key_right; //Because left or right can only be 1 or -1 then adding both makes move = 0
- if(move!=0){hsp = move * movespeed; }
- if (vsp < 10) vsp += grav;
- //Friction
- var fricActive;
- fricActive = fric * (key_left + key_right != 0) * place_meeting(x,y+1,par_wall)
- //Applies Friction fricActive represents how much friction we apply while fric represents the baseline amount of friction
- hsp = max(abs(hsp) - fricActive, 0) * sign(hsp);
- //for Jumping
- if(key_jump)
- {
- if(place_meeting(x,y+1,par_wall))
- {
- vsp=key_jump * -jumpspeed;
- djump=1;
- }
- else
- {
- if(djump=1)
- {
- vsp=key_jump * -jumpspeed+1;
- djump=0;
- }
- }
- }
- //Horizontal Collision
- if (place_meeting(x+hsp,y,par_wall))
- {
- while(!place_meeting(x+sign(hsp),y,par_wall))
- {
- x += sign(hsp);
- }
- hsp = 0;
- }
- else
- x += hsp;
- //Vertical Collision
- if (place_meeting(x,y+vsp,par_wall))
- {
- while(!place_meeting(x,y+sign(vsp),par_wall)) y += sign(vsp);
- {
- vsp=0;
- }
- }
- else
- y += vsp;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement