Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. extends KinematicBody2D
  2.  
  3. var motion = Vector2()
  4.  
  5. const SPEED = 1000
  6. const GRAVITY = 300
  7. const UP = Vector2(0, -1)
  8. const JUMP_SPEED = 3000
  9.  
  10. func _physics_process(delta):
  11. apply_gravity()
  12. jump()
  13. move()
  14. animate()
  15. move_and_slide(motion, UP)
  16.  
  17.  
  18. func apply_gravity():
  19. if is_on_floor():
  20. motion.y = 0
  21. else:
  22. motion.y += GRAVITY
  23.  
  24.  
  25. func jump():
  26. if Input.is_action_pressed("jump") and is_on_floor():
  27. motion.y -= JUMP_SPEED
  28.  
  29.  
  30. func move():
  31. if Input.is_action_pressed("left") and not Input.is_action_pressed("right"):
  32. motion.x = -SPEED
  33. elif Input.is_action_pressed("right") and not Input.is_action_pressed("left"):
  34. motion.x = SPEED
  35. else:
  36. motion.x = 0
  37.  
  38.  
  39. func animate():
  40. if motion.y < 0:
  41. $AnimatedSprite.play("jump")
  42.  
  43. elif motion.x != 0:
  44. $AnimatedSprite.play("walk")
  45. $AnimatedSprite.flip_h = false
  46.  
  47. elif motion.x < 0:
  48. $AnimatedSprite.play(("walk")
  49. $AnimatedSprite.flip_h = true
  50.  
  51. else:
  52. $AnimatedSprite.play("idle")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement