diff --git a/scenes/galaxy.tscn b/scenes/galaxy.tscn new file mode 100644 index 0000000..d254faa --- /dev/null +++ b/scenes/galaxy.tscn @@ -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 diff --git a/scripts/GameData.gd b/scripts/GameData.gd index acc5763..1bfd62e 100644 --- a/scripts/GameData.gd +++ b/scripts/GameData.gd @@ -4,7 +4,7 @@ var player_data = [] var sectors: Array = [] func new_game(): - TranslationServer.set_locale("cs") + TranslationServer.set_locale(Settings.language) print("🔹 Tworzenie nowej gry...") sectors.clear() player_data.clear() @@ -18,7 +18,7 @@ func new_game(): func print_game_state(): #fucnkja do testów 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: 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) @@ -43,4 +43,6 @@ func print_game_state(): #fucnkja do testów func _ready(): new_game() + + diff --git a/scripts/SectorData.gd b/scripts/SectorData.gd index e817018..5df144d 100644 --- a/scripts/SectorData.gd +++ b/scripts/SectorData.gd @@ -5,19 +5,37 @@ var id = "" var name = "" var position = Vector2.ZERO var owner = null +var texture = "" var planets: Array = [] # Funkcja statyczna tworząca listę sektorów static func generate_sectors(sector_count: int) -> Array: var sectors_list: Array = [] + var min_distance = 100 # minimalna odległość między sektorami + for i in range(sector_count): var s = SectorData.new() s.id = "sector_" + str(i) 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() sectors_list.append(s) return sectors_list + + +static func random_star_texture() -> Texture2D: + var id = randi_range(1, 8) + return load("res://assets/stars/s%d.png" % id) diff --git a/scripts/galaxy.gd b/scripts/galaxy.gd new file mode 100644 index 0000000..7a64a61 --- /dev/null +++ b/scripts/galaxy.gd @@ -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") diff --git a/scripts/galaxy.gd.uid b/scripts/galaxy.gd.uid new file mode 100644 index 0000000..d44d535 --- /dev/null +++ b/scripts/galaxy.gd.uid @@ -0,0 +1 @@ +uid://cts6e8xmnqsax diff --git a/scripts/settings.gd b/scripts/settings.gd index 01c0d18..bd3bdce 100644 --- a/scripts/settings.gd +++ b/scripts/settings.gd @@ -1,8 +1,8 @@ extends Node - +var language = 'pl' var number_of_players = 3 # Liczba sektorów w galaktyce -var sector_count: int = 3 +var sector_count: int = 10 # Minimalna i maksymalna liczba planet w sektorze var min_planets_per_sector: int = 1