Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. extends KinematicBody2D
  2.  
  3. const SPEED = 210
  4. var dir = "down"
  5. var move = Vector2()
  6. var input = false
  7.  
  8. func _ready():
  9.  
  10. func _physics_process(delta):
  11.     if Input.is_action_pressed("ui_up"):
  12.         move.y += SPEED
  13.         dir = "up"
  14.         elif Input.is_action_pressed("ui_down"):
  15.             move.y -= SPEED
  16.             dir = "down"
  17.     else:
  18.         move.y = 0
  19.    
  20.     if Input.is_action_pressed("ui_right"):
  21.         move.x += SPEED
  22.         dir = "right"
  23.         elif Input.is_action_pressed("ui_left"):
  24.             move.x -= SPEED
  25.             dir = "left"
  26.     else:
  27.         move.x = 0
  28.  
  29.     if Input.is_action_pressed("ui_up") or Input.is_action_pressed("ui_down") or Input.is_action_pressed("ui_right") or Input.is_action_pressed("ui_left"):
  30.         input = true
  31.    
  32.     if dir == "down":
  33.         $AnimatedSprite.play("idle_down")
  34.         if input == true:
  35.             §AnimatedSprite2D("walk_down")
  36.  
  37. move_and_slide(move)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement