Stworzenie katalogów i pierwsze pliki

This commit is contained in:
Tomasz Boruc 2025-10-13 17:09:10 +02:00
parent a9ba756fa6
commit bfb70e0056
10 changed files with 150 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B

11
scenes/main.tscn Normal file
View File

@ -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]

15
scenes/planet.tscn Normal file
View File

@ -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

11
scenes/sector.tscn Normal file
View File

@ -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]

View File

@ -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]

18
scripts/GameState.gd Normal file
View File

@ -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

6
scripts/main.gd Normal file
View File

@ -0,0 +1,6 @@
extends Node2D
# main.gd - loads sector and ensures UI exists
func _ready():
# nothing special here for now
pass

24
scripts/planet.gd Normal file
View File

@ -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])

20
scripts/planet_menu.gd Normal file
View File

@ -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")

28
scripts/sector.gd Normal file
View File

@ -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)