cosmic/scripts/misc/StarsGeneration.gd
2024-01-13 19:21:55 +05:00

18 lines
675 B
GDScript

extends Node
@export var star : PackedScene
@export var stars_amount = 1000
@export var compress_space_amount = 0.5
func _ready():
var compress_multiplier = 1-compress_space_amount
var map_width_halved = get_tree().current_scene.map_width * compress_multiplier
var map_height_halved = get_tree().current_scene.map_height * compress_multiplier
for i in range(stars_amount):
var star_inst = star.instantiate()
var x = randi_range(-map_width_halved, map_width_halved)
var y = randi_range(-map_height_halved, map_height_halved)
var distance = randi_range(0,get_child_count()-1)
get_children()[distance].add_child(star_inst)
star_inst.position = Vector2(x, y)