Отработано размещение больших структур
This commit is contained in:
parent
00c22e1be4
commit
0e4e854cc1
BIN
assets/coridors.png
Normal file
BIN
assets/coridors.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 398 B |
34
assets/coridors.png.import
Normal file
34
assets/coridors.png.import
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://b8k27fv80r3qm"
|
||||||
|
path="res://.godot/imported/coridors.png-42ffbd04c5cdb13f597308920a8a1657.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/coridors.png"
|
||||||
|
dest_files=["res://.godot/imported/coridors.png-42ffbd04c5cdb13f597308920a8a1657.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
Binary file not shown.
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 4.5 KiB |
76
tile_map.gd
Normal file
76
tile_map.gd
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
extends Node2D
|
||||||
|
|
||||||
|
enum StructType {
|
||||||
|
EMPTY_ROOM, # 0. Пустой модуль
|
||||||
|
RESIDENTIAL_ROOM, # 1. Жилой Модуль
|
||||||
|
LABORATORY_ROOM, # 2. Лабораторный Модуль
|
||||||
|
ENERGY_ROOM, # 3. Энергетический Модуль
|
||||||
|
FARM_ROOM, # 4. Фермерский Модуль
|
||||||
|
LIFE_SUPPORT_ROOM, # 5. Модуль Жизнеобеспечения
|
||||||
|
CONTROL_ROOM, # 6. Модуль Управления
|
||||||
|
OBSERVATORY_ROOM, # 7. Модуль Обсерватории
|
||||||
|
MEDICAL_ROOM, # 8. Медицинский Модуль
|
||||||
|
GEOLOGICAL_ROOM, # 9. Геологический Модуль
|
||||||
|
RESOURCE_EXTRACTION_ROOM, # 10. Модуль Добычи и Переработки Ресурсов
|
||||||
|
COMMUNICATIONS_ROOM # 11. Модуль Связи и Навигации
|
||||||
|
}
|
||||||
|
|
||||||
|
enum struct_fields {
|
||||||
|
SOURCE_ID,
|
||||||
|
SIZE,
|
||||||
|
POS_ATLAS,
|
||||||
|
LAYER
|
||||||
|
}
|
||||||
|
|
||||||
|
@onready var structs = {
|
||||||
|
StructType.EMPTY_ROOM: {
|
||||||
|
struct_fields.SOURCE_ID: 1,
|
||||||
|
struct_fields.SIZE: Vector2i(5,5),
|
||||||
|
struct_fields.POS_ATLAS: Vector2i(0,0),
|
||||||
|
struct_fields.LAYER: $buildings/buildings0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var layers: Array[TileMapLayer]
|
||||||
|
var layers_dict: Dictionary
|
||||||
|
|
||||||
|
func _list_childrens(node: Node2D):
|
||||||
|
for child in node.get_children():
|
||||||
|
if child is TileMapLayer:
|
||||||
|
layers.append(child)
|
||||||
|
layers_dict.get_or_add(child.name, child)
|
||||||
|
elif child is Node2D:
|
||||||
|
_list_childrens(child)
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
layers = []
|
||||||
|
_list_childrens(self)
|
||||||
|
|
||||||
|
func get_maxZ(tile_pos: Vector2i) -> int:
|
||||||
|
for layer in layers:
|
||||||
|
if layer.get_cell_source_id(tile_pos) != -1:
|
||||||
|
return layer.z_index
|
||||||
|
return -1
|
||||||
|
|
||||||
|
func place_struct(pos: Vector2i, type: StructType):
|
||||||
|
#Is place free check
|
||||||
|
var struct_size = structs[type][struct_fields.SIZE]
|
||||||
|
var layer = structs[type][struct_fields.LAYER]
|
||||||
|
var source_id = structs[type][struct_fields.SOURCE_ID]
|
||||||
|
var pos_atlas = structs[type][struct_fields.POS_ATLAS]
|
||||||
|
|
||||||
|
var half_size = Vector2i(struct_size.x / 2, struct_size.y / 2)
|
||||||
|
|
||||||
|
for x in range(struct_size.x):
|
||||||
|
for y in range(struct_size.y):
|
||||||
|
var offset = Vector2i(x, y)
|
||||||
|
var tile_pos = pos+offset-half_size
|
||||||
|
if get_maxZ(tile_pos) >= layer.z_index:
|
||||||
|
return
|
||||||
|
|
||||||
|
for x in range(struct_size.x):
|
||||||
|
for y in range(struct_size.y):
|
||||||
|
var offset = Vector2i(x, y)
|
||||||
|
var tile_pos = pos+offset-half_size
|
||||||
|
layer.set_cell(tile_pos, source_id, Vector2i(x,y)+pos_atlas)
|
@ -1,11 +0,0 @@
|
|||||||
extends TileMapLayer
|
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
|
||||||
func _ready() -> void:
|
|
||||||
pass # Replace with function body.
|
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
func _process(delta: float) -> void:
|
|
||||||
pass
|
|
10
world.gd
10
world.gd
@ -1,7 +1,7 @@
|
|||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
# Переменная для хранения ссылки на TileMap
|
# Переменная для хранения ссылки на TileMap
|
||||||
@onready var buildings: TileMapLayer = $TileMap/buildings
|
@onready var buildings: TileMapLayer = $TileMap/buildings/buildings0
|
||||||
@onready var roads: TileMapLayer = $TileMap/roads
|
@onready var roads: TileMapLayer = $TileMap/roads
|
||||||
@onready var ground: TileMapLayer = $TileMap/ground
|
@onready var ground: TileMapLayer = $TileMap/ground
|
||||||
|
|
||||||
@ -17,16 +17,10 @@ func _input(event):
|
|||||||
if event.button_index == MOUSE_BUTTON_LEFT:
|
if event.button_index == MOUSE_BUTTON_LEFT:
|
||||||
is_drawing_road = event.pressed # Устанавливаем флаг, если кнопка нажата
|
is_drawing_road = event.pressed # Устанавливаем флаг, если кнопка нажата
|
||||||
elif event.button_index == MOUSE_BUTTON_RIGHT:
|
elif event.button_index == MOUSE_BUTTON_RIGHT:
|
||||||
is_drawing_mountian = event.pressed # Устанавливаем флаг, если кнопка нажата
|
$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:
|
if event is InputEventMouseMotion and is_drawing_road:
|
||||||
# Получаем позицию мыши в мировых координатах
|
# Получаем позицию мыши в мировых координатах
|
||||||
var current_tile:Vector2 = ground.local_to_map(get_global_mouse_position()-$TileMap.global_position)
|
var current_tile:Vector2 = ground.local_to_map(get_global_mouse_position()-$TileMap.global_position)
|
||||||
if buildings.get_cell_source_id(current_tile) == -1:
|
if buildings.get_cell_source_id(current_tile) == -1:
|
||||||
roads.set_cells_terrain_connect([current_tile], 0, 2, true)
|
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)
|
|
||||||
|
114
world.tscn
114
world.tscn
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user