testproject/world.gd
2024-12-06 21:03:26 +04:00

33 lines
1.7 KiB
GDScript

extends Node2D
# Переменная для хранения ссылки на TileMap
@onready var buildings: TileMapLayer = $TileMap/buildings
@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:
is_drawing_mountian = event.pressed # Устанавливаем флаг, если кнопка нажата
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)
if event is InputEventMouseMotion and is_drawing_mountian:
# Получаем позицию мыши в мировых координатах
var current_tile:Vector2 = ground.local_to_map(get_global_mouse_position()-$TileMap.global_position)
roads.set_cells_terrain_connect([current_tile], 0, -1, true)
buildings.set_cells_terrain_connect([current_tile], 0, 1, true)