godot-start/script/demo13_camera/player.gd

30 lines
622 B
GDScript
Raw Normal View History

2021-10-07 01:31:11 +00:00
extends Sprite
# How fast the player will move (pixels/sec).
export var speed = 400
# Size of the game window.
var screen_size
func _ready():
screen_size = get_viewport_rect().size
func _process(delta):
var velocity = Vector2.ZERO # The player's movement vector.
if Input.is_action_pressed("move_right"):
velocity.x += 1
if Input.is_action_pressed("move_left"):
velocity.x -= 1
if Input.is_action_pressed("move_down"):
velocity.y += 1
if Input.is_action_pressed("move_up"):
velocity.y -= 1
if velocity.length() <= 0:
return
velocity = velocity.normalized() * speed
position += velocity * delta