Advertisement
Guest User

Top-down movement with strafing

a guest
Dec 17th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //// Create event
  2. dir = direction;
  3. strafe = 0;
  4. spd = 4;
  5. image_speed = 0;
  6.  
  7. //// Step event
  8. var up = keyboard_check(ord('W'));
  9. var left = keyboard_check(ord('A'));
  10. var down = keyboard_check(ord('S'));
  11. var right = keyboard_check(ord('D'));
  12.  
  13. image_angle = point_direction(x,y,mouse_x,mouse_y);
  14. direction = image_angle;
  15. image_index = 0;
  16.  
  17. if (up){
  18.     direction = image_angle;
  19.     speed = spd;
  20. }
  21. if (down){
  22.     direction = image_angle+180;
  23.     speed = spd;
  24. }
  25. if (left){
  26.     if (strafe = 1){
  27.         strafe = 0;
  28.     }
  29.     if (strafe = 0){
  30.         dir = image_angle+90;
  31.         strafe = -1;
  32.     }
  33.     direction = dir;
  34.     speed = spd;
  35. }
  36. else if (right){
  37.     if (strafe = -1){
  38.         strafe = 0;
  39.     }
  40.     if (strafe = 0){
  41.         dir = image_angle-90;
  42.         strafe = 1;
  43.     }
  44.     direction = dir;
  45.     speed = spd;
  46. }
  47. if ((!left && !right) || (left && right)){
  48.     strafe = 0;
  49. }
  50. if ((!up && !down && !left && !right) || (left && right) || (up && down)){
  51.     speed = 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement