001-00009
Skalowanie Czcionka w galaxy Dodanie pliku z Settings Losowanie gwiazd nie ma kolizji
This commit is contained in:
parent
60ff51b2d1
commit
74b0b412bd
63
Manager.gd
63
Manager.gd
@ -2,12 +2,15 @@ extends Node
|
|||||||
# Autoload: Manager
|
# Autoload: Manager
|
||||||
|
|
||||||
# --- KONFIGURACJA ---
|
# --- KONFIGURACJA ---
|
||||||
@export var SECTOR_COUNT: int = 15
|
@export var SECTOR_COUNT: int = 17
|
||||||
@export var PLANETS_PER_SECTOR_RANGE: Vector2 = Vector2(5, 5)
|
@export var PLANETS_PER_SECTOR_RANGE: Vector2 = Vector2(5, 5)
|
||||||
const UPDATE_INTERVAL := 2.0
|
|
||||||
|
const MIN_DISTANCE = 80.0 # Minimalna odległość (promień) między środkami gwiazd
|
||||||
|
const MAX_ATTEMPTS = 50 # Maksymalna liczba prób znalezienia miejsca
|
||||||
|
|
||||||
# --- DANE ---
|
# --- DANE ---
|
||||||
var sectors_data: Array = [] # Każdy element: {"name", "position", "planets", "star"}
|
var sectors_data: Array = [] # Każdy element: {"name", "position", "planets", "star"}
|
||||||
|
var placed_star_positions: Array[Vector2] = []
|
||||||
var current_sector: int = -1
|
var current_sector: int = -1
|
||||||
|
|
||||||
# Timer aktualizacji
|
# Timer aktualizacji
|
||||||
@ -55,7 +58,7 @@ func _ready():
|
|||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
update_timer += delta
|
update_timer += delta
|
||||||
if update_timer >= UPDATE_INTERVAL:
|
if update_timer >= Settings.UPDATE_INTERVAL:
|
||||||
update_timer = 0.0
|
update_timer = 0.0
|
||||||
_update_planets()
|
_update_planets()
|
||||||
|
|
||||||
@ -70,24 +73,26 @@ func get_unique_sector_name() -> String:
|
|||||||
|
|
||||||
# --- INICJALIZACJA SEKTORÓW ---
|
# --- INICJALIZACJA SEKTORÓW ---
|
||||||
func _initialize_sectors():
|
func _initialize_sectors():
|
||||||
var screen_size = get_viewport().get_visible_rect().size
|
|
||||||
|
|
||||||
for i in range(SECTOR_COUNT):
|
for i in range(SECTOR_COUNT):
|
||||||
if sectors_data.size() <= i:
|
if sectors_data.size() <= i:
|
||||||
sectors_data.resize(i + 1)
|
sectors_data.resize(i + 1)
|
||||||
if sectors_data[i] == null:
|
if sectors_data[i] == null:
|
||||||
# Pozycja sektora
|
# Pozycja sektora
|
||||||
var pos = Vector2(
|
var pos = find_safe_position()
|
||||||
randf_range(100, screen_size.x - 200),
|
if pos != Vector2.ZERO:
|
||||||
randf_range(100, screen_size.y - 200)
|
print("Udało się znaleźć miejsca dla gwiazdy.")
|
||||||
)
|
placed_star_positions.append(pos)
|
||||||
|
else:
|
||||||
|
print("Nie udało się znaleźć miejsca dla wszystkich gwiazd.")
|
||||||
|
|
||||||
# Nazwa sektora
|
# Nazwa sektora
|
||||||
var name = get_unique_sector_name()
|
var name = get_unique_sector_name()
|
||||||
|
|
||||||
# Losowa gwiazda
|
# Losowa gwiazda
|
||||||
var star_texture = _random_star_texture()
|
var star_texture = _random_star_texture()
|
||||||
var star_scale = randf_range(0.03, 0.03)
|
var star_scale = randf_range(0.02, 0.04)
|
||||||
|
|
||||||
# Utworzenie sektora
|
# Utworzenie sektora
|
||||||
sectors_data[i] = {
|
sectors_data[i] = {
|
||||||
@ -190,20 +195,28 @@ func _random_star_texture() -> String:
|
|||||||
var id = randi_range(1, 8)
|
var id = randi_range(1, 8)
|
||||||
return "res://assets/stars/s%d.png" % id
|
return "res://assets/stars/s%d.png" % id
|
||||||
|
|
||||||
func generate_non_overlapping_position(existing_positions: Array, min_distance: float, screen_size: Vector2) -> Vector2:
|
|
||||||
var pos: Vector2
|
func find_safe_position() -> Vector2:
|
||||||
var attempts = 0
|
var screen_size = get_viewport().get_visible_rect().size
|
||||||
while true:
|
for attempt in range(MAX_ATTEMPTS):
|
||||||
pos = Vector2(
|
# 1. Losowanie potencjalnej pozycji w obszarze (zgodnie z Twoimi marginesami)
|
||||||
randf_range(100, screen_size.x - 200),
|
var potential_pos = Vector2(
|
||||||
randf_range(100, screen_size.y - 200)
|
randf_range(50, screen_size.x - 50),
|
||||||
|
randf_range(50, screen_size.y - 50)
|
||||||
)
|
)
|
||||||
var overlap = false
|
|
||||||
for other in existing_positions:
|
# 2. Sprawdzenie, czy pozycja jest bezpieczna
|
||||||
if pos.distance_to(other) < min_distance:
|
if is_position_safe(potential_pos):
|
||||||
overlap = true
|
return potential_pos # Znaleziono bezpieczną pozycję!
|
||||||
break
|
|
||||||
attempts += 1
|
# 3. Jeśli po MAX_ATTEMPTS nie znaleziono miejsca
|
||||||
if not overlap or attempts > 100:
|
print("Osiągnięto limit prób, nie można znaleźć bezpiecznego miejsca.")
|
||||||
break
|
return Vector2.ZERO # Zwróć zero, aby zasygnalizować błąd
|
||||||
return pos
|
|
||||||
|
func is_position_safe(potential_pos: Vector2) -> bool:
|
||||||
|
for existing_pos in placed_star_positions:
|
||||||
|
var distance = potential_pos.distance_to(existing_pos)
|
||||||
|
if distance < MIN_DISTANCE:
|
||||||
|
return false # Kolizja znaleziona
|
||||||
|
return true # Brak kolizji z żadną istniejącą gwiazdą
|
||||||
|
|
||||||
|
|||||||
BIN
assets/fonts/font3.ttf
Normal file
BIN
assets/fonts/font3.ttf
Normal file
Binary file not shown.
36
assets/fonts/font3.ttf.import
Normal file
36
assets/fonts/font3.ttf.import
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="font_data_dynamic"
|
||||||
|
type="FontFile"
|
||||||
|
uid="uid://choploj3iec0a"
|
||||||
|
path="res://.godot/imported/font3.ttf-2cd23d8fac261e9271189c108512bad4.fontdata"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/fonts/font3.ttf"
|
||||||
|
dest_files=["res://.godot/imported/font3.ttf-2cd23d8fac261e9271189c108512bad4.fontdata"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
Rendering=null
|
||||||
|
antialiasing=1
|
||||||
|
generate_mipmaps=false
|
||||||
|
disable_embedded_bitmaps=true
|
||||||
|
multichannel_signed_distance_field=false
|
||||||
|
msdf_pixel_range=8
|
||||||
|
msdf_size=48
|
||||||
|
allow_system_fallback=true
|
||||||
|
force_autohinter=false
|
||||||
|
modulate_color_glyphs=false
|
||||||
|
hinting=1
|
||||||
|
subpixel_positioning=4
|
||||||
|
keep_rounding_remainders=true
|
||||||
|
oversampling=0.0
|
||||||
|
Fallbacks=null
|
||||||
|
fallbacks=[]
|
||||||
|
Compress=null
|
||||||
|
compress=true
|
||||||
|
preload=[]
|
||||||
|
language_support={}
|
||||||
|
script_support={}
|
||||||
|
opentype_features={}
|
||||||
@ -19,6 +19,7 @@ config/icon="res://icon.svg"
|
|||||||
|
|
||||||
Manager="*res://Manager.gd"
|
Manager="*res://Manager.gd"
|
||||||
MusicManager="*res://music_manager.gd"
|
MusicManager="*res://music_manager.gd"
|
||||||
|
Settings="*res://scripts/settings.gd"
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|
||||||
|
|||||||
@ -39,12 +39,12 @@ layout_mode = 1
|
|||||||
anchors_preset = 2
|
anchors_preset = 2
|
||||||
anchor_top = 1.0
|
anchor_top = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
offset_left = 23.999998
|
offset_left = 14.0
|
||||||
offset_top = -238.00006
|
offset_top = -186.0
|
||||||
offset_right = 474.0
|
offset_right = 464.0
|
||||||
offset_bottom = 388.0
|
offset_bottom = 420.66687
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
scale = Vector2(0.4, 0.4)
|
scale = Vector2(0.3, 0.3)
|
||||||
|
|
||||||
[node name="start" type="TextureButton" parent="VBoxContainer"]
|
[node name="start" type="TextureButton" parent="VBoxContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|||||||
@ -9,10 +9,13 @@ func _ready():
|
|||||||
|
|
||||||
# --- TWORZENIE GWIAZD SEKTORÓW ---
|
# --- TWORZENIE GWIAZD SEKTORÓW ---
|
||||||
const GLOBAL_STAR_REDUCTION = 0.45 # Zmniejsza gwiazdy do 65% oryginalnego rozmiaru
|
const GLOBAL_STAR_REDUCTION = 0.45 # Zmniejsza gwiazdy do 65% oryginalnego rozmiaru
|
||||||
|
const FONT_PATH := "res://assets/fonts/font3.ttf"
|
||||||
func _create_sector_buttons():
|
func _create_sector_buttons():
|
||||||
for child in container.get_children():
|
for child in container.get_children():
|
||||||
child.queue_free()
|
child.queue_free()
|
||||||
|
|
||||||
|
var font = load(FONT_PATH)
|
||||||
|
|
||||||
for i in range(Manager.SECTOR_COUNT):
|
for i in range(Manager.SECTOR_COUNT):
|
||||||
var sector_info = Manager.get_sector(i)
|
var sector_info = Manager.get_sector(i)
|
||||||
|
|
||||||
@ -20,35 +23,42 @@ func _create_sector_buttons():
|
|||||||
button.texture_normal = load(sector_info["star"]["texture_path"])
|
button.texture_normal = load(sector_info["star"]["texture_path"])
|
||||||
button.stretch_mode = TextureButton.STRETCH_KEEP_ASPECT_CENTERED
|
button.stretch_mode = TextureButton.STRETCH_KEEP_ASPECT_CENTERED
|
||||||
|
|
||||||
# Skala zapisanej gwiazdy
|
# Skala gwiazdy
|
||||||
var star_scale = sector_info["star"]["scale"]
|
var star_scale = sector_info["star"]["scale"] * GLOBAL_STAR_REDUCTION
|
||||||
var final_scale = star_scale * GLOBAL_STAR_REDUCTION
|
button.scale = Vector2(star_scale, star_scale)
|
||||||
button.scale = Vector2(final_scale, final_scale)
|
|
||||||
|
|
||||||
# Pozycja z Managera
|
|
||||||
button.position = sector_info["position"]
|
button.position = sector_info["position"]
|
||||||
|
print(button.scale)
|
||||||
|
# --- Podpis sektora ---
|
||||||
|
var label = Label.new()
|
||||||
|
label.text = sector_info["name"]
|
||||||
|
label.add_theme_font_override("font", font)
|
||||||
|
label.scale = Vector2(1 / star_scale, 1 / star_scale)
|
||||||
|
# Ustawienie grubości konturu
|
||||||
|
label.add_theme_constant_override("outline_size", 2) # Grubość konturu 2px
|
||||||
|
|
||||||
# Podpis sektora
|
# Ustawienie koloru konturu
|
||||||
var sector_label = Label.new()
|
label.add_theme_color_override("font_outline_color", Color.BLACK)
|
||||||
sector_label.text = sector_info["name"]
|
|
||||||
sector_label.modulate = Color(0.979, 0.808, 0.764, 1.0) # czerwony
|
|
||||||
#sector_label.scale = Vector2(0.5, 0.5) # ignoruje skalę gwiazdy
|
|
||||||
|
|
||||||
sector_label.add_theme_font_size_override("font_size", 600) # malutki podpis
|
label.add_theme_font_size_override("font_size", 9)
|
||||||
sector_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
label.modulate = Color(0.887, 0.867, 0.836, 1.0)
|
||||||
sector_label.position = Vector2(-1002, -650)
|
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||||
|
label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||||
|
|
||||||
# 🔹 Ustawienie czcionki:
|
# umieszczamy labelkę POD gwiazdą (np. 60 px niżej)
|
||||||
# ✅ Poprawne ładowanie czcionki
|
var button_width = button.size.x
|
||||||
var font = load("res://assets/fonts/font2.ttf")
|
var button_height = button.size.y
|
||||||
sector_label.add_theme_font_override("font", font)
|
|
||||||
|
|
||||||
button.add_child(sector_label)
|
# ... reszta kodu do centrowania i pozycjonowania
|
||||||
|
|
||||||
|
label.position = Vector2(
|
||||||
|
button_width / 2 - label.get_rect().size.x / 2, # Centrujemy względem X
|
||||||
|
button_height + 60 # 60 jednostek poniżej dolnej krawędzi przycisku
|
||||||
|
)
|
||||||
|
|
||||||
|
button.add_child(label)
|
||||||
|
|
||||||
var index = i
|
var index = i
|
||||||
button.pressed.connect(func() -> void:
|
button.pressed.connect(func(): _on_sector_selected(index))
|
||||||
_on_sector_selected(index)
|
|
||||||
)
|
|
||||||
|
|
||||||
container.add_child(button)
|
container.add_child(button)
|
||||||
|
|
||||||
|
|||||||
@ -5,8 +5,7 @@ var PlanetScene = preload("res://scenes/planet.tscn")
|
|||||||
@onready var PlanetStatPanel = $PlanetStatPanel
|
@onready var PlanetStatPanel = $PlanetStatPanel
|
||||||
@onready var BackButton: TextureButton = $BackButton
|
@onready var BackButton: TextureButton = $BackButton
|
||||||
|
|
||||||
var ORBIT_STEP = 60
|
|
||||||
const FIRST_ORBIT_STEP = 80
|
|
||||||
var tracked_planet: Node = null
|
var tracked_planet: Node = null
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
@ -61,9 +60,9 @@ func spawn_planets():
|
|||||||
planet_node.data = planet_data
|
planet_node.data = planet_data
|
||||||
planet_node.orbit_center = center
|
planet_node.orbit_center = center
|
||||||
if i == 0:
|
if i == 0:
|
||||||
planet_node.orbit_radius = planet_data.get("orbit_radius", FIRST_ORBIT_STEP * (i + 1))
|
planet_node.orbit_radius = planet_data.get("orbit_radius", Settings.FIRST_ORBIT_STEP * (i + 1))
|
||||||
else:
|
else:
|
||||||
planet_node.orbit_radius = planet_data.get("orbit_radius", ORBIT_STEP * (i + 1))
|
planet_node.orbit_radius = planet_data.get("orbit_radius", Settings.ORBIT_STEP * (i + 1))
|
||||||
|
|
||||||
planet_node.angle = planet_data.get("angle", randf() * TAU)
|
planet_node.angle = planet_data.get("angle", randf() * TAU)
|
||||||
planet_node.rotation_speed = planet_data.get("rotation_speed", randf_range(0.00001, 1))
|
planet_node.rotation_speed = planet_data.get("rotation_speed", randf_range(0.00001, 1))
|
||||||
|
|||||||
4
scripts/settings.gd
Normal file
4
scripts/settings.gd
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
extends Node
|
||||||
|
const UPDATE_INTERVAL := 30.0 #Cykl w sekundach
|
||||||
|
var ORBIT_STEP = 60 #odległośc miedzy orbitami
|
||||||
|
const FIRST_ORBIT_STEP = 80 #pierwsza planeta od gwiazdy
|
||||||
1
scripts/settings.gd.uid
Normal file
1
scripts/settings.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://drqjlcgywn2db
|
||||||
Loading…
x
Reference in New Issue
Block a user