Rozbudowa szkieletu i scena galaxy

This commit is contained in:
Tirith 2025-10-29 15:23:18 +01:00
parent fb4f777639
commit af3becec0b
6 changed files with 74 additions and 6 deletions

17
scenes/galaxy.tscn Normal file
View File

@ -0,0 +1,17 @@
[gd_scene load_steps=4 format=3 uid="uid://b1vxl6rs5odt1"]
[ext_resource type="Script" uid="uid://cts6e8xmnqsax" path="res://scripts/galaxy.gd" id="1_jxn3g"]
[ext_resource type="Texture2D" uid="uid://dvydsg5o77wdm" path="res://assets/background/galaxy_background.jpg" id="1_n7ltq"]
[ext_resource type="AudioStream" uid="uid://c8xg32p8lbltw" path="res://assets/sounds/music/game_music.mp3" id="3_mlxib"]
[node name="Galaxy" type="Node2D"]
script = ExtResource("1_jxn3g")
[node name="Background" type="Sprite2D" parent="."]
position = Vector2(576.00006, 323.99994)
scale = Vector2(0.3, 0.30000004)
texture = ExtResource("1_n7ltq")
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource("3_mlxib")
autoplay = true

View File

@ -4,7 +4,7 @@ var player_data = []
var sectors: Array = [] var sectors: Array = []
func new_game(): func new_game():
TranslationServer.set_locale("cs") TranslationServer.set_locale(Settings.language)
print("🔹 Tworzenie nowej gry...") print("🔹 Tworzenie nowej gry...")
sectors.clear() sectors.clear()
player_data.clear() player_data.clear()
@ -18,7 +18,7 @@ func new_game():
func print_game_state(): #fucnkja do testów func print_game_state(): #fucnkja do testów
for s in sectors: for s in sectors:
print("Sektor:", s.name, "ID:", s.id, "Pozycja:", s.position, "Planety:", s.planets.size()) print("Sektor:", s.name, "ID:", s.id, "Pozycja:", s.position, "Planety:", s.planets.size(),s.texture)
for p in s.planets: for p in s.planets:
print(" Planeta:", p.name, "Rozmiar:", p.size, "Orbit:", p.orbit_radius, "Rotation:", round(p.rotation_speed*100)/100, print(" Planeta:", p.name, "Rozmiar:", p.size, "Orbit:", p.orbit_radius, "Rotation:", round(p.rotation_speed*100)/100,
"Biosfere:", round(p.biosfere*100)/100, "Resource Rich:", round(p.resource_rich*100)/100) "Biosfere:", round(p.biosfere*100)/100, "Resource Rich:", round(p.resource_rich*100)/100)
@ -43,4 +43,6 @@ func print_game_state(): #fucnkja do testów
func _ready(): func _ready():
new_game() new_game()

View File

@ -5,19 +5,37 @@ var id = ""
var name = "" var name = ""
var position = Vector2.ZERO var position = Vector2.ZERO
var owner = null var owner = null
var texture = ""
var planets: Array = [] var planets: Array = []
# Funkcja statyczna tworząca listę sektorów # Funkcja statyczna tworząca listę sektorów
static func generate_sectors(sector_count: int) -> Array: static func generate_sectors(sector_count: int) -> Array:
var sectors_list: Array = [] var sectors_list: Array = []
var min_distance = 100 # minimalna odległość między sektorami
for i in range(sector_count): for i in range(sector_count):
var s = SectorData.new() var s = SectorData.new()
s.id = "sector_" + str(i) s.id = "sector_" + str(i)
s.name = ObjectNames.sector_names[randi() % ObjectNames.sector_names.size()] s.name = ObjectNames.sector_names[randi() % ObjectNames.sector_names.size()]
s.position = Vector2(randi() % 1000, randi() % 600)
# Generujemy planety dla tego sektora var pos_ok = false
var new_pos = Vector2.ZERO # <- deklaracja zmiennej przed while
while not pos_ok:
new_pos = Vector2(randi() % 1000, randi() % 600)
pos_ok = true
for existing in sectors_list:
if existing.position.distance_to(new_pos) < min_distance:
pos_ok = false
break
s.position = new_pos
s.texture = random_star_texture()
s.planets = PlanetData.generate_planets() s.planets = PlanetData.generate_planets()
sectors_list.append(s) sectors_list.append(s)
return sectors_list return sectors_list
static func random_star_texture() -> Texture2D:
var id = randi_range(1, 8)
return load("res://assets/stars/s%d.png" % id)

30
scripts/galaxy.gd Normal file
View File

@ -0,0 +1,30 @@
extends Node2D
func _ready():
var sectors = GameData.sectors # zakładam że GameData jest autoloadem
_spawn_sectors(sectors)
func _spawn_sectors(sectors: Array):
for sector in sectors:
var star = Sprite2D.new()
star.texture = sector.texture
star.position = sector.position
star.scale = Vector2(0.02, 0.02) # ewentualnie zmień skalę
add_child(star) # dodajemy bezpośrednio do Galaxy
# dodaj nazwę pod gwiazdą
var name_label = Label.new()
name_label.text = sector.name
name_label.position = star.position + Vector2(-20, 20)
add_child(name_label)
# dodaj nazwę pod gwiazdą
var name_label2 = Label.new()
name_label2.text = sector.id
name_label2.position = star.position + Vector2(-20, 40)
add_child(name_label2)
func _input(event):
if event.is_action_pressed("ui_cancel"): # "ui_cancel" to ESC
get_tree().change_scene_to_file("res://scenes/Menu.tscn")

1
scripts/galaxy.gd.uid Normal file
View File

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

View File

@ -1,8 +1,8 @@
extends Node extends Node
var language = 'pl'
var number_of_players = 3 var number_of_players = 3
# Liczba sektorów w galaktyce # Liczba sektorów w galaktyce
var sector_count: int = 3 var sector_count: int = 10
# Minimalna i maksymalna liczba planet w sektorze # Minimalna i maksymalna liczba planet w sektorze
var min_planets_per_sector: int = 1 var min_planets_per_sector: int = 1