2022-01-23 11:47:18 +01:00
|
|
|
extends Node2D
|
|
|
|
|
2022-01-24 22:12:50 +01:00
|
|
|
var Coin = preload("res://scenes/Coin.tscn")
|
2022-01-23 11:47:18 +01:00
|
|
|
|
|
|
|
# Declare member variables here. Examples:
|
|
|
|
# var a = 2
|
|
|
|
# var b = "text"
|
2022-01-23 14:08:28 +01:00
|
|
|
var coin_spread = 100
|
2022-01-24 22:12:50 +01:00
|
|
|
var coin_lifetime = 5
|
2022-01-23 11:47:18 +01:00
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
|
|
|
assert (Coin != null)
|
|
|
|
pass # Replace with function body.
|
|
|
|
|
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
#func _process(delta):
|
|
|
|
# pass
|
|
|
|
|
2022-01-23 14:08:28 +01:00
|
|
|
func create_coins (num, _position = null):
|
|
|
|
var result = []
|
2022-01-23 11:47:18 +01:00
|
|
|
for i in range (num):
|
|
|
|
var coin = Coin.instance()
|
|
|
|
|
|
|
|
coin.position = position
|
|
|
|
if _position != null:
|
|
|
|
coin.position = _position
|
2022-01-23 14:08:28 +01:00
|
|
|
|
2022-01-24 22:12:50 +01:00
|
|
|
coin.velocity = Vector2 (rand_range(-coin_spread, coin_spread), rand_range (-coin_spread, coin_spread))
|
|
|
|
coin.lifetime = coin_lifetime
|
2022-01-23 11:47:18 +01:00
|
|
|
coin.z_pos = 0
|
|
|
|
coin.z_vel = rand_range(300, 800)
|
2022-01-23 14:08:28 +01:00
|
|
|
result.push_back(coin)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
2022-01-23 11:47:18 +01:00
|
|
|
|
|
|
|
func _unhandled_input(event):
|
|
|
|
if 'position' in event:
|
|
|
|
var relative_pos = self.transform.affine_inverse() * event.position
|
|
|
|
|
|
|
|
if event is InputEventMouseButton:
|
|
|
|
if event.button_index == BUTTON_LEFT and event.pressed:
|
2022-01-23 14:08:28 +01:00
|
|
|
var coins = create_coins(25, relative_pos)
|
|
|
|
for coin in coins:
|
|
|
|
add_child(coin)
|