-
Notifications
You must be signed in to change notification settings - Fork 0
/
Coin.gd
38 lines (32 loc) · 861 Bytes
/
Coin.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
extends Area2D
export var min_speed = 500
export var max_speed = 700
var velocity
var value = 2
signal coin_hit
var ran
# Called when the node enters the scene tree for the first time.
func _ready():
var coin_types = $AnimatedSprite.frames.get_animation_names()
ran = randf() * 100
if (ran >= 0 && ran <= 10):
print("Gold coin")
$AnimatedSprite.animation = coin_types[1]
value = 5
elif (ran > 10 && ran <= 40):
print("Silver coin")
$AnimatedSprite.animation = coin_types[2]
value = 3
else:
print("Bronze coin")
$AnimatedSprite.animation = coin_types[0]
value = 2
$AnimatedSprite.play()
velocity = Vector2(rand_range(min_speed, max_speed), 0)
func _process(delta):
position -= velocity * delta
func _on_VisibilityNotifier2D_screen_exited():
queue_free()
func _on_Coin_body_entered(_body):
emit_signal("coin_hit")
queue_free()