Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. extends KinematicBody2D
  2.  
  3. #movimiento translates to movement.
  4.  
  5. const speed = 10
  6. const gravity = 20
  7. const JUMP_HEIGHT = -75
  8. const UP = Vector2(0,-1)
  9. var motion = Vector2()
  10.  
  11.  
  12. func _physics_process(delta):
  13. printt(motion)
  14. motion.y += gravity
  15.  
  16. if (Input.is_action_pressed("ui_left")):
  17. movimiento("left")
  18.  
  19. if(Input.is_action_pressed("ui_right")):
  20. movimiento("right")
  21.  
  22. if(Input.is_action_pressed("ui_up")):
  23. movimiento("up")
  24.  
  25. if(Input.is_key_pressed("ui_up" or "ui_right" or "ui_left")):
  26. movimiento("nothing")
  27.  
  28. motion = move_and_slide(motion,UP)
  29.  
  30.  
  31. func movimiento(moveset):
  32. match moveset:
  33. "left":
  34. $AnimatedSprite.animation = "Walking"
  35. $AnimatedSprite.flip_h = false
  36.  
  37. motion.x -= speed
  38. "right":
  39. $AnimatedSprite.animation = "Walking"
  40. $AnimatedSprite.flip_h = true
  41.  
  42. motion.x += speed
  43. "up":
  44. if is_on_floor():
  45. $AnimatedSprite.animation = "Jumping"
  46. $AnimatedSprite.play()
  47. print("On floor")
  48.  
  49. motion.y -= JUMP_HEIGHT
  50. "nothing":
  51. if $AnimatedSprite.is_playing() == false:
  52. $AnimatedSprite.animation = "Idle"
  53. motion.x = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement