Advertisement
SteelGolem

ZeldaOoS/OoA improvement on angled movement code

Jan 12th, 2017
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// obj_link_Step
  2.  
  3. var up = keyboard_check(vk_up);
  4. var down = keyboard_check(vk_down);
  5. var left = keyboard_check(vk_left);
  6. var right = keyboard_check(vk_right);
  7.  
  8. var dx = right - left;
  9. var dy = down - up;
  10.  
  11. if (dx == 0 && dy == 0) // no dpad input
  12. {
  13.     image_speed = 0; // not moving, so don't animate
  14. }
  15. else // some dpad input
  16. {
  17.     image_speed = 0.2; // moving, so animate
  18.    
  19.     if (dx != 0 && dy != 0) // diagonal dpad input
  20.     {
  21.         // do nothing for ZeldaLA walking emulation (sweet moonwalkin' action!)
  22.        
  23.         // for ZeldaOoS/OoA, if sprite_index doesn't match the direction, pick the other sprite_index
  24.         /*
  25.         if (sprite_index == spr_link_walking_up && dy == 1) sprite_index = spr_link_walking_down;
  26.         if (sprite_index == spr_link_walking_down && dy == -1) sprite_index = spr_link_walking_up;
  27.         if (sprite_index == spr_link_walking_left && dx == 1) sprite_index = spr_link_walking_right;
  28.         if (sprite_index == spr_link_walking_right && dx == -1) sprite_index = spr_link_walking_left;
  29.         */
  30.     }
  31.     else // axis-aligned dpad input
  32.     {
  33.         if (left) sprite_index = spr_link_walking_left;
  34.         if (right) sprite_index = spr_link_walking_right;
  35.         if (up) sprite_index = spr_link_walking_up;
  36.         if (down) sprite_index = spr_link_walking_down;
  37.     }
  38. }
  39.  
  40. var move_speed = 2.0;
  41. x += dx * move_speed;
  42. y += dy * move_speed;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement