Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This is used to get input from the user based on the game state
- switch(gameState){
- case gStates.playing:
- /*
- If the player isn't in a menu then this will get all the input needed
- and determine what state the player should be in
- */
- key_Up = -keyboard_check(ord("W"));
- key_Down = keyboard_check(ord("S"));
- key_Left = -keyboard_check(ord("A"));
- key_Right = keyboard_check(ord("D"));
- key_Dodge = keyboard_check_pressed(vk_space);
- /*
- If the player hits the dodge button (space) and dodge is off cooldown
- then this will make all the necessary calculations for the dodge movement
- and then change the player state to dodging.
- */
- if(key_Dodge && dodgeCount >= 30){
- playerState = states.dodge;
- targetX = mouse_x - xPos;
- targetY = mouse_y - yPos;
- //Get the unit vector magnitude
- unitVectorMag = sqrt(sqr(targetX) + sqr(targetY));
- //Check to see if the target for the dodge is greater then maxDodgeDist
- sizeDif = max(1,abs(unitVectorMag/maxDodgeDist));
- //If the size dif is > 1 then we use the unit vector, otherwise just use division
- if(sizeDif > 1){
- xVel = abs((targetX/sizeDif) / dodgeInstances) * (targetX/unitVectorMag);
- yVel = abs((targetY/sizeDif) / dodgeInstances) * (targetY/unitVectorMag);
- } else {
- xVel = targetX/dodgeInstances;
- yVel = targetY/dodgeInstances;
- }
- dodgeCount = 0;
- /*
- We break from the switch here since there is nothing else that needs to be done
- after this. The player is now dodging and cannot walk, attack or do anything else
- */
- break;
- }
- hMove = key_Left + key_Right;
- vMove = key_Up + key_Down;
- if(hMove != 0 && vMove != 0){
- unitVectorMag = sqrt(2);
- } else {
- unitVectorMag = 1;
- }
- break;
- case gStates.inventory:
- break;
- default: //This is standing
- break;
- }
- //This is used to control the player based on the players state
- switch(playerState){
- case states.walk:
- //We use the same variable to count dodgeinstances and its cool down. "EFFICIENCY"
- dodgeCount += 1;
- /*
- Movespeed is calculated in this moment as the player might randomly gain or loose
- agi from an item or buff. We use large numbers that are kater scaled down to allow
- for more variation in movement speeds between enemies and players.
- */
- maxMoveSpeed = 200 + (2*totalAgi);
- currentMoveSpeed = maxMoveSpeed;
- /*
- What the fuck is going on here?
- Well its really quite simple, if the player is inputting that they want to move in
- the x axis (hMove != 0), then we check to see if they were previously moving in that
- direction or at all (sign(hMove) == sign(xVel) || round(xVel) == 0), otherwise
- we just simply deccelerate the players movement in the x axis
- */
- if(hMove != 0 && (sign(hMove) == sign(xVel) || round(xVel) == 0)){
- xVel += (currentMoveSpeed / 600) * hMove;
- } else {
- xVel = xVel - (xVel/3);
- }
- //Same thing as above boi
- if(vMove != 0 && (sign(vMove) == sign(yVel) || round(yVel) == 0)){
- yVel += (currentMoveSpeed / 600) * vMove;
- } else {
- yVel = yVel - (yVel/3);
- }
- /*
- This just simple checks to see if the player is to much of a speedy boi or not..
- If vel is greater then the movement speed then we make the proper adjustments
- */
- if(abs(xVel) > (currentMoveSpeed / 100)){
- xVel = (currentMoveSpeed / 100) * hMove;
- }
- if(abs(yVel) > (currentMoveSpeed / 100)){
- yVel = (currentMoveSpeed / 100) * vMove;
- }
- /*
- WHY WE USE 2 VARS FOR POSITION? REEE? One gets track of the real values of
- the player position (xPos and yPos) which allows for small difference in movement
- speed to actually make a difference and the other one is the int value of the
- players position to makes sure the image isnt have a seizure on the screen
- */
- xPos += xVel * (1/unitVectorMag);
- yPos += yVel * (1/unitVectorMag);
- phy_position_x = round(xPos);
- phy_position_y = round(yPos);
- break;
- case states.attack:
- break;
- case states.dodge:
- /*
- 2 VARS AGAIN? just check the same thing int the walk section pls
- */
- xPos += xVel;
- yPos += yVel;
- phy_position_x = round(xPos);
- phy_position_y = round(yPos);
- //If boi over num of dodges allowed. halt him from doing the dodgy doo
- dodgeCount += 1;
- if(dodgeCount == dodgeInstances){
- playerState = states.walk;
- xVel = 0;
- yVel = 0;
- }
- break;
- default: //This is standing
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement