emersonmx

player.gd

Jan 30th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. extends KinematicBody2D
  2.  
  3. const GRAVITY = 20
  4. const SPEED = 300
  5. const JUMP_HEIGHT = -600
  6. const FLOOR_NORMAL = Vector2(0, -1)
  7.  
  8. var velocity = Vector2()
  9.  
  10. func _physics_process(delta):
  11. velocity.y += GRAVITY
  12.  
  13. velocity.x = 0
  14. if Input.is_action_pressed('ui_left'):
  15. velocity.x = -SPEED
  16. elif Input.is_action_pressed('ui_right'):
  17. velocity.x = SPEED
  18.  
  19. if Input.is_action_just_pressed('ui_cancel'):
  20. position = Vector2(512, 80)
  21. velocity = Vector2()
  22.  
  23. if is_on_floor():
  24. velocity.y += GRAVITY * 10
  25.  
  26. if is_on_floor() and Input.is_action_just_pressed('ui_select'):
  27. velocity.y = JUMP_HEIGHT
  28.  
  29. velocity = move_and_slide(velocity, FLOOR_NORMAL, 25)
Advertisement
Add Comment
Please, Sign In to add comment