This commit is contained in:
Kirill
2025-11-20 10:02:20 +03:00
parent aecce7d1c4
commit 9f94114aa2
30 changed files with 294 additions and 129 deletions
+32 -47
View File
@@ -1,21 +1,21 @@
extends Node2D
@export var STARRY_SKY_LAYER: PackedScene
@export_group("Visual Settings")
@export var Parallax_2d: Parallax2D
#@export var Node_2d: Node2D
@export var Star_Count: int = 6000: set = set_star_count
@export var Background_Image_Size: Vector2 = Vector2(4096, 4096):
@export var STARRY_SKY_LAYER: PackedScene
@export var Star_Count: int = 2000: set = set_star_count
@export var Background_Image_Size: Vector2 = Vector2(1080, 1920):
set = set_Background_Image_Size
@export var Background_Layers: Array [StarrySkyLayer]
var Stars_by_Layers: Dictionary = {}
const BACKGROUND_COLOR: Color = Color.BLACK
const X_SCROLL_RANGE: Vector2 = Vector2(3, 10)
const Y_SCROLL_RANGE: Vector2 = Vector2(1, 5)
const SCALE_FACTOR = 1
const STAR_COLOR_DISTRIBUTION = [
[700, '#8FA8FFFF', 0 ],
[1700, '#8FA8FFD8', 0 ],
@@ -55,30 +55,17 @@ const STAR_COLOR_DISTRIBUTION = [
[1_000_000, '#E8F4FF28', 2 ],
]
var x_offset: int = 20
var y_offset: int = 20
var _random
func _ready() -> void:
_random = RandomNumberGenerator.new()
x_offset = _random_offset_x() * _random_sign()
y_offset = _random_offset_y() * _random_sign()
Parallax_2d.autoscroll = Vector2(x_offset, y_offset)
initiate_layers()
randomize_parallax()
generate_layers()
#layer.queue_redraw()
func _process(delta: float) -> void:
#Parallax_2d.scroll_offset.x += x_offset * delta
#Parallax_2d.scroll_offset.y += y_offset * delta
if _random.randi_range(0, 2096) == 0:
if _random_sign() == 1:
x_offset = _random_offset_x() * _random_sign()
else:
y_offset = _random_offset_y() * _random_sign()
Parallax_2d.autoscroll = Vector2(x_offset, y_offset)
if randi_range(0, 1000) == 0:
randomize_parallax()
func _draw() -> void:
draw_rect(Rect2(Vector2.ZERO, Background_Image_Size), BACKGROUND_COLOR)
func generate_layers():
var max_rnd_seed = STAR_COLOR_DISTRIBUTION[-1][0]
@@ -97,42 +84,40 @@ func generate_layers():
"color": star_color,
})
break
#draw_circle(star_coords, 1, star_color)
for it1 in Background_Layers:
print(len(it1.Stars))
it1.queue_redraw()
func initiate_layers():
var layer_count = 0
for item:Array in STAR_COLOR_DISTRIBUTION:
if item[2] > layer_count:
layer_count = item[2]
for ind in range(layer_count + 1):
for ind1 in range(layer_count + 1):
var new_star_layer:StarrySkyLayer = STARRY_SKY_LAYER.instantiate()
Parallax_2d.add_child(new_star_layer)
add_child(new_star_layer)
new_star_layer.Background_Image_Size = Background_Image_Size
#new_star_layer.autoscroll = (ind1 + 1) * DEFAULT_AUTOSCROL
Background_Layers.append(new_star_layer)
func draw_layer(layer):
print(layer)
pass
func randomize_parallax():
var x_offset = 0
var y_offset = 0
if _random_sign() == 1:
x_offset = _random_offset(X_SCROLL_RANGE) * _random_sign()
else:
y_offset = _random_offset(Y_SCROLL_RANGE) * _random_sign()
var scale_factor = 1
for layer in Background_Layers:
layer.autoscroll = Vector2(x_offset, y_offset) * scale_factor
scale_factor += SCALE_FACTOR
#region Random offset
func _random_offset_x() -> int:
return _random.randi_range(15, 25)
func _random_offset_y() -> int:
return _random.randi_range(5, 10)
func _random_offset(rng: Vector2i) -> int:
return randi_range(rng.x, rng.y)
func _random_sign() -> int:
if _random.randi_range(1, 2) == 1:
return 1
else:
return -1
return [1, -1].pick_random()
#endregion
#region Сеттеры для автоматического обновления