Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// @description movement
- // input
- /*
- var rkey = keyboard_check(vk_right);
- var lkey = keyboard_check(vk_left);
- // move right
- if (rkey) {
- if (hsp < max_speed) {
- hsp += acc;
- } else {
- hsp = max_speed;
- }
- }
- // move left
- if (lkey) {
- if (hsp > max_speed) {
- hsp -= acc;
- } else {
- hsp = -max_speed;
- }
- }
- */
- /*
- // acceleration
- if (move !=0)
- {
- if (walksp < max_speed)
- {
- walksp += acc;
- }
- else
- {
- walksp = max_speed;
- }
- if (walksp > -max_speed)
- {
- walksp -= acc;
- }
- else
- {
- walksp = -max_speed;
- }
- }
- if (move = 0)
- {
- if (walksp != 0)
- {
- if (walksp < 0)
- {
- walksp += acc;
- }
- else
- {
- walksp -= acc;
- }
- }
- }
- */
- // check if keys are pressed
- key_left = keyboard_check(vk_left) || keyboard_check(ord("A"));
- key_right = keyboard_check(vk_right) || keyboard_check(ord("D"));
- key_jump = keyboard_check_pressed(vk_space);
- key_jump_held = keyboard_check(vk_space);
- // movement
- var move = key_right - key_left;
- // acceleration
- if (move == -1 || move == 1)
- {
- if (walksp < max_speed)
- {
- walksp += acc;
- }
- }
- else
- {
- //walksp = 0;
- if (walksp > 0)
- walksp -= acc;
- }
- //if (move == 0)
- // hsp = 0;
- // deceleration
- if (move != 0)
- hsp = move * walksp
- else
- {
- if (hsp > 0)
- hsp = walksp;
- else
- {
- if (hsp < 0)
- hsp = -walksp;
- }
- }
- //show_debug_message(hsp);
- // gravity
- vsp = vsp + grv;
- // jump
- if (place_meeting(x,y+1,oWall)) && (key_jump)
- {
- vsp = -7;
- }
- if (vsp < 0) && (!key_jump_held) vsp = max(vsp,-2)
- // horizontal collision
- if (place_meeting(x+hsp,y,oWall))
- {
- while (!place_meeting(x+sign(hsp),y,oWall))
- {
- x = x + sign(hsp);
- }
- hsp = 0;
- }
- x = x + hsp;
- // vertical collision
- if (place_meeting(x,y+vsp,oWall))
- {
- while (!place_meeting(x,y+sign(vsp),oWall))
- {
- y = y + sign(vsp);
- }
- vsp = 0;
- }
- y = y + vsp;
- // animation
- if (!place_meeting(x,y+1,oWall))
- {
- sprite_index = sPlayerA;
- image_speed = 0;
- if (sign(vsp) > 0) image_index = 1; else image_index = 0;
- }
- else
- {
- image_speed = 1;
- if (hsp == 0)
- {
- sprite_index = sPlayer;
- }
- else
- {
- sprite_index = sPlayerR;
- }
- }
- if (hsp != 0) image_xscale = sign(hsp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement