-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.gd
58 lines (43 loc) · 1.21 KB
/
Player.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
extends Area2D
export var speed = 100
var screen_size
signal hit
func start(pos):
position = pos
show()
$CollisionShape2D.disabled = false
# Called when the node enters the scene tree for the first time.
func _ready():
screen_size = get_viewport_rect().size
#hide()
show()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var velocity = Vector2()
if Input.is_action_pressed("ui_up"):
$AnimatedSprite.animation = "up"
velocity.y -= 1
elif Input.is_action_pressed("ui_down"):
$AnimatedSprite.animation = "down"
velocity.y += 1
elif Input.is_action_pressed("ui_left"):
$AnimatedSprite.animation = "left"
velocity.x -= 1
elif Input.is_action_pressed("ui_right"):
$AnimatedSprite.animation = "right"
velocity.x += 1
if velocity.length() > 0:
velocity = velocity.normalized() * speed
$AnimatedSprite.play()
$Step.play()
else:
$AnimatedSprite.stop()
$Step.stop()
position += velocity * delta
position.x = clamp(position.x, 0, screen_size.x)
position.y = clamp(position.y, 0, screen_size.y)
yield($Step, "finished")
func _on_Player_body_entered(body):
# hide()
emit_signal("hit")
$CollisionShape2D.set_deferred("disabled", true)