extends Node2D # Переменная для хранения ссылки на TileMap @onready var buildings: TileMapLayer = $TileMap/buildings/buildings0 @onready var roads: TileMapLayer = $TileMap/roads @onready var ground: TileMapLayer = $TileMap/ground var is_drawing_road: bool = false # Флаг для отслеживания зажатия кнопки мыши var is_drawing_mountian: bool = false # Флаг для отслеживания зажатия кнопки мыши func _ready(): pass func _input(event): if event is InputEventMouseButton: # Проверяем нажатие или отпускание левой кнопки мыши if event.button_index == MOUSE_BUTTON_LEFT: is_drawing_road = event.pressed # Устанавливаем флаг, если кнопка нажата elif event.button_index == MOUSE_BUTTON_RIGHT: $TileMap.place_struct(ground.local_to_map(get_global_mouse_position()-$TileMap.global_position), $TileMap.StructType.EMPTY_ROOM) if event is InputEventMouseMotion and is_drawing_road: # Получаем позицию мыши в мировых координатах var current_tile:Vector2 = ground.local_to_map(get_global_mouse_position()-$TileMap.global_position) if buildings.get_cell_source_id(current_tile) == -1: roads.set_cells_terrain_connect([current_tile], 0, 2, true)