From bfb70e0056bdd46648284001f31aab89a675ead3 Mon Sep 17 00:00:00 2001 From: Tomasz Boruc Date: Mon, 13 Oct 2025 17:09:10 +0200 Subject: [PATCH] =?UTF-8?q?Stworzenie=20katalog=C3=B3w=20i=20pierwsze=20pl?= =?UTF-8?q?iki?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/placeholder_planet.png | Bin 0 -> 433 bytes scenes/main.tscn | 11 +++++++++++ scenes/planet.tscn | 15 +++++++++++++++ scenes/sector.tscn | 11 +++++++++++ scenes/ui/planet_menu.tscn | 17 +++++++++++++++++ scripts/GameState.gd | 18 ++++++++++++++++++ scripts/main.gd | 6 ++++++ scripts/planet.gd | 24 ++++++++++++++++++++++++ scripts/planet_menu.gd | 20 ++++++++++++++++++++ scripts/sector.gd | 28 ++++++++++++++++++++++++++++ 10 files changed, 150 insertions(+) create mode 100644 assets/placeholder_planet.png create mode 100644 scenes/main.tscn create mode 100644 scenes/planet.tscn create mode 100644 scenes/sector.tscn create mode 100644 scenes/ui/planet_menu.tscn create mode 100644 scripts/GameState.gd create mode 100644 scripts/main.gd create mode 100644 scripts/planet.gd create mode 100644 scripts/planet_menu.gd create mode 100644 scripts/sector.gd diff --git a/assets/placeholder_planet.png b/assets/placeholder_planet.png new file mode 100644 index 0000000000000000000000000000000000000000..a25c17dfff9671cf7865964f754bfa818e722001 GIT binary patch literal 433 zcmV;i0Z#sjP)f923#bIholMuK`oAc#s;NC-u%qYu}%*}e|&YrJr<9_z@UT?{E z=}shtdt4>tl8ssxFR>P3wy`Tqx3G}$un2-EZ?)f322sUpXs1Cv0iMb)i$0G^fVc95 zCYM-%*YbokpGbiB@`NNOTR@cZ1UD~BK(z7%CwEss)bd0x|Dk~B<%y#nCRc)yX$lzS z=o76zRRN=wCu+TN37`X@`4cee_!DKnoPhn4(T_f{@0k;T4uB>F(1TglKS6zS0?+}_ zqyTgPG${Zb08I)&2SAeo&;ii=1l;wX94}DcoB(tHG$~;JWR~;5zGqHA`NHT^Q1;6S zKnFlm6)@^DsP$@2z-SU$eR2sLy*bJh9QEigxb+60~_tN+5q)KYJidt^`rjV6or4Z_sjMCDYzH+QQ?# b!_)Hx35b+(7e_@c00000NkvXXu0mjfnJBw; literal 0 HcmV?d00001 diff --git a/scenes/main.tscn b/scenes/main.tscn new file mode 100644 index 0000000..b21e23e --- /dev/null +++ b/scenes/main.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=3 format=3 uid="1c3c8b6f-3c9d-4a6f-9a3f-1b2e6a9b0cde"] +[node name="Main" type="Node2D"] +script = ExtResource( 1 ) + +[node name="Sector" parent="." instance=ExtResource( 2 )] +[node name="UI" type="CanvasLayer" parent="."] +[node name="PlanetMenu" parent="UI" instance=ExtResource( 3 )] + +[ext_resource path="res://scripts/main.gd" type="Script" id=1] +[ext_resource path="res://scenes/sector.tscn" type="PackedScene" id=2] +[ext_resource path="res://scenes/ui/planet_menu.tscn" type="PackedScene" id=3] diff --git a/scenes/planet.tscn b/scenes/planet.tscn new file mode 100644 index 0000000..3b06511 --- /dev/null +++ b/scenes/planet.tscn @@ -0,0 +1,15 @@ +[gd_scene load_steps=2 format=3 uid="a1b2c3d4-e5f6-7890-abcd-ef0123456789"] +[node name="Planet" type="Area2D"] +script = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture = ExtResource( 2 ) + +[ext_resource path="res://scripts/planet.gd" type="Script" id=1] +[ext_resource path="res://assets/placeholder_planet.png" type="Texture2D" id=2] + +[sub_resource type="CircleShape2D" id=1] +radius = 28.0 diff --git a/scenes/sector.tscn b/scenes/sector.tscn new file mode 100644 index 0000000..bd4623e --- /dev/null +++ b/scenes/sector.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=3 format=3 uid="b6c8d9a1-5f2a-4db8-b3a1-9d2c1f6a7b12"] +[node name="Sector" type="Node2D"] +script = ExtResource( 1 ) + +[node name="Star" type="Node2D" parent="."] +transform/pos = Vector2(480, 240) + +[node name="Planets" type="Node2D" parent="."] + +[ext_resource path="res://scripts/sector.gd" type="Script" id=1] +[ext_resource path="res://scenes/planet.tscn" type="PackedScene" id=2] diff --git a/scenes/ui/planet_menu.tscn b/scenes/ui/planet_menu.tscn new file mode 100644 index 0000000..6cfd30c --- /dev/null +++ b/scenes/ui/planet_menu.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=2 format=3 uid="ui-planet-menu-0001"] +[node name="PlanetMenu" type="Panel"] +anchor_right = 1.0 +anchor_bottom = 0.25 +margin_left = 16.0 +margin_top = 16.0 +margin_right = -16.0 +margin_bottom = -16.0 +script = ExtResource( 1 ) + +[node name="VBox" type="VBoxContainer" parent="."] +[node name="Label" type="Label" parent="VBox"] +text = "Planet: -" +[node name="BuildButton" type="Button" parent="VBox"] +text = "Build Mine" + +[ext_resource path="res://scripts/planet_menu.gd" type="Script" id=1] diff --git a/scripts/GameState.gd b/scripts/GameState.gd new file mode 100644 index 0000000..e73b0b5 --- /dev/null +++ b/scripts/GameState.gd @@ -0,0 +1,18 @@ +extends Node +# GameState.gd - simple resource manager singleton (add as Autoload 'GameState' in Project Settings) + +var resources := { + "metal": 100, + "energy": 50 +} + +func add_resource(kind: String, amount: int): + if not resources.has(kind): + resources[kind] = 0 + resources[kind] += amount + +func spend_resource(kind: String, amount: int) -> bool: + if resources.get(kind, 0) >= amount: + resources[kind] -= amount + return true + return false diff --git a/scripts/main.gd b/scripts/main.gd new file mode 100644 index 0000000..87adad1 --- /dev/null +++ b/scripts/main.gd @@ -0,0 +1,6 @@ +extends Node2D +# main.gd - loads sector and ensures UI exists + +func _ready(): + # nothing special here for now + pass diff --git a/scripts/planet.gd b/scripts/planet.gd new file mode 100644 index 0000000..bbc653d --- /dev/null +++ b/scripts/planet.gd @@ -0,0 +1,24 @@ +extends Area2D +# planet.gd - simple clickable planet + +signal planet_selected(planet) + +var buildings: Array = [] + +func _ready(): + # add a simple visual if Sprite2D not set + if not $Sprite2D.texture: + # create a colored CircleTexture placeholder + var img = Image.new() + img.create(64,64,false,Image.FORMAT_RGBA8) + img.fill(Color(0.2,0.5,1.0,1.0)) + var tex = ImageTexture.create_from_image(img) + $Sprite2D.texture = tex + +func _input_event(viewport, event, shape_idx): + if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT: + emit_signal("planet_selected", self) + +func build(building_type: String): + buildings.append(building_type) + print("Built %s on %s" % [building_type, name]) diff --git a/scripts/planet_menu.gd b/scripts/planet_menu.gd new file mode 100644 index 0000000..c50b6c4 --- /dev/null +++ b/scripts/planet_menu.gd @@ -0,0 +1,20 @@ +extends Panel +# planet_menu.gd - UI for interacting with a planet + +onready var label = $VBox/Label +onready var build_btn = $VBox/BuildButton +var current_planet = null + +func _ready(): + visible = false + build_btn.pressed = false + build_btn.connect("pressed", Callable(self, "_on_build_pressed")) + +func open_for(planet): + current_planet = planet + label.text = "Planet: %s" % planet.name + visible = true + +func _on_build_pressed(): + if current_planet: + current_planet.build("Mine") diff --git a/scripts/sector.gd b/scripts/sector.gd new file mode 100644 index 0000000..e396092 --- /dev/null +++ b/scripts/sector.gd @@ -0,0 +1,28 @@ +extends Node2D +# sector.gd - spawns a star and several planets and connects signals + +@export var planet_scene: PackedScene = preload("res://scenes/planet.tscn") + +func _ready(): + # create a simple star visual (Circle) - using a Node2D as placeholder + var star = Node2D.new() + star.name = "StarSprite" + star.position = Vector2(480, 240) + add_child(star) + # Spawn planets + for i in range(3): + var p = planet_scene.instantiate() + p.name = "Planet_%d" % i + var angle = i * (PI * 2 / 3) + var radius = 160 + p.position = Vector2(480,240) + Vector2(cos(angle), sin(angle)) * radius + add_child(p) + p.connect("planet_selected", Callable(self, "_on_planet_selected")) + +func _on_planet_selected(planet): + # find the PlanetMenu in the scene tree and open it + var ui = get_tree().get_root().get_node("Main/UI/PlanetMenu") if get_tree().get_root().has_node("Main/UI/PlanetMenu") else null + if ui: + ui.open_for(planet) + else: + print("PlanetMenu not found, but selected: ", planet.name)