Advertisement
Yeetamus___

Godot_Starter_Game

Dec 9th, 2020
1,516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends Area2D
  2.  
  3.  
  4.  
  5. export var speed = 400  # How fast the player will move (pixels/sec).
  6. var screen_size  # Size of the game window.
  7.  
  8. func _ready():
  9.     screen_size = get_viewport_rect().size
  10.  
  11. func _process(delta):
  12.     var velocity = Vector2()  # The player's movement vector.
  13.     if Input.is_action_pressed("ui_right"):
  14.         velocity.x += 1
  15.     if Input.is_action_pressed("ui_left"):
  16.         velocity.x -= 1
  17.     if Input.is_action_pressed("ui_down"):
  18.         velocity.y += 1
  19.     if Input.is_action_pressed("ui_up"):
  20.         velocity.y -= 1
  21.     if velocity.length() > 0:
  22.         velocity = velocity.normalized() * speed
  23.         $AnimatedSprite.play()
  24.     else:
  25.         $AnimatedSprite.stop()
  26.    
  27.     position += velocity * delta
  28.     position.x = clamp(position.x, 0, screen_size.x)
  29.     position.y = clamp(position.y, 0, screen_size.y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement