-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.gd
54 lines (37 loc) · 1.24 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
extends Area2D
export var speed = 400
var screen_size
signal candy_entered
signal barrier_entered
# Called when the node enters the scene tree for the first time.
func _ready():
screen_size = get_viewport_rect().size
hide()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var velocity = Vector2()
look_at(Vector2(position.x + 500, position.y))
if Input.is_action_pressed("ui_down") || Input.is_key_pressed(KEY_S):
velocity.y += 1
look_at(Vector2(position.x + 500, position.y + 200))
if Input.is_action_pressed("ui_up") || Input.is_key_pressed(KEY_W):
velocity.y -= 1
look_at(Vector2(position.x + 500, position.y - 200))
if velocity.length() > 0:
velocity = velocity.normalized() * speed
position += velocity * delta
if position.y < 0:
position.y = screen_size.y
if position.y > screen_size.y:
position.y = 0
func _on_Player_body_entered(body):
if body.is_in_group("candy"):
emit_signal("candy_entered")
body.explode()
elif body.is_in_group("barrier"):
body.queue_free()
$AnimatedSprite.animation = "explosion"
func _on_AnimatedSprite_animation_finished():
if $AnimatedSprite.animation == "explosion":
$AnimatedSprite.stop()
emit_signal("barrier_entered")