Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///-------------------------------------------------------------
- /// This is not the complete code--just some relevant bits since Tumblr code formatting sucks.
- ///-------------------------------------------------------------
- ///-------------------------------------------------------------
- /// @description Player Object - Create
- ///-------------------------------------------------------------
- xSpeed = 0;
- ySpeed = 0;
- xSpeedRemainder = 0;
- ySpeedRemainder = 0;
- ///-------------------------------------------------------------
- /// @description Player Object - Begin Step
- ///-------------------------------------------------------------
- xSpeed = 0;
- ySpeed = 0;
- ///-------------------------------------------------------------
- /// @description PlayerWalkState script
- ///-------------------------------------------------------------
- if(state_new)
- {
- playerAnimationSpeed = 1;
- image_index = 1;
- canTransitionCamera = true;
- isInputBufferOpen = true;
- }
- if(isCameraTransitioning)
- {
- StateSwitch("CameraTransition");
- return;
- }
- if(!isUpKeyHeld && !isDownKeyHeld && !isRightKeyHeld && !isLeftKeyHeld)
- {
- StateSwitch("Stand");
- return;
- }
- CheckItemState();
- image_speed = playerAnimationSpeed;
- playerSpeed = 1;
- playerSpeedDiagonal = playerSpeed * 0.707; //We could calculate exact speed, but this constant is close enough.
- CheckCameraTransitionState();
- xSpeed = 0;
- ySpeed = 0;
- //Northwest
- if(isUpKeyHeld && isLeftKeyHeld && !isDownKeyHeld && !isRightKeyHeld)
- {
- sprite_index = player_walk_n_sp;
- rotation = compass.northwest;
- xSpeed = -playerSpeedDiagonal;
- ySpeed = -playerSpeedDiagonal;
- }
- //Northeast
- else if(isUpKeyHeld && isRightKeyHeld && !isDownKeyHeld && !isLeftKeyHeld)
- {
- sprite_index = player_walk_n_sp;
- rotation = compass.northeast;
- xSpeed = playerSpeedDiagonal;
- ySpeed = -playerSpeedDiagonal;
- }
- //Southwest
- else if(isDownKeyHeld && isLeftKeyHeld && !isUpKeyHeld && !isRightKeyHeld)
- {
- sprite_index = player_walk_s_sp;
- rotation = compass.southwest;
- xSpeed = -playerSpeedDiagonal;
- ySpeed = playerSpeedDiagonal;
- }
- //Southeast
- else if(isDownKeyHeld && isRightKeyHeld && !isUpKeyHeld && !isLeftKeyHeld)
- {
- sprite_index = player_walk_s_sp;
- rotation = compass.southeast;
- xSpeed = playerSpeedDiagonal;
- ySpeed = playerSpeedDiagonal;
- }
- //North
- else if(isUpKeyHeld)
- {
- sprite_index = player_walk_n_sp;
- rotation = compass.north;
- ySpeed = -playerSpeed;
- }
- //South
- else if(isDownKeyHeld)
- {
- sprite_index = player_walk_s_sp;
- rotation = compass.south;
- ySpeed = playerSpeed;
- }
- //West
- else if(isLeftKeyHeld)
- {
- sprite_index = player_walk_w_sp;
- rotation = compass.west;
- xSpeed = -playerSpeed;
- }
- //East
- else if(isRightKeyHeld)
- {
- sprite_index = player_walk_e_sp;
- rotation = compass.east;
- xSpeed = playerSpeed;
- }
- ///-------------------------------------------------------------
- /// @description Player Object - End Step
- ///-------------------------------------------------------------
- StateUpdate();
- //Add the speed to the respective remainders.
- xSpeedRemainder += xSpeed;
- ySpeedRemainder += ySpeed;
- //Sync up remainders for diagonals to avoid stair-step effect (abs() prevents sync on knockback).
- if(xSpeed != 0 && ySpeed != 0 && abs(xSpeed) == abs(ySpeed))
- {
- if (ySpeedRemainder < xSpeedRemainder)
- ySpeedRemainder = sign(ySpeedRemainder) * abs(xSpeedRemainder);
- if (xSpeedRemainder < ySpeedRemainder)
- xSpeedRemainder = sign(xSpeedRemainder) * abs(ySpeedRemainder);
- }
- //If the remainder is >= 1 or <= -1, set the whole number as the speed.
- var xSpeedWholeNum = xSpeedRemainder & ~0;
- var ySpeedWholeNum = ySpeedRemainder & ~0;
- //Move x, process x collision.
- x += xSpeedWholeNum;
- ProcessCollision(id, xSpeedWholeNum, 0);
- //Move y, process y collision.
- y += ySpeedWholeNum;
- ProcessCollision(id, 0, ySpeedWholeNum);
- //Hitbox should follow player.
- player_hitbox_obj.x = x;
- player_hitbox_obj.y = y;
- //Subtract the whole number from the respective remainder (so just a fraction is left).
- xSpeedRemainder -= xSpeedWholeNum;
- ySpeedRemainder -= ySpeedWholeNum;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement