Advertisement
Guest User

Dashing - oPlayer Step Event

a guest
Feb 1st, 2021
3,434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var xDirection = keyboard_check(ord("D")) - keyboard_check(ord("Q"));
  2. var jump = keyboard_check_pressed(vk_space);
  3. var dash = keyboard_check_pressed(vk_shift);
  4. var onTheGround = place_meeting(x, y + 1, oWall);
  5. var onAWall = place_meeting(x-5, y, oWall) - place_meeting(x+5, y, oWall);
  6.  
  7. mvtLocked = max(mvtLocked - 1, 0);
  8. dashDuration = max(dashDuration - 1, 0);
  9.  
  10. if (dashDuration > 0) ySpeed = 0;
  11. else if (onAWall != 0) ySpeed = min(ySpeed + 1, 5);
  12. else ySpeed++;
  13.  
  14. if (dash) {
  15.     dashDuration = 10;
  16.     xSpeed = image_xscale * dashSpd;
  17. }
  18.  
  19. if (mvtLocked <= 0 && dashDuration <= 0) {
  20.     if (xDirection != 0) image_xscale = xDirection;
  21.     xSpeed = xDirection * spd;
  22.  
  23.     if (jump) {
  24.         if (onTheGround) {
  25.             ySpeed = -15;
  26.         }
  27.    
  28.         if (onAWall != 0) {
  29.             ySpeed = -15;
  30.             xSpeed = onAWall * spd;
  31.             mvtLocked = 10;
  32.         }
  33.     }
  34. }
  35.  
  36. if (dashDuration > 0) {
  37.     sprite_index = sPlayerDash;
  38. } else if (onTheGround) {
  39.     if (xDirection != 0) { sprite_index = sPlayerRun_strip7; }
  40.     else { sprite_index = sPlayerIdle_strip4; }
  41. } else if (onAWall != 0) {
  42.     image_xscale = onAWall;
  43.     sprite_index = sPlayerSlide;
  44. } else {
  45.     sprite_index = sPlayerJump;
  46. }
  47.  
  48. if (place_meeting(x + xSpeed, y, oWall)) {
  49.    
  50.     while (!place_meeting(x + sign(xSpeed), y, oWall)) {
  51.         x += sign(xSpeed);
  52.     }
  53.     xSpeed = 0;
  54. }
  55.  
  56. x += xSpeed;
  57.  
  58.  
  59. if (place_meeting(x, y + ySpeed, oWall)) {
  60.    
  61.     while (!place_meeting(x, y + sign(ySpeed), oWall)) {
  62.         y += sign(ySpeed);
  63.     }
  64.    
  65.     ySpeed = 0;
  66. }
  67.  
  68. y += ySpeed;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement