Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -2,10 +2,9 @@ extends Node2D
|
||||
|
||||
@export_group("Visual Settings")
|
||||
@export var STARRY_SKY_LAYER: PackedScene
|
||||
@export var Star_Count: int = 2000: set = set_star_count
|
||||
@export var Star_Count: int = 2000
|
||||
|
||||
@export var Background_Image_Size: Vector2 = Vector2(1080, 1920):
|
||||
set = set_Background_Image_Size
|
||||
@export var Background_Image_Size: Vector2 = Vector2(1080, 1920)
|
||||
@export var Background_Layers: Array [StarrySkyLayer]
|
||||
|
||||
var Stars_by_Layers: Dictionary = {}
|
||||
@@ -59,10 +58,11 @@ func _ready() -> void:
|
||||
initiate_layers()
|
||||
randomize_parallax()
|
||||
generate_layers()
|
||||
randomize_parallax(0)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if randi_range(0, 1000) == 0:
|
||||
randomize_parallax()
|
||||
#func _process(delta: float) -> void:
|
||||
#if randi_range(0, 1000) == 0:
|
||||
#randomize_parallax()
|
||||
|
||||
func _draw() -> void:
|
||||
draw_rect(Rect2(Vector2.ZERO, Background_Image_Size), BACKGROUND_COLOR)
|
||||
@@ -71,8 +71,8 @@ func generate_layers():
|
||||
var max_rnd_seed = STAR_COLOR_DISTRIBUTION[-1][0]
|
||||
|
||||
for ind1 in range(Star_Count):
|
||||
var star_coords = Vector2(randi_range(0, Background_Image_Size.x),
|
||||
randi_range(0, Background_Image_Size.y))
|
||||
var star_coords = Vector2(randf_range(0, Background_Image_Size.x),
|
||||
randf_range(0, Background_Image_Size.y))
|
||||
var rnd_seed = randi_range(0, max_rnd_seed)
|
||||
for item:Array in STAR_COLOR_DISTRIBUTION:
|
||||
var item_seed = item[0]
|
||||
@@ -94,10 +94,12 @@ func initiate_layers():
|
||||
var new_star_layer:StarrySkyLayer = STARRY_SKY_LAYER.instantiate()
|
||||
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 randomize_parallax():
|
||||
func randomize_parallax(chance: int = 120):
|
||||
if randi_range(0, chance) != 0:
|
||||
return
|
||||
|
||||
var x_offset = 0
|
||||
var y_offset = 0
|
||||
if _random_sign() == 1:
|
||||
@@ -119,14 +121,3 @@ func _random_sign() -> int:
|
||||
return [1, -1].pick_random()
|
||||
|
||||
#endregion
|
||||
|
||||
#region Сеттеры для автоматического обновления
|
||||
func set_Background_Image_Size(value: Vector2):
|
||||
Background_Image_Size = value
|
||||
queue_redraw()
|
||||
|
||||
func set_star_count(value: int):
|
||||
Star_Count = value
|
||||
queue_redraw()
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user