Advertisement
keith527

Planet Demo - Player Step Event Code

Sep 22nd, 2019
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (!isInAir && oInputSystem.wasJumpPressed) {
  2.     isInAir = true;
  3.     verticalSpeed -= JUMP_INITIAL_VERTICAL_SPEED;
  4.     audio_play_sound(sndJump, 1, false);
  5. }
  6.  
  7. verticalSpeed += MY_GRAVITY;
  8.  
  9. var fallDirection = point_direction(x, y, oPlanet.x, oPlanet.y);
  10.  
  11. var isWalking = false;
  12.  
  13. if (oInputSystem.isLeftPressed) {
  14.     isFacingRight = false;
  15.     isWalking = true;
  16.     x += lengthdir_x(HORIZONTAL_SPEED_MAGNITUDE, fallDirection - 90);
  17.     y += lengthdir_y(HORIZONTAL_SPEED_MAGNITUDE, fallDirection - 90);
  18. }
  19.  
  20. if (oInputSystem.isRightPressed) {
  21.     isFacingRight = true;
  22.     isWalking = true;
  23.     x += lengthdir_x(HORIZONTAL_SPEED_MAGNITUDE, fallDirection + 90);
  24.     y += lengthdir_y(HORIZONTAL_SPEED_MAGNITUDE, fallDirection + 90);
  25. }
  26.  
  27. if (!isInAir && isWalking) {
  28.     sprite_index = sPlayerWalking;
  29. } else if (isInAir && verticalSpeed <= 0) {
  30.     sprite_index = sPlayerJumping;
  31. } else if (isInAir && verticalSpeed > 0) {
  32.     sprite_index = sPlayerFalling;
  33. } else {
  34.     sprite_index = sPlayerStanding;
  35. }
  36.  
  37. image_angle = fallDirection + 90;
  38. if (isFacingRight) {
  39.     image_xscale = 1;
  40. } else {
  41.     image_xscale = -1;
  42. }
  43.  
  44. var newDeltaXFromFalling = lengthdir_x(verticalSpeed, fallDirection);
  45. var newDeltaYFromFalling = lengthdir_y(verticalSpeed, fallDirection);
  46. var newX = x + newDeltaXFromFalling;
  47. var newY = y + newDeltaYFromFalling;
  48. if (place_meeting(newX, newY, oPlanet)) {
  49.     while (!place_meeting(x, y, oPlanet)) {
  50.         x += lengthdir_x(0.5, fallDirection);
  51.         y += lengthdir_y(0.5, fallDirection);
  52.     }
  53.    
  54.     verticalSpeed = 0;
  55.     isInAir = false;
  56. } else {
  57.     x = newX;
  58.     y = newY;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement