32 lines
784 B
GDScript3
32 lines
784 B
GDScript3
extends KinematicBody2D
|
|
|
|
signal moved(position)
|
|
|
|
# Declare member variables here.
|
|
export var speed = 720
|
|
var paused = false
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
pass # Replace with function body.
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
#func _process(delta):
|
|
# pass
|
|
|
|
func _physics_process(delta):
|
|
if not paused:
|
|
var velocity = Vector2()
|
|
if Input.is_action_pressed('ui_right'):
|
|
velocity = Vector2(speed, 1)
|
|
if Input.is_action_pressed('ui_left'):
|
|
velocity = Vector2(- speed, 1)
|
|
var _collision = move_and_collide(delta * velocity)
|
|
emit_signal("moved", position)
|
|
|
|
func pause():
|
|
paused = true
|
|
|
|
func unpause():
|
|
paused = false
|