Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. extends KinematicBody2D
  2.  
  3. var motion = Vector2(0, 0)
  4. const UP = Vector2(0, -1)
  5. const GRAVITY = 500
  6. const MAX_SPEED = 100
  7. const ACCELERATION = 600
  8. const JUMP_HEIGHT = -200
  9. const WALL_JUMP_HEIGHT = -130
  10. const TERMINAL_VELOCITY = 250
  11. const FRICTION = 1.2
  12. const AIR_FRICTION = 1.03
  13. var direction = 1
  14. var gravitymode = 1
  15. var active = 1
  16. var debugmode = true
  17.  
  18.  
  19.  
  20.  
  21. func _physics_process(delta):
  22. if debugmode == true:
  23. print(Engine.get_frames_per_second())
  24. print(motion.y)
  25. if active == 1:
  26. if gravitymode == 1:
  27. motion.y += GRAVITY * delta
  28. motion.y = min(motion.y, TERMINAL_VELOCITY)
  29. elif gravitymode == 3:
  30. motion.y += GRAVITY * delta * 0.4
  31. motion.y = min(motion.y, TERMINAL_VELOCITY/4)
  32. if is_on_floor():
  33. if Input.is_action_just_pressed("jump"):
  34. motion.y = JUMP_HEIGHT - (abs(motion.x) / 10)
  35. if Input.is_action_just_released("jump"):
  36. if motion.y < -100:
  37. motion.y = -100
  38. if Input.is_action_pressed("right"):
  39. motion.x = min(motion.x+ACCELERATION * delta, MAX_SPEED)
  40. elif Input.is_action_pressed("left"):
  41. motion.x = max(motion.x-ACCELERATION * delta, -MAX_SPEED)
  42. else:
  43. if is_on_floor():
  44. motion.x = motion.x / FRICTION
  45. else:
  46. motion.x = motion.x / AIR_FRICTION
  47. if motion.x > 0:
  48. $Sprite.flip_h = false
  49. direction = 1
  50. elif motion.x < 0:
  51. $Sprite.flip_h = true
  52. direction = -1
  53. if is_on_wall() && !is_on_floor():
  54. if motion.y > 0:
  55. gravitymode = 3
  56. if Input.is_action_just_pressed("jump"):
  57. motion.y = WALL_JUMP_HEIGHT
  58. motion.x = MAX_SPEED * -direction * 1.4
  59. elif gravitymode != 2:
  60. gravitymode = 1
  61.  
  62. if is_on_floor():
  63. if motion.x < -10 || motion.x > 10:
  64. $Sprite/AnimationPlayer.play("Running")
  65. else:
  66. $Sprite/AnimationPlayer.play("Idle")
  67. if motion.x > 0 && Input.is_action_pressed("left") || motion.x < 0 && Input.is_action_pressed("right"):
  68. $Sprite/AnimationPlayer.play("Turning")
  69. else:
  70. if motion.y < 0:
  71. $Sprite/AnimationPlayer.play("Jumping")
  72. else:
  73. $Sprite/AnimationPlayer.play("Falling")
  74. if is_on_wall():
  75. $Sprite/AnimationPlayer.play("WallSlide")
  76. if position.y > 960:
  77. position.y = 1
  78. motion = move_and_slide(motion, UP)
  79. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement