Parallax background
Zmiany w skalowaniu gwiazd przy zoom
This commit is contained in:
parent
7569b9d172
commit
14d03465a9
Binary file not shown.
|
Before Width: | Height: | Size: 448 KiB After Width: | Height: | Size: 1.8 MiB |
BIN
assets/background/galaxy_background1.jpg
Normal file
BIN
assets/background/galaxy_background1.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 448 KiB |
40
assets/background/galaxy_background1.jpg.import
Normal file
40
assets/background/galaxy_background1.jpg.import
Normal file
@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://drajnancvfqk3"
|
||||
path="res://.godot/imported/galaxy_background1.jpg-a577e06b36b9b802cd5d7b05631d9d53.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/background/galaxy_background1.jpg"
|
||||
dest_files=["res://.godot/imported/galaxy_background1.jpg-a577e06b36b9b802cd5d7b05631d9d53.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
|
||||
@ -12,19 +12,13 @@ script = ExtResource("1_jxn3g")
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
layer = -1
|
||||
|
||||
[node name="Background" type="Sprite2D" parent="CanvasLayer"]
|
||||
z_index = -10
|
||||
position = Vector2(580.00006, 340.00003)
|
||||
scale = Vector2(0.30208334, 0.3148148)
|
||||
texture = ExtResource("1_n7ltq")
|
||||
|
||||
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer" parent="."]
|
||||
stream = ExtResource("3_mlxib")
|
||||
autoplay = true
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
position = Vector2(904, 512)
|
||||
zoom = Vector2(0.64, 0.64)
|
||||
zoom = Vector2(0.81, 0.81)
|
||||
script = ExtResource("4_5xxpo")
|
||||
|
||||
[node name="CanvasLayer2" type="CanvasLayer" parent="."]
|
||||
@ -37,3 +31,16 @@ z_as_relative = false
|
||||
offset_left = 896.0
|
||||
offset_top = 8.0
|
||||
offset_bottom = -616.0
|
||||
|
||||
[node name="ParallaxBackground" type="ParallaxBackground" parent="."]
|
||||
scroll_ignore_camera_zoom = true
|
||||
|
||||
[node name="ParallaxLayer" type="ParallaxLayer" parent="ParallaxBackground"]
|
||||
motion_scale = Vector2(0.1, 0.1)
|
||||
motion_mirroring = Vector2(1686.955, 1000)
|
||||
|
||||
[node name="Background" type="Sprite2D" parent="ParallaxBackground/ParallaxLayer"]
|
||||
z_index = -10
|
||||
position = Vector2(844, 500)
|
||||
scale = Vector2(0.43958333, 0.46296293)
|
||||
texture = ExtResource("1_n7ltq")
|
||||
|
||||
@ -1,18 +1,44 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://cynwjsqox5eqx"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://cynwjsqox5eqx"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bdmoi05k2qhjs" path="res://scripts/planet.gd" id="1_cktii"]
|
||||
[ext_resource type="Texture2D" uid="uid://bmu7jwnvu7ob2" path="res://assets/planets/p5.png" id="2_h8ms6"]
|
||||
[ext_resource type="FontFile" uid="uid://chk8jrn2ighpx" path="res://assets/fonts/main_font.ttf" id="3_ggt7d"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_h8ms6"]
|
||||
radius = 8.0
|
||||
|
||||
[node name="Planet" type="Node2D"]
|
||||
script = ExtResource("1_cktii")
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
position = Vector2(16, -40)
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
position = Vector2(-16, 40)
|
||||
shape = SubResource("CircleShape2D_h8ms6")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
scale = Vector2(0.053333335, 0.053333335)
|
||||
texture = ExtResource("2_h8ms6")
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
offset_left = -16.0
|
||||
offset_top = 8.0
|
||||
offset_right = 8.0
|
||||
offset_bottom = 21.0
|
||||
offset_left = 8.0
|
||||
offset_top = -8.0
|
||||
offset_right = 32.0
|
||||
offset_bottom = 8.0
|
||||
theme_override_fonts/font = ExtResource("3_ggt7d")
|
||||
theme_override_font_sizes/font_size = 8
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="Info" type="Label" parent="CanvasLayer"]
|
||||
visible = false
|
||||
offset_left = 16.0
|
||||
offset_top = 32.0
|
||||
offset_right = 128.0
|
||||
offset_bottom = 120.0
|
||||
theme_override_font_sizes/font_size = 8
|
||||
text = "test"
|
||||
autowrap_mode = 2
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://cvc0brcqh2rhu"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://cvc0brcqh2rhu"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c7l387xor12hx" path="res://scripts/star.gd" id="1_mcqwg"]
|
||||
[ext_resource type="Texture2D" uid="uid://b4iycl7xcvpkp" path="res://assets/stars/s1.png" id="2_j6vao"]
|
||||
[ext_resource type="Script" uid="uid://bgghdcbxp6o0k" path="res://scripts/star_sprite.gd" id="3_ef0hr"]
|
||||
[ext_resource type="FontFile" uid="uid://chk8jrn2ighpx" path="res://assets/fonts/main_font.ttf" id="4_8d8bx"]
|
||||
|
||||
[node name="Star" type="Node2D"]
|
||||
script = ExtResource("1_mcqwg")
|
||||
@ -10,10 +12,14 @@ script = ExtResource("1_mcqwg")
|
||||
position = Vector2(-2.3841858e-07, 0)
|
||||
scale = Vector2(0.014858843, 0.014858842)
|
||||
texture = ExtResource("2_j6vao")
|
||||
script = ExtResource("3_ef0hr")
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
offset_left = -16.0
|
||||
offset_top = 16.0
|
||||
offset_right = 16.0
|
||||
offset_bottom = 30.0
|
||||
offset_left = -40.0
|
||||
offset_top = 8.0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 22.0
|
||||
theme_override_fonts/font = ExtResource("4_8d8bx")
|
||||
theme_override_font_sizes/font_size = 10
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
@ -27,3 +27,4 @@ func _process(delta):
|
||||
# ograniczenie minimalnego i maksymalnego zoomu
|
||||
zoom.x = clamp(zoom.x, 0.1, 3)
|
||||
zoom.y = clamp(zoom.y, 0.1, 3)
|
||||
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
extends Node
|
||||
|
||||
const RESOURCE_TYPES = ["res_iron", "res_uran", "res_titan", "res_alu"]
|
||||
|
||||
|
||||
const sector_names = [
|
||||
"Aetherion", "Altaris", "Andur System", "Artemis Reach", "Astrion",
|
||||
"Azura Prime", "Borealis Expanse", "Caldris Belt", "Canthar System", "Celion Verge",
|
||||
|
||||
@ -3,14 +3,19 @@ extends Node2D
|
||||
@onready var StarScene = preload("res://scenes/Star.tscn")
|
||||
@onready var PlanetScene = preload("res://scenes/Planet.tscn")
|
||||
@onready var MenuScene = preload("res://scenes/Menu.tscn")
|
||||
|
||||
|
||||
@onready var camera = $Camera2D
|
||||
const PLANET_HIDE_ZOOM = 0.6 # powyżej tego zoomu planety się chowają
|
||||
func _ready():
|
||||
if GameData.game_lunched == false:
|
||||
_generate_galaxy(Settings.NUMBER_OF_SYSTEMS)
|
||||
GameData.game_lunched = true
|
||||
|
||||
|
||||
|
||||
func _process(delta):
|
||||
var zoom_level = (camera.zoom.x + camera.zoom.y) / 2.0
|
||||
|
||||
for planet in get_tree().get_nodes_in_group("planets"):
|
||||
planet.visible = zoom_level > PLANET_HIDE_ZOOM
|
||||
|
||||
func _generate_galaxy(count: int):
|
||||
for i in range(count):
|
||||
@ -46,7 +51,7 @@ func _generate_galaxy(count: int):
|
||||
|
||||
|
||||
# Lista wszystkich możliwych surowców
|
||||
var RESOURCE_TYPES = Settings.RESOURCE_TYPES
|
||||
var RESOURCE_TYPES = Names.RESOURCE_TYPES
|
||||
|
||||
func generate_planet_resources(planet):
|
||||
planet.resources = {} # resetujemy słownik
|
||||
|
||||
@ -1,6 +1,11 @@
|
||||
extends Node2D
|
||||
class_name Planet
|
||||
@onready var label = $Label
|
||||
|
||||
@onready var info_label = $CanvasLayer/Info
|
||||
@onready var area = $Area2D
|
||||
|
||||
|
||||
var pname: String = ""
|
||||
var orbit_radius: float = 30.0
|
||||
var orbit_speed: float = 0.01
|
||||
@ -11,6 +16,11 @@ var texture: Texture2D
|
||||
var angle = randf() * TAU
|
||||
func _ready():
|
||||
|
||||
add_to_group("planets")
|
||||
|
||||
# Podłącz sygnały
|
||||
area.mouse_entered.connect(_on_mouse_entered)
|
||||
area.mouse_exited.connect(_on_mouse_exited)
|
||||
#str(round(biosfere * 100) / 100.0)
|
||||
_update_position()
|
||||
|
||||
@ -25,3 +35,28 @@ func _process(delta):
|
||||
func _update_position():
|
||||
# pozycja lokalna względem gwiazdy
|
||||
position = Vector2(cos(angle), sin(angle)) * orbit_radius
|
||||
|
||||
func _on_mouse_entered():
|
||||
info_label.visible = true
|
||||
|
||||
var text = "🌍 %s\n" % pname
|
||||
text += "Biosfera: %.2f\n" % biosfere
|
||||
|
||||
var has_any_resource = false
|
||||
for key in resources.keys():
|
||||
var res = resources[key]
|
||||
if res.has("exist") and res["exist"]:
|
||||
if not has_any_resource:
|
||||
text += "Zasoby:\n"
|
||||
has_any_resource = true
|
||||
|
||||
var display_name = tr(key) # tłumaczenie klucza przez system Godot
|
||||
text += "%s:%s\n" % [display_name, str(res.get("amount", 0))]
|
||||
|
||||
info_label.text = text
|
||||
|
||||
|
||||
|
||||
|
||||
func _on_mouse_exited():
|
||||
info_label.visible = false
|
||||
|
||||
@ -5,7 +5,7 @@ var number_of_players = 1
|
||||
# Liczba sektorów w galaktyce
|
||||
var NUMBER_OF_SYSTEMS: int = 144
|
||||
|
||||
const RESOURCE_TYPES = ["Iron", "Uran", "Titan", "Water"]
|
||||
|
||||
|
||||
#pozycja systemów
|
||||
var x = 8000
|
||||
|
||||
@ -9,3 +9,4 @@ var texture: Texture2D
|
||||
func _ready():
|
||||
#print("Gwiazda %s z %d planetami" % [star_name, planet_count])
|
||||
label.text = star_name
|
||||
|
||||
|
||||
39
scripts/star_sprite.gd
Normal file
39
scripts/star_sprite.gd
Normal file
@ -0,0 +1,39 @@
|
||||
extends Sprite2D
|
||||
|
||||
# Określa minimalny ZOOM kamery (największe PRZYBLIŻENIE),
|
||||
# przy którym gwiazda osiągnie MAKSYMALNY rozmiar ekranowy.
|
||||
@export var MAX_ZOOM_IN_LIMIT: float = 0.5
|
||||
|
||||
# NOWA ZMIENNA: Określa maksymalny ZOOM kamery (największe ODDALENIE),
|
||||
# przy którym gwiazda osiągnie MINIMALNY rozmiar ekranowy.
|
||||
# Np. jeśli ustawisz na 5.0, przy zoomie 5.0x gwiazda osiągnie swój
|
||||
# najmniejszy dopuszczalny rozmiar na ekranie i przestanie się zmniejszać.
|
||||
@export var MIN_ZOOM_OUT_LIMIT: float = 1.0
|
||||
|
||||
var initial_scale: Vector2
|
||||
|
||||
func _ready():
|
||||
initial_scale = scale
|
||||
|
||||
func _process(delta):
|
||||
var camera: Camera2D = get_viewport().get_camera_2d()
|
||||
|
||||
if is_instance_valid(camera):
|
||||
var cam_zoom: Vector2 = camera.zoom
|
||||
|
||||
# 1. Obliczamy efektywny zoom kamery, który będziemy używać w obliczeniach.
|
||||
# Używamy MIN i MAX, aby ograniczyć wartość zoomu:
|
||||
# - Nie mniejszy niż MAX_ZOOM_IN_LIMIT (ograniczenie "rosnące" gwiazdy).
|
||||
# - Nie większy niż MIN_ZOOM_OUT_LIMIT (ograniczenie "malejące" gwiazdy).
|
||||
|
||||
var effective_zoom_x = clampf(cam_zoom.x, MAX_ZOOM_IN_LIMIT, MIN_ZOOM_OUT_LIMIT)
|
||||
var effective_zoom_y = clampf(cam_zoom.y, MAX_ZOOM_IN_LIMIT, MIN_ZOOM_OUT_LIMIT)
|
||||
|
||||
# 2. Obliczamy ostateczną skalę na podstawie OGRANICZONEGO zoomu.
|
||||
# Im większa jest wartość effective_zoom, tym MNIEJSZA będzie skala.
|
||||
# Wartość ta jest teraz zawsze w zakresie [1.0 / MAX_ZOOM_IN_LIMIT, 1.0 / MIN_ZOOM_OUT_LIMIT]
|
||||
|
||||
var final_scale_x = initial_scale.x / effective_zoom_x
|
||||
var final_scale_y = initial_scale.y / effective_zoom_y
|
||||
|
||||
scale = Vector2(final_scale_x, final_scale_y)
|
||||
1
scripts/star_sprite.gd.uid
Normal file
1
scripts/star_sprite.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://bgghdcbxp6o0k
|
||||
Loading…
x
Reference in New Issue
Block a user