Advertisement
Guest User

Untitled

a guest
Jun 1st, 2018
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. extends Sprite
  2.  
  3. export(float) var speed = 10.0
  4. export(int) var tileSize = 32
  5.  
  6. func _process(delta):
  7.     var dir = get_input_dir()
  8.     if dir != Vector2():
  9.         $Tween.interpolate_property(self, "position", position, position + dir * tileSize, 1.0 / speed, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
  10.         $Tween.start()
  11.  
  12. func _on_Tween_tween_started(object, key):
  13.     set_process(false)
  14.  
  15. func _on_Tween_tween_completed(object, key):
  16.     set_process(true)
  17.  
  18. func get_input_dir():
  19.     var dir = Vector2()
  20.  
  21.     dir.y = (int(Input.is_action_pressed("ui_down")) - int(Input.is_action_pressed("ui_up")))
  22.     if dir.y == 0:
  23.         dir.x = (int(Input.is_action_pressed("ui_right")) - int(Input.is_action_pressed("ui_left")))
  24.  
  25.     return dir
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement