Guest User

Untitled

a guest
Jan 16th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. extends KinematicBody2D
  2.  
  3. export (int) var run_speed = 300
  4. export (int) var jump_speed = -400
  5. export (int) var gravity = 1000
  6.  
  7. var velocity = Vector2()
  8. var jumping = false
  9.  
  10. func get_input():
  11. velocity.x = 0
  12. var right = Input.is_action_pressed('ui_right')
  13. var left = Input.is_action_pressed('ui_left')
  14. var jump = Input.is_action_just_pressed('ui_select')
  15.  
  16. if jump and is_on_floor():
  17. jumping = true
  18. velocity.y = jump_speed
  19. if right:
  20. velocity.x += run_speed
  21. if left:
  22. velocity.x -= run_speed
  23.  
  24. if left or right and jumping != false:
  25. get_node("AnimationPlayer").play('walkcyc')
  26.  
  27. if left or right and jumping != true:
  28. $AnimatedSprite.animation = 'run'
  29. $AnimatedSprite.flip_h = velocity.x < 0
  30.  
  31. if is_on_floor() and velocity.x == 0 or velocity.y == 0:
  32. $AnimatedSprite.animation = 'stand'
  33. $AnimatedSprite.flip_v = false
  34. $AnimatedSprite.flip_h = velocity.x < 0
  35.  
  36. if jumping != false:
  37. $AnimatedSprite.animation = 'jump'
  38. $AnimatedSprite.flip_v = false
  39. $AnimatedSprite.flip_h = velocity.x < 0
  40.  
  41. func _physics_process(delta):
  42. get_input()
  43. velocity.y += gravity * delta
  44. if jumping and is_on_floor():
  45. jumping = false
  46. velocity = move_and_slide(velocity, Vector2(0, -1))
Add Comment
Please, Sign In to add comment