001-00009

Skalowanie
Czcionka w galaxy
Dodanie pliku z Settings
Losowanie gwiazd nie ma kolizji
This commit is contained in:
Tomasz Boruc 2025-10-22 22:00:13 +02:00
parent 60ff51b2d1
commit 74b0b412bd
9 changed files with 125 additions and 61 deletions

View File

@ -2,12 +2,15 @@ extends Node
# Autoload: Manager
# --- KONFIGURACJA ---
@export var SECTOR_COUNT: int = 15
@export var SECTOR_COUNT: int = 17
@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 ---
var sectors_data: Array = [] # Każdy element: {"name", "position", "planets", "star"}
var placed_star_positions: Array[Vector2] = []
var current_sector: int = -1
# Timer aktualizacji
@ -55,7 +58,7 @@ func _ready():
func _process(delta):
update_timer += delta
if update_timer >= UPDATE_INTERVAL:
if update_timer >= Settings.UPDATE_INTERVAL:
update_timer = 0.0
_update_planets()
@ -70,24 +73,26 @@ func get_unique_sector_name() -> String:
# --- INICJALIZACJA SEKTORÓW ---
func _initialize_sectors():
var screen_size = get_viewport().get_visible_rect().size
for i in range(SECTOR_COUNT):
if sectors_data.size() <= i:
sectors_data.resize(i + 1)
if sectors_data[i] == null:
# Pozycja sektora
var pos = Vector2(
randf_range(100, screen_size.x - 200),
randf_range(100, screen_size.y - 200)
)
var pos = find_safe_position()
if pos != Vector2.ZERO:
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
var name = get_unique_sector_name()
# Losowa gwiazda
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
sectors_data[i] = {
@ -190,20 +195,28 @@ func _random_star_texture() -> String:
var id = randi_range(1, 8)
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
var attempts = 0
while true:
pos = Vector2(
randf_range(100, screen_size.x - 200),
randf_range(100, screen_size.y - 200)
func find_safe_position() -> Vector2:
var screen_size = get_viewport().get_visible_rect().size
for attempt in range(MAX_ATTEMPTS):
# 1. Losowanie potencjalnej pozycji w obszarze (zgodnie z Twoimi marginesami)
var potential_pos = Vector2(
randf_range(50, screen_size.x - 50),
randf_range(50, screen_size.y - 50)
)
var overlap = false
for other in existing_positions:
if pos.distance_to(other) < min_distance:
overlap = true
break
attempts += 1
if not overlap or attempts > 100:
break
return pos
# 2. Sprawdzenie, czy pozycja jest bezpieczna
if is_position_safe(potential_pos):
return potential_pos # Znaleziono bezpieczną pozycję!
# 3. Jeśli po MAX_ATTEMPTS nie znaleziono miejsca
print("Osiągnięto limit prób, nie można znaleźć bezpiecznego miejsca.")
return Vector2.ZERO # Zwróć zero, aby zasygnalizować błąd
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

Binary file not shown.

View 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={}

View File

@ -19,6 +19,7 @@ config/icon="res://icon.svg"
Manager="*res://Manager.gd"
MusicManager="*res://music_manager.gd"
Settings="*res://scripts/settings.gd"
[display]

View File

@ -39,12 +39,12 @@ layout_mode = 1
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_left = 23.999998
offset_top = -238.00006
offset_right = 474.0
offset_bottom = 388.0
offset_left = 14.0
offset_top = -186.0
offset_right = 464.0
offset_bottom = 420.66687
grow_vertical = 0
scale = Vector2(0.4, 0.4)
scale = Vector2(0.3, 0.3)
[node name="start" type="TextureButton" parent="VBoxContainer"]
layout_mode = 2

View File

@ -9,10 +9,13 @@ func _ready():
# --- TWORZENIE GWIAZD SEKTORÓW ---
const GLOBAL_STAR_REDUCTION = 0.45 # Zmniejsza gwiazdy do 65% oryginalnego rozmiaru
const FONT_PATH := "res://assets/fonts/font3.ttf"
func _create_sector_buttons():
for child in container.get_children():
child.queue_free()
var font = load(FONT_PATH)
for i in range(Manager.SECTOR_COUNT):
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.stretch_mode = TextureButton.STRETCH_KEEP_ASPECT_CENTERED
# Skala zapisanej gwiazdy
var star_scale = sector_info["star"]["scale"]
var final_scale = star_scale * GLOBAL_STAR_REDUCTION
button.scale = Vector2(final_scale, final_scale)
# Pozycja z Managera
# Skala gwiazdy
var star_scale = sector_info["star"]["scale"] * GLOBAL_STAR_REDUCTION
button.scale = Vector2(star_scale, star_scale)
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
var sector_label = Label.new()
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
# Ustawienie koloru konturu
label.add_theme_color_override("font_outline_color", Color.BLACK)
sector_label.add_theme_font_size_override("font_size", 600) # malutki podpis
sector_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
sector_label.position = Vector2(-1002, -650)
label.add_theme_font_size_override("font_size", 9)
label.modulate = Color(0.887, 0.867, 0.836, 1.0)
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
# 🔹 Ustawienie czcionki:
# ✅ Poprawne ładowanie czcionki
var font = load("res://assets/fonts/font2.ttf")
sector_label.add_theme_font_override("font", font)
# umieszczamy labelkę POD gwiazdą (np. 60 px niżej)
var button_width = button.size.x
var button_height = button.size.y
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
button.pressed.connect(func() -> void:
_on_sector_selected(index)
)
button.pressed.connect(func(): _on_sector_selected(index))
container.add_child(button)

View File

@ -5,8 +5,7 @@ var PlanetScene = preload("res://scenes/planet.tscn")
@onready var PlanetStatPanel = $PlanetStatPanel
@onready var BackButton: TextureButton = $BackButton
var ORBIT_STEP = 60
const FIRST_ORBIT_STEP = 80
var tracked_planet: Node = null
func _ready():
@ -61,9 +60,9 @@ func spawn_planets():
planet_node.data = planet_data
planet_node.orbit_center = center
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:
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.rotation_speed = planet_data.get("rotation_speed", randf_range(0.00001, 1))

4
scripts/settings.gd Normal file
View 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
View File

@ -0,0 +1 @@
uid://drqjlcgywn2db