Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// @description Player Controls
- //--------------- MOVEMENT ------------------------
- inputUp = keyboard_check(ord("W")); //move up key variable
- inputLeft = keyboard_check(ord("A")); //move left key variable
- inputDown = keyboard_check(ord("S")); //move down key variable
- inputRight = keyboard_check(ord("D")); //move right key variable
- inputShift = keyboard_check(vk_shift); //move speed key variable
- //--------------RESET MOVMENT--------------------
- moveY=0; //Set initial Y movment to 0
- moveX=0; //Set initial X movment to 0
- //------------SPEED CONTROL----------------------
- if (inputShift) { spd = rSpd; } // Sets speed to run speed
- else { spd = wSpd; } // Sets speed to walk speed
- //-------------MOVEMENT SETUP-------------------
- moveY=( inputDown - inputUp ) *spd; // Set initial Y to move direction times speed
- moveX=( inputRight - inputLeft ) *spd; // Set initial X to move direction times speed
- //-------------COLLISION CHECK-------------------
- //Horizontal
- if (moveX!=0){ // Checks if player is trying to move horizontaly
- i=0 // Array index variable
- repeat(array_length_1d(plCollide)){ // Loops for the amount of items in the array
- if (place_meeting(x+moveX, y, plCollide[i])){ // If the intilized X will cause player to collide
- repeat(abs(moveX)){ // Makes moveX a positive number if negative then loops that many times
- if (!place_meeting(x+sign(moveX), y, plCollide[i])){ // If 1 pixel in the movement direction doesn't collide
- x+=sign(moveX); // Increase the player movement by 1 pixel in the movement direction
- }
- else {break;} // Else break the loop
- }
- moveX=0; // Resets moveX
- }
- i+=1; // Adds 1 to array index variable
- }
- }
- //Vertical
- if (moveY != 0){
- i=0 // Array index variable
- repeat(array_length_1d(plCollide)){ // Loops for the amount of items in the array
- if (place_meeting(x, y+moveY, plCollide[i])){ // If the intilized Y will cause player to collide
- repeat(abs(moveY)){ // Makes moveY a positive number if negative then loops that many times
- if (!place_meeting(x, y+sign(moveY), plCollide[i])){ // If 1 pixel in the movement direction doesn't collide
- y+=sign(moveY); // Increase the player movement by 1 pixel in the movement direction
- }
- else {break;} // Else break the loop
- }
- moveY=0; // Resets moveX
- }
- i+=1; // Adds 1 to array index variable
- }
- }
- //---------------APPLY MOVEMENT-----------
- x+=moveX; // Apply X movement
- y+=moveY; // Apply y movement
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement