Przesuwanie mapy
This commit is contained in:
parent
c2bd684782
commit
41dd25f798
16
Manager.gd
16
Manager.gd
@ -193,17 +193,23 @@ func _random_star_texture() -> String:
|
||||
|
||||
|
||||
func find_safe_position() -> Vector2:
|
||||
var screen_size = get_viewport().get_visible_rect().size
|
||||
# Używamy stałych rozmiarów mapy, a nie rozmiaru ekranu
|
||||
var max_width = Settings.MAP_WIDTH
|
||||
var max_height = Settings.MAP_HEIGHT
|
||||
|
||||
# Przesunięcie krawędzi (te 50 jednostek od brzegów)
|
||||
var margin = 50
|
||||
|
||||
for attempt in range(Settings.MAX_ATTEMPTS):
|
||||
# 1. Losowanie potencjalnej pozycji w obszarze (zgodnie z Twoimi marginesami)
|
||||
# 1. Losowanie pozycji w nowym, większym obszarze
|
||||
var potential_pos = Vector2(
|
||||
randf_range(50, screen_size.x - 50),
|
||||
randf_range(50, screen_size.y - 50)
|
||||
randf_range(margin, max_width - margin),
|
||||
randf_range(margin, max_height - margin)
|
||||
)
|
||||
|
||||
# 2. Sprawdzenie, czy pozycja jest bezpieczna
|
||||
if is_position_safe(potential_pos):
|
||||
return potential_pos # Znaleziono bezpieczną pozycję!
|
||||
return potential_pos
|
||||
|
||||
# 3. Jeśli po MAX_ATTEMPTS nie znaleziono miejsca
|
||||
print("Osiągnięto limit prób, nie można znaleźć bezpiecznego miejsca.")
|
||||
|
||||
@ -28,6 +28,29 @@ window/size/mode=2
|
||||
window/stretch/mode="canvas_items"
|
||||
window/stretch/aspect="ignore"
|
||||
|
||||
[input]
|
||||
|
||||
map_move_up={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
map_move_left={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
map_move_right={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
map_move_down={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[internationalization]
|
||||
|
||||
locale/translations=PackedStringArray("res://localization/translation.de.translation", "res://localization/translation.en.translation", "res://localization/translation.pl.translation")
|
||||
|
||||
@ -1,24 +1,24 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://krtvmtme8s5f"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://krtvmtme8s5f"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://2x1k6uk86wqj" path="res://scripts/galaxy.gd" id="1_n7ltq"]
|
||||
[ext_resource type="PackedScene" uid="uid://bbgymc0drqpbx" path="res://scenes/time_display.tscn" id="2_jxn3g"]
|
||||
[ext_resource type="Texture2D" uid="uid://dvydsg5o77wdm" path="res://assets/background/galaxy_background.jpg" id="3_mlxib"]
|
||||
|
||||
[node name="galaxy" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
[node name="galaxy" type="Node2D"]
|
||||
script = ExtResource("1_n7ltq")
|
||||
|
||||
[node name="VBoxContainer" type="Control" parent="."]
|
||||
anchors_preset = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
layer = -1
|
||||
|
||||
[node name="TimeDisplay" parent="." instance=ExtResource("2_jxn3g")]
|
||||
layout_mode = 1
|
||||
[node name="Sprite2D" type="Sprite2D" parent="CanvasLayer"]
|
||||
show_behind_parent = true
|
||||
z_index = -10
|
||||
z_as_relative = false
|
||||
position = Vector2(576, 324)
|
||||
scale = Vector2(0.29999998, 0.3)
|
||||
texture = ExtResource("3_mlxib")
|
||||
|
||||
[node name="TimeDisplay" parent="CanvasLayer" instance=ExtResource("2_jxn3g")]
|
||||
anchors_preset = 1
|
||||
anchor_left = 1.0
|
||||
anchor_bottom = 0.0
|
||||
@ -26,3 +26,12 @@ offset_left = -128.0
|
||||
offset_bottom = 23.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 1
|
||||
|
||||
[node name="VBoxContainer" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
position = Vector2(576, 325)
|
||||
|
||||
@ -1,12 +1,56 @@
|
||||
extends Control
|
||||
extends Node2D
|
||||
|
||||
@export var SectorScenePath: String = "res://scenes/sector.tscn"
|
||||
@onready var container = $VBoxContainer
|
||||
@onready var camera: Camera2D = $Camera2D # Pamiętaj o poprawnej nazwie węzła kamery
|
||||
|
||||
# KONFIGURACJA KAMERY (ZOOM)
|
||||
const ZOOM_SPEED = 0.1
|
||||
const MIN_ZOOM = 0.25
|
||||
const MAX_ZOOM = 4.0
|
||||
|
||||
# ZMIENNE DO PRZECIĄGANIA (PAN) - MUSZĄ BYĆ ZADEKLAROWANE TUTAJ
|
||||
var is_dragging: bool = false
|
||||
var drag_start_position: Vector2 = Vector2.ZERO
|
||||
|
||||
func _ready():
|
||||
_init_background()
|
||||
#_init_background()
|
||||
_create_sector_buttons()
|
||||
# Upewnienie się, że kamera jest aktywna
|
||||
camera.make_current()
|
||||
|
||||
# Ograniczenie ruchu kamery do granic świata
|
||||
$Camera2D.limit_left = 0
|
||||
$Camera2D.limit_top = 0
|
||||
$Camera2D.limit_right = Settings.MAP_WIDTH
|
||||
$Camera2D.limit_bottom = Settings.MAP_HEIGHT
|
||||
func _process(delta):
|
||||
# Tworzenie wektora ruchu na podstawie akcji (Input Map)
|
||||
var movement_vector = Vector2.ZERO
|
||||
|
||||
# Ruch pionowy
|
||||
if Input.is_action_pressed("map_move_down"):
|
||||
movement_vector.y += 1.0
|
||||
if Input.is_action_pressed("map_move_up"):
|
||||
movement_vector.y -= 1.0
|
||||
|
||||
# Ruch poziomy
|
||||
if Input.is_action_pressed("map_move_right"):
|
||||
movement_vector.x += 1.0
|
||||
if Input.is_action_pressed("map_move_left"):
|
||||
movement_vector.x -= 1.0
|
||||
|
||||
# Normalizacja wektora, aby ruch po przekątnej nie był szybszy
|
||||
if movement_vector.length() > 0:
|
||||
movement_vector = movement_vector.normalized()
|
||||
|
||||
# Aktualizacja pozycji kamery
|
||||
# Ruch jest skalowany przez czas (delta), prędkość i aktualny poziom zoomu
|
||||
camera.position += movement_vector * Settings.MOVE_SPEED * camera.zoom * delta
|
||||
|
||||
# OPCJONALNIE: Ograniczenie ruchu do granic mapy (jeśli je ustaliłeś)
|
||||
# camera.position.x = clampf(camera.position.x, camera.limit_left, camera.limit_right)
|
||||
# camera.position.y = clampf(camera.position.y, camera.limit_top, camera.limit_bottom)
|
||||
# --- TWORZENIE GWIAZD SEKTORÓW ---
|
||||
const GLOBAL_STAR_REDUCTION = 0.45 # Zmniejsza gwiazdy do 65% oryginalnego rozmiaru
|
||||
const FONT_PATH := "res://assets/fonts/Chopsic.otf"
|
||||
@ -78,3 +122,56 @@ func _init_background():
|
||||
|
||||
add_child(background)
|
||||
background.z_index = -10
|
||||
|
||||
func _unhandled_input(event):
|
||||
# --- PRZESUWANIE (PAN) ---
|
||||
|
||||
if event is InputEventMouseButton:
|
||||
# Rozpoczęcie przeciągania (domyślnie Prawy Przycisk Mysz)
|
||||
if event.button_index == MOUSE_BUTTON_RIGHT and event.pressed:
|
||||
is_dragging = true
|
||||
# Zapis pozycji myszy w koordynatach ekranu
|
||||
drag_start_position = event.position
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
# Zakończenie przeciągania
|
||||
elif event.button_index == MOUSE_BUTTON_RIGHT and not event.pressed:
|
||||
is_dragging = false
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
# --- SKALOWANIE (ZOOM) ---
|
||||
|
||||
elif event.button_index == MOUSE_BUTTON_WHEEL_UP:
|
||||
# Kółko w górę (przybliżanie)
|
||||
_apply_zoom(1.0 / (1.0 + ZOOM_SPEED))
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
|
||||
# Kółko w dół (oddalanie)
|
||||
_apply_zoom(1.0 + ZOOM_SPEED)
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
if event is InputEventMouseMotion and is_dragging:
|
||||
# Przesunięcie myszy od ostatniej klatki
|
||||
var delta_drag = event.position - drag_start_position
|
||||
|
||||
# Zmiana pozycji kamery
|
||||
# Dzielimy przez zoom, aby ruch był stały niezależnie od skali
|
||||
camera.position -= delta_drag * camera.zoom
|
||||
|
||||
# Aktualizujemy punkt startowy, aby śledzić ciągły ruch
|
||||
drag_start_position = event.position
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
|
||||
func _apply_zoom(factor: float):
|
||||
var new_zoom = camera.zoom * factor
|
||||
|
||||
# Ograniczenie zoomu do zdefiniowanych minimalnych i maksymalnych wartości
|
||||
new_zoom.x = clampf(new_zoom.x, MIN_ZOOM, MAX_ZOOM)
|
||||
new_zoom.y = clampf(new_zoom.y, MIN_ZOOM, MAX_ZOOM)
|
||||
|
||||
camera.zoom = new_zoom
|
||||
|
||||
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ extends Node
|
||||
const UPDATE_INTERVAL := 10.0 #Cykl w sekundach
|
||||
var ORBIT_STEP = randf_range(30, 50) #odległośc miedzy orbitami
|
||||
const FIRST_ORBIT_STEP = 120 #pierwsza planeta od gwiazdy
|
||||
const SECTOR_COUNT = 13 #ilość sektorów
|
||||
const SECTOR_COUNT = 150 #ilość sektorów
|
||||
const PLANET_PER_SECTOR: Vector2 = Vector2(5, 5)
|
||||
const MIN_DISTANCE = 80.0 # Minimalna odległość (promień) między środkami gwiazd
|
||||
const MAX_ATTEMPTS = 50 # Maksymalna liczba prób znalezienia miejsca
|
||||
@ -16,3 +16,8 @@ const CURSOR: = "res://assets/icons/cursors/cursor.png"
|
||||
|
||||
|
||||
const LANGUAGE: = "pl"
|
||||
|
||||
const MAP_WIDTH: int = 4000 # Przykładowa szerokość mapy w świecie gry
|
||||
const MAP_HEIGHT: int = 4000 # Przykładowa wysokość mapy w świecie gry
|
||||
|
||||
const MOVE_SPEED = 1000.0 # Szybkość mapy w jednostkach na sekundę (px/s)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user