0.1-0002
Losowanie pozycji gwiazd w galaktyce
This commit is contained in:
parent
4ad0ca91f8
commit
aa4b9452d5
134
Manager.gd
134
Manager.gd
@ -1,57 +1,78 @@
|
||||
extends Node
|
||||
#class_name Manager
|
||||
|
||||
# Globalne ustawienia
|
||||
@export var SECTOR_COUNT: int = 15
|
||||
@export var PLANETS_PER_SECTOR_RANGE: Vector2 = Vector2(1, 5) # min i max planet
|
||||
# --- KONFIGURACJA ---
|
||||
@export var SECTOR_COUNT: int = 10
|
||||
@export var PLANETS_PER_SECTOR_RANGE: Vector2 = Vector2(1, 5)
|
||||
|
||||
# Lista sektorów (każdy sektor to słownik z planetami)
|
||||
var sectors_data: Array = []
|
||||
|
||||
# Aktualnie wybrany sektor
|
||||
# --- DANE ---
|
||||
var sectors_data: Array = [] # Każdy element: {"name": str, "position": Vector2, "planets": Array, "star": Dictionary}
|
||||
var current_sector: int = -1
|
||||
|
||||
# Timer aktualizacji
|
||||
var update_timer := 0.0
|
||||
const UPDATE_INTERVAL := 30.0
|
||||
# Nazwy sektorów i planet
|
||||
var sector_names = [
|
||||
"Aetherion", "Altaris", "Andur System", "Artemis Reach", "Astrion",
|
||||
"Azura Prime", "Borealis Expanse", "Caldris Belt", "Canthar System", "Celion Verge",
|
||||
"Corvax Sector", "Cygnera Rift", "Daedalus Reach", "Darnis Cluster", "Dravon Expanse"
|
||||
]
|
||||
|
||||
# Nazwy planet
|
||||
var planet_names = [
|
||||
"Arcturus","Betelgeuse","Canopus","Deneb","Elnath",
|
||||
"Fomalhaut","Gacrux","Hadar","Izar","Jabbah",
|
||||
"Kaus","Lesath","Menkent","Nunki","Okul",
|
||||
"Pollux","Rigel","Sargas","Toliman","Unukalhai",
|
||||
"Vega","Wezen","Xamidimura","Yildun","Zosma",
|
||||
"Alkaid","Baten","Caph","Diphda","Electra"
|
||||
"Vega","Wezen","Xamidimura","Yildun","Zosma"
|
||||
]
|
||||
|
||||
# --- START ---
|
||||
func _ready():
|
||||
randomize()
|
||||
_initialize_sectors()
|
||||
print("[Manager] Initialized global manager with %d sectors" % SECTOR_COUNT)
|
||||
print(sectors_data[0])
|
||||
|
||||
func _process(delta):
|
||||
update_timer += delta
|
||||
if update_timer >= UPDATE_INTERVAL:
|
||||
update_timer = 0.0
|
||||
_update_planets()
|
||||
# --- LOSOWANIE UNIKALNEJ NAZWY SEKTORA ---
|
||||
func get_unique_sector_name() -> String:
|
||||
if sector_names.size() == 0:
|
||||
return "Unknown Sector"
|
||||
var index = randi() % sector_names.size()
|
||||
var name = sector_names[index]
|
||||
sector_names.remove_at(index)
|
||||
return name
|
||||
|
||||
# --- Inicjalizacja wszystkich sektorów z losowymi planetami ---
|
||||
# --- 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:
|
||||
sectors_data[i] = {"planets": []}
|
||||
# Losowa pozycja
|
||||
var pos = Vector2(
|
||||
randf_range(100, screen_size.x - 200),
|
||||
randf_range(100, screen_size.y - 200)
|
||||
)
|
||||
|
||||
# Unikalna nazwa
|
||||
var name = get_unique_sector_name()
|
||||
|
||||
# Utwórz sektor
|
||||
var scale = randf_range(0.03, 0.08)
|
||||
|
||||
sectors_data[i] = {
|
||||
"name": name,
|
||||
"position": pos,
|
||||
"star_scale": scale,
|
||||
"planets": [],
|
||||
"star": {}
|
||||
}
|
||||
|
||||
|
||||
# Losowe planety
|
||||
var planet_count = randi_range(PLANETS_PER_SECTOR_RANGE.x, PLANETS_PER_SECTOR_RANGE.y)
|
||||
for j in range(planet_count):
|
||||
var size = randi_range(1, 3)
|
||||
var growth_rate = randf_range(0.1, 1.0)
|
||||
var texture_planet: String
|
||||
if growth_rate > 0.7:
|
||||
texture_planet = "res://assets/planets/p%d.png" % randi_range(1,9)
|
||||
else:
|
||||
texture_planet = "res://assets/planets/p%d.png" % randi_range(10,18)
|
||||
var texture_planet = "res://assets/planets/p%d.png" % randi_range(1,18)
|
||||
var planet = {
|
||||
"name": planet_names[randi() % planet_names.size()],
|
||||
"size": size,
|
||||
@ -63,24 +84,11 @@ func _initialize_sectors():
|
||||
"is_colonized": false,
|
||||
"angle": randf() * TAU,
|
||||
"rotation_speed": randf_range(0.001, 0.02),
|
||||
"texture_path": texture_planet,
|
||||
"texture_path": texture_planet
|
||||
}
|
||||
sectors_data[i]["planets"].append(planet)
|
||||
|
||||
# --- Aktualizacja planet dla wszystkich sektorów ---
|
||||
func _update_planets():
|
||||
for sector in sectors_data:
|
||||
if sector == null:
|
||||
continue
|
||||
for planet in sector["planets"]:
|
||||
if planet["is_colonized"]:
|
||||
var growth = int(max(1, planet["population"] * 0.05 * planet["growth_rate"]))
|
||||
planet["population"] = min(planet["population"] + growth, planet["max_population"])
|
||||
planet["resources"] += get_mined_per_cycle(planet)
|
||||
|
||||
func get_mined_per_cycle(planet: Dictionary) -> float:
|
||||
return planet["mining_rate"] * pow(planet["population"], 0.5) * 0.05
|
||||
|
||||
# --- FUNKCJE POMOCNICZE ---
|
||||
func get_max_population(size: int) -> int:
|
||||
match size:
|
||||
1: return 1000
|
||||
@ -89,35 +97,23 @@ func get_max_population(size: int) -> int:
|
||||
4: return 30000
|
||||
return 1000
|
||||
|
||||
# --- Pobranie planety po nazwie w bieżącym sektorze ---
|
||||
func get_planet_by_name(name: String) -> Dictionary:
|
||||
if current_sector < 0 or current_sector >= sectors_data.size():
|
||||
return {}
|
||||
var sector = sectors_data[current_sector]
|
||||
for planet in sector["planets"]:
|
||||
if planet["name"] == name:
|
||||
return planet
|
||||
func get_sector(index: int) -> Dictionary:
|
||||
if index >= 0 and index < sectors_data.size():
|
||||
return sectors_data[index]
|
||||
return {}
|
||||
|
||||
# --- Rejestracja nowej planety w danym sektorze ---
|
||||
func register_planet(sector_index: int, planet_name: String, size: int, mining_rate: float, growth_rate: float) -> Dictionary:
|
||||
func get_planets(index: int) -> Array:
|
||||
var sector = get_sector(index)
|
||||
if sector.has("planets"):
|
||||
return sector["planets"]
|
||||
return []
|
||||
|
||||
func register_planet(sector_index: int, planet_data: Dictionary):
|
||||
if sectors_data.size() <= sector_index:
|
||||
sectors_data.resize(sector_index + 1)
|
||||
if sectors_data[sector_index] == null:
|
||||
sectors_data[sector_index] = {"planets": []}
|
||||
|
||||
var planet = {
|
||||
"name": planet_name,
|
||||
"size": size,
|
||||
"population": 0,
|
||||
"max_population": get_max_population(size),
|
||||
"resources": 0.0,
|
||||
"mining_rate": mining_rate,
|
||||
"growth_rate": growth_rate,
|
||||
"is_colonized": false,
|
||||
"angle": randf() * TAU,
|
||||
"rotation_speed": randf_range(0.01, 0.04),
|
||||
"texture_path": "res://assets/planets/p%d.png" % randi_range(1,18)
|
||||
}
|
||||
sectors_data[sector_index]["planets"].append(planet)
|
||||
return planet
|
||||
sectors_data[sector_index] = {"planets": [], "name":"Unknown", "position": Vector2.ZERO, "star":{}}
|
||||
sectors_data[sector_index]["planets"].append(planet_data)
|
||||
|
||||
func get_mined_per_cycle(planet: Dictionary) -> float:
|
||||
return planet["mining_rate"] * pow(planet["population"], 0.5) * 0.05
|
||||
|
||||
BIN
assets/background/galaxy_background.jpg
Normal file
BIN
assets/background/galaxy_background.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 MiB |
40
assets/background/galaxy_background.jpg.import
Normal file
40
assets/background/galaxy_background.jpg.import
Normal file
@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://dvydsg5o77wdm"
|
||||
path="res://.godot/imported/galaxy_background.jpg-c8eb9ea5017da972f713c4f12517b8c3.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/background/galaxy_background.jpg"
|
||||
dest_files=["res://.godot/imported/galaxy_background.jpg-c8eb9ea5017da972f713c4f12517b8c3.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 1.1 MiB |
@ -7,7 +7,7 @@ layout_mode = 3
|
||||
anchors_preset = 0
|
||||
script = ExtResource("1_n7ltq")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
layout_mode = 0
|
||||
[node name="VBoxContainer" type="Control" parent="."]
|
||||
anchors_preset = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
|
||||
@ -1,26 +1,64 @@
|
||||
extends Control
|
||||
|
||||
#@export var SECTOR_COUNT: int = 15
|
||||
@export var SectorScenePath: String = "res://scenes/Sector.tscn"
|
||||
@onready var container = $VBoxContainer
|
||||
|
||||
func _ready():
|
||||
_init_background()
|
||||
_create_sector_buttons()
|
||||
|
||||
# --- TWORZENIE GWIAZD SEKTORÓW ---
|
||||
func _create_sector_buttons():
|
||||
for child in container.get_children():
|
||||
child.queue_free()
|
||||
|
||||
var screen_size = get_viewport_rect().size
|
||||
|
||||
for i in range(Manager.SECTOR_COUNT):
|
||||
var button = Button.new()
|
||||
button.text = "Sector %d" % (i+1)
|
||||
button.custom_minimum_size = Vector2(200, 40)
|
||||
var sector_info = Manager.get_sector(i)
|
||||
|
||||
var button = TextureButton.new()
|
||||
button.texture_normal = preload("res://assets/stars/s1.png")
|
||||
button.stretch_mode = TextureButton.STRETCH_KEEP_ASPECT_CENTERED
|
||||
|
||||
# 🎨 Losowy rozmiar gwiazdy
|
||||
|
||||
button.scale = Vector2(sector_info["star_scale"], sector_info["star_scale"])
|
||||
|
||||
|
||||
# Pozycja z Managera
|
||||
button.position = sector_info["position"]
|
||||
|
||||
# Podpis sektora
|
||||
var sector_label = Label.new()
|
||||
sector_label.text = sector_info["name"]
|
||||
sector_label.add_theme_font_size_override("font_size", 350) # malutki podpis
|
||||
sector_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
sector_label.position = Vector2(0, -450)
|
||||
button.add_child(sector_label)
|
||||
|
||||
var index = i
|
||||
button.pressed.connect(func() -> void:
|
||||
_on_sector_selected(index)
|
||||
)
|
||||
|
||||
container.add_child(button)
|
||||
|
||||
# --- WYBRANIE SEKTORA ---
|
||||
func _on_sector_selected(index: int):
|
||||
Manager.current_sector = index
|
||||
var sector_scene = load(SectorScenePath)
|
||||
get_tree().change_scene_to_packed(sector_scene)
|
||||
|
||||
# --- TŁO ---
|
||||
func _init_background():
|
||||
var background = Sprite2D.new()
|
||||
background.texture = load("res://assets/background/galaxy_background.jpg")
|
||||
background.centered = true
|
||||
background.position = get_viewport_rect().size / 2
|
||||
var screen_size = get_viewport_rect().size
|
||||
var tex_size = background.texture.get_size()
|
||||
var scale_factor = max(screen_size.x / tex_size.x, screen_size.y / tex_size.y)
|
||||
background.scale = Vector2(scale_factor, scale_factor)
|
||||
add_child(background)
|
||||
background.z_index = -10
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user