testproject/world.gd

28 lines
1.4 KiB
GDScript3
Raw Normal View History

extends Node2D
# Переменная для хранения ссылки на TileMap
@onready var buildings: TileMapLayer = $TileMap/buildings/buildings0
2024-12-06 21:03:26 +04:00
@onready var roads: TileMapLayer = $TileMap/roads
@onready var ground: TileMapLayer = $TileMap/ground
@onready var tileMap: Node2D = $TileMap
2024-12-06 21:03:26 +04:00
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:
tileMap.place_struct(ground.local_to_map(get_global_mouse_position()-tileMap.global_position), tileMap.StructType.EMPTY_ROOM)
2024-12-06 21:03:26 +04:00
elif event.button_index == MOUSE_BUTTON_RIGHT:
tileMap.remove_struct(ground.local_to_map(get_global_mouse_position()-tileMap.global_position))
2024-12-06 21:03:26 +04:00
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)