Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Movement
- global.delta = delta_time / ((1/room_speed)*1000000);
- // Get input
- keyboard_set_map(ord("W"), vk_up);
- keyboard_set_map(ord("A"), vk_left);
- keyboard_set_map(ord("D"), vk_right);
- key_right = keyboard_check(vk_right);
- key_left = -keyboard_check(vk_left);
- key_jump += buffer*keyboard_check_pressed(vk_up);
- if key_jump > 0 key_jump--;
- move = key_left + key_right;
- if move != 0 //Accelerating
- {
- dir = move;
- hsp = (lerp(hsp,move * spd, 0.2)*global.delta);
- }
- else hsp = (lerp(hsp,move * spd,0.1)*global.delta); //Decelerating
- if vsp < 10 vsp += grav*global.delta;
- if place_meeting(x, y + 1, obj_wall) //If on ground
- {
- if key_jump > 0
- {
- vsp = sign(key_jump) * -jspd * global.delta;
- key_jump = 0;
- }
- }
- //Collisions
- if place_meeting(x + hsp, y, obj_wall)
- {
- while (!place_meeting(x+sign(hsp),y, obj_wall))
- {
- x += sign(hsp);
- }
- hsp = 0;
- }
- x += hsp;
- if place_meeting(x, y + vsp, obj_wall)
- {
- while !place_meeting(x, y + sign(vsp), obj_wall)
- {
- y += sign(vsp);
- }
- vsp = 0;
- }
- y += vsp;
- //Clamp in room
- x = clamp(x,sprite_width/2,room_width-(sprite_width/2));
- y = clamp(y,sprite_height/2,room_height-(sprite_height/2));
Add Comment
Please, Sign In to add comment