2020-08-17 14:37:07 +02:00
|
|
|
extends RigidBody2D
|
|
|
|
|
|
|
|
|
|
|
|
var dir = Vector2(0, 0)
|
|
|
|
|
2020-08-19 18:59:29 +02:00
|
|
|
var sleep = true
|
|
|
|
|
|
|
|
var input_right = false
|
|
|
|
var input_left = false
|
|
|
|
var input_up = false
|
|
|
|
var input_down = false
|
|
|
|
|
2020-08-17 14:37:07 +02:00
|
|
|
func _input(event):
|
2020-08-19 18:59:29 +02:00
|
|
|
if sleep: return
|
|
|
|
|
2020-08-17 14:37:07 +02:00
|
|
|
if event.is_action_pressed('left'):
|
2020-08-19 18:59:29 +02:00
|
|
|
input_left = true
|
2020-08-17 14:37:07 +02:00
|
|
|
if event.is_action_released('left'):
|
2020-08-19 18:59:29 +02:00
|
|
|
input_left = false
|
2020-08-17 14:37:07 +02:00
|
|
|
if event.is_action_pressed('right'):
|
2020-08-19 18:59:29 +02:00
|
|
|
input_right = true
|
2020-08-17 14:37:07 +02:00
|
|
|
if event.is_action_released('right'):
|
2020-08-19 18:59:29 +02:00
|
|
|
input_right = false
|
2020-08-17 14:37:07 +02:00
|
|
|
|
|
|
|
if event.is_action_pressed('up'):
|
2020-08-19 18:59:29 +02:00
|
|
|
input_up = true
|
2020-08-17 14:37:07 +02:00
|
|
|
if event.is_action_released('up'):
|
2020-08-19 18:59:29 +02:00
|
|
|
input_up = false
|
2020-08-17 14:37:07 +02:00
|
|
|
if event.is_action_pressed('down'):
|
2020-08-19 18:59:29 +02:00
|
|
|
input_down = true
|
2020-08-17 14:37:07 +02:00
|
|
|
if event.is_action_released('down'):
|
2020-08-19 18:59:29 +02:00
|
|
|
input_down = false
|
|
|
|
|
|
|
|
var x = 0
|
|
|
|
var y = 0
|
|
|
|
|
|
|
|
if input_left: x -= 1
|
|
|
|
if input_right: x += 1
|
|
|
|
if input_up: y -= 1
|
|
|
|
if input_down: y += 1
|
2020-08-17 14:37:07 +02:00
|
|
|
|
2020-08-19 18:59:29 +02:00
|
|
|
dir = Vector2(x, y)
|
2020-08-17 14:37:07 +02:00
|
|
|
|
|
|
|
func _process(delta):
|
|
|
|
if linear_velocity.length_squared() < 1:
|
|
|
|
$Sprite.play('default')
|
|
|
|
elif linear_velocity.x > 0:
|
|
|
|
$Sprite.play('right')
|
|
|
|
else:
|
|
|
|
$Sprite.play('left')
|
|
|
|
|
|
|
|
func _physics_process(delta : float):
|
2020-08-20 12:01:19 +02:00
|
|
|
if sleep: return
|
2020-08-17 14:37:07 +02:00
|
|
|
apply_central_impulse(dir.normalized() * 10)
|
|
|
|
|