Refactor game structure and update project settings for 2D gameplay. Removed the game stub scene, introduced a new vault scene, and organized game scripts into distinct files for grid management, rendering, and scene control. Updated input actions for camera movement and changed rendering method to Mobile for better performance.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
class_name VaultCamera
|
||||
extends Camera2D
|
||||
## Камера убежища: перетаскивание, зум колесом и клавиатурная прокрутка.
|
||||
##
|
||||
## Границы задаются встроенными limit_* по размеру убежища, поэтому вручную
|
||||
## позицию не зажимаем — движок делает это сам.
|
||||
|
||||
const ZOOM_STEP := 1.12
|
||||
const MIN_ZOOM := 0.45
|
||||
const MAX_ZOOM := 2.2
|
||||
const KEY_PAN_SPEED := 900.0
|
||||
const EDGE_MARGIN := 420.0
|
||||
|
||||
var _dragging := false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var bounds := VaultGrid.bounds()
|
||||
limit_left = int(bounds.position.x - EDGE_MARGIN)
|
||||
limit_right = int(bounds.end.x + EDGE_MARGIN)
|
||||
limit_top = int(bounds.position.y - EDGE_MARGIN)
|
||||
limit_bottom = int(bounds.end.y + EDGE_MARGIN)
|
||||
position = bounds.get_center()
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var direction := Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
if direction != Vector2.ZERO:
|
||||
position += direction * KEY_PAN_SPEED * delta / zoom.x
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton:
|
||||
_handle_mouse_button(event as InputEventMouseButton)
|
||||
elif event is InputEventMouseMotion and _dragging:
|
||||
position -= (event as InputEventMouseMotion).relative / zoom
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
|
||||
func _handle_mouse_button(event: InputEventMouseButton) -> void:
|
||||
match event.button_index:
|
||||
MOUSE_BUTTON_WHEEL_UP:
|
||||
_zoom_by(ZOOM_STEP)
|
||||
get_viewport().set_input_as_handled()
|
||||
MOUSE_BUTTON_WHEEL_DOWN:
|
||||
_zoom_by(1.0 / ZOOM_STEP)
|
||||
get_viewport().set_input_as_handled()
|
||||
MOUSE_BUTTON_RIGHT, MOUSE_BUTTON_MIDDLE:
|
||||
# Правая и средняя кнопки таскают вид; левая остаётся строительству.
|
||||
_dragging = event.pressed
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
|
||||
func _zoom_by(factor: float) -> void:
|
||||
var target := clampf(zoom.x * factor, MIN_ZOOM, MAX_ZOOM)
|
||||
zoom = Vector2(target, target)
|
||||
Reference in New Issue
Block a user