playerObj ( Step Event )

a guest
Aug 6th, 2019
74
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. /// @description Player Controls
2.
3. //--------------- MOVEMENT ------------------------
4.
5. inputUp = keyboard_check(ord("W")); //move up key variable
6. inputLeft = keyboard_check(ord("A")); //move left key variable
7. inputDown = keyboard_check(ord("S")); //move down key variable
8. inputRight = keyboard_check(ord("D")); //move right key variable
9. inputShift = keyboard_check(vk_shift); //move speed key variable
10.
11. //--------------RESET MOVMENT--------------------
12.
13. moveY=0; //Set initial Y movment to 0
14. moveX=0; //Set initial X movment to 0
15.
16. //------------SPEED CONTROL----------------------
17.
18. if (inputShift) { spd = rSpd; } // Sets speed to run speed
19. else            { spd = wSpd; } // Sets speed to walk speed
20.
21. //-------------MOVEMENT SETUP-------------------
22.
23. moveY=( inputDown - inputUp ) *spd; // Set initial Y to move direction times speed
24.
25. moveX=( inputRight - inputLeft ) *spd; // Set initial X to move direction times speed
26.
27. //-------------COLLISION CHECK-------------------
28.
29. //Horizontal
30. if (moveX!=0){ // Checks if player is trying to move horizontaly
31.     i=0 // Array index variable
32.     repeat(array_length_1d(plCollide)){ // Loops for the amount of items in the array
33.         if (place_meeting(x+moveX, y, plCollide[i])){ // If the intilized X will cause player to collide
34.             repeat(abs(moveX)){ // Makes moveX a positive number if negative then loops that many times
35.                 if (!place_meeting(x+sign(moveX), y, plCollide[i])){ // If 1 pixel in the movement direction doesn't collide
36.                     x+=sign(moveX); // Increase the player movement by 1 pixel in the movement direction
37.                 }
38.                 else {break;} // Else break the loop
39.             }
40.             moveX=0; // Resets moveX
41.         }
42.         i+=1; // Adds 1 to array index variable
43.     }
44. }
45.
46. //Vertical
47. if (moveY!=0){ // Checks if player is trying to move vertically
48.     i=0; // Array index variable
49.     repeat(array_length_1d(plCollide)){ // Loops for the ammount of items in the array
50.         if (place_meeting(x, y+moveY, plCollide[i])){ // If the intilized Y will cause player to collide
51.             repeat(abs(moveX)){ // Makes moveY a positive number if negative then loops that many times
52.                 if (!place_meeting(x, y+sign(moveY), plCollide[i])){ // If 1 pixel in the movement direction doesn't collide
53.                     y+=sign(moveY); // Increase the player movement by 1 pixel in the movement direction
54.                 }
55.                 else {break;} // Else break the loop
56.             }
57.             moveY=0; // Resets moveX
58.         }
59.         i+=1; // Adds 1 to array index variable
60.     }
61. }
62.
63. //---------------APPLY MOVEMENT-----------
64. x+=moveX; // Apply X movement
65. y+=moveY; // Apply y movement
RAW Paste Data