place_buildings #24
8 changed files with 343 additions and 1 deletions
62
Mai8E8B.tmp
Normal file
62
Mai8E8B.tmp
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
[gd_scene load_steps=10 format=3 uid="uid://5ske2hm55rce"]
|
||||||
|
|
||||||
|
[ext_resource type="Theme" uid="uid://d035h7upxrw3h" path="res://theme.tres" id="1_xbn5h"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://bsrh0u02bckhy" path="res://iso_building.png" id="3_qa5pv"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://bvn5lewpp7pmd" path="res://iso_tile.png" id="4_7pks7"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dykc1mgg5uopw" path="res://components/Cursor/MouseHandler.tscn" id="5_6lpdu"]
|
||||||
|
[ext_resource type="Script" path="res://tile_map.gd" id="5_v47eg"]
|
||||||
|
|
||||||
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_dxrqb"]
|
||||||
|
texture = ExtResource("4_7pks7")
|
||||||
|
margins = Vector2i(16, 16)
|
||||||
|
1:1/0 = 0
|
||||||
|
0:0/0 = 0
|
||||||
|
|
||||||
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_j7eew"]
|
||||||
|
texture = ExtResource("3_qa5pv")
|
||||||
|
margins = Vector2i(15, 14)
|
||||||
|
texture_region_size = Vector2i(18, 20)
|
||||||
|
1:1/0 = 0
|
||||||
|
0:0/0 = 0
|
||||||
|
|
||||||
|
[sub_resource type="TileSet" id="TileSet_2mye8"]
|
||||||
|
tile_shape = 1
|
||||||
|
tile_layout = 5
|
||||||
|
tile_size = Vector2i(16, 8)
|
||||||
|
sources/0 = SubResource("TileSetAtlasSource_dxrqb")
|
||||||
|
sources/1 = SubResource("TileSetAtlasSource_j7eew")
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_s8q4l"]
|
||||||
|
radius = 134.7
|
||||||
|
|
||||||
|
[node name="Main" type="Node2D"]
|
||||||
|
|
||||||
|
[node name="Control" type="Control" parent="."]
|
||||||
|
layout_mode = 3
|
||||||
|
anchors_preset = 0
|
||||||
|
offset_right = 40.0
|
||||||
|
offset_bottom = 40.0
|
||||||
|
theme = ExtResource("1_xbn5h")
|
||||||
|
|
||||||
|
[node name="TileMap" type="TileMap" parent="."]
|
||||||
|
tile_set = SubResource("TileSet_2mye8")
|
||||||
|
rendering_quadrant_size = 128
|
||||||
|
format = 2
|
||||||
|
layer_1/name = "Layer1"
|
||||||
|
layer_2/name = "Layer2"
|
||||||
|
layer_3/name = "Layer3"
|
||||||
|
layer_4/name = "Layer4"
|
||||||
|
layer_5/name = "Layer5"
|
||||||
|
script = ExtResource("5_v47eg")
|
||||||
|
|
||||||
|
[node name="MouseHandler" parent="TileMap" instance=ExtResource("5_6lpdu")]
|
||||||
|
position = Vector2(318, 178)
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="TileMap/MouseHandler"]
|
||||||
|
shape = SubResource("CircleShape2D_s8q4l")
|
||||||
|
|
||||||
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
|
offset = Vector2(50, 150)
|
||||||
|
|
||||||
|
[connection signal="clicked" from="TileMap/MouseHandler" to="TileMap" method="_on_mouse_handler_clicked"]
|
||||||
|
[connection signal="rclicked" from="TileMap/MouseHandler" to="TileMap" method="_on_mouse_handler_rclicked"]
|
62
MaiD4A.tmp
Normal file
62
MaiD4A.tmp
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
[gd_scene load_steps=10 format=3 uid="uid://5ske2hm55rce"]
|
||||||
|
|
||||||
|
[ext_resource type="Theme" uid="uid://d035h7upxrw3h" path="res://theme.tres" id="1_xbn5h"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://bsrh0u02bckhy" path="res://iso_building.png" id="3_qa5pv"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://bvn5lewpp7pmd" path="res://iso_tile.png" id="4_7pks7"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dykc1mgg5uopw" path="res://components/Cursor/MouseHandler.tscn" id="5_6lpdu"]
|
||||||
|
[ext_resource type="Script" path="res://tile_map.gd" id="5_v47eg"]
|
||||||
|
|
||||||
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_dxrqb"]
|
||||||
|
texture = ExtResource("4_7pks7")
|
||||||
|
margins = Vector2i(16, 16)
|
||||||
|
1:1/0 = 0
|
||||||
|
0:0/0 = 0
|
||||||
|
|
||||||
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_j7eew"]
|
||||||
|
texture = ExtResource("3_qa5pv")
|
||||||
|
margins = Vector2i(15, 14)
|
||||||
|
texture_region_size = Vector2i(18, 20)
|
||||||
|
1:1/0 = 0
|
||||||
|
0:0/0 = 0
|
||||||
|
|
||||||
|
[sub_resource type="TileSet" id="TileSet_2mye8"]
|
||||||
|
tile_shape = 1
|
||||||
|
tile_layout = 5
|
||||||
|
tile_size = Vector2i(16, 8)
|
||||||
|
sources/0 = SubResource("TileSetAtlasSource_dxrqb")
|
||||||
|
sources/1 = SubResource("TileSetAtlasSource_j7eew")
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_s8q4l"]
|
||||||
|
radius = 134.7
|
||||||
|
|
||||||
|
[node name="Main" type="Node2D"]
|
||||||
|
|
||||||
|
[node name="Control" type="Control" parent="."]
|
||||||
|
layout_mode = 3
|
||||||
|
anchors_preset = 0
|
||||||
|
offset_right = 40.0
|
||||||
|
offset_bottom = 40.0
|
||||||
|
theme = ExtResource("1_xbn5h")
|
||||||
|
|
||||||
|
[node name="TileMap" type="TileMap" parent="."]
|
||||||
|
tile_set = SubResource("TileSet_2mye8")
|
||||||
|
rendering_quadrant_size = 128
|
||||||
|
format = 2
|
||||||
|
layer_1/name = "Layer1"
|
||||||
|
layer_2/name = "Layer2"
|
||||||
|
layer_3/name = "Layer3"
|
||||||
|
layer_4/name = "Layer4"
|
||||||
|
layer_5/name = "Layer5"
|
||||||
|
script = ExtResource("5_v47eg")
|
||||||
|
|
||||||
|
[node name="MouseHandler" parent="TileMap" instance=ExtResource("5_6lpdu")]
|
||||||
|
position = Vector2(318, 178)
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="TileMap/MouseHandler"]
|
||||||
|
shape = SubResource("CircleShape2D_s8q4l")
|
||||||
|
|
||||||
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
|
offset = Vector2(50, 150)
|
||||||
|
|
||||||
|
[connection signal="clicked" from="TileMap/MouseHandler" to="TileMap" method="_on_mouse_handler_clicked"]
|
||||||
|
[connection signal="rclicked" from="TileMap/MouseHandler" to="TileMap" method="_on_mouse_handler_rclicked"]
|
52
Main.tscn
52
Main.tscn
|
@ -1,6 +1,33 @@
|
||||||
[gd_scene load_steps=2 format=3 uid="uid://5ske2hm55rce"]
|
[gd_scene load_steps=10 format=3 uid="uid://5ske2hm55rce"]
|
||||||
|
|
||||||
[ext_resource type="Theme" uid="uid://d035h7upxrw3h" path="res://theme.tres" id="1_xbn5h"]
|
[ext_resource type="Theme" uid="uid://d035h7upxrw3h" path="res://theme.tres" id="1_xbn5h"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://bsrh0u02bckhy" path="res://iso_building.png" id="3_qa5pv"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://bvn5lewpp7pmd" path="res://iso_tile.png" id="4_7pks7"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dykc1mgg5uopw" path="res://components/Cursor/MouseHandler.tscn" id="5_6lpdu"]
|
||||||
|
[ext_resource type="Script" path="res://tile_map.gd" id="5_v47eg"]
|
||||||
|
|
||||||
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_dxrqb"]
|
||||||
|
texture = ExtResource("4_7pks7")
|
||||||
|
margins = Vector2i(16, 16)
|
||||||
|
1:1/0 = 0
|
||||||
|
0:0/0 = 0
|
||||||
|
|
||||||
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_j7eew"]
|
||||||
|
texture = ExtResource("3_qa5pv")
|
||||||
|
margins = Vector2i(15, 14)
|
||||||
|
texture_region_size = Vector2i(18, 20)
|
||||||
|
1:1/0 = 0
|
||||||
|
0:0/0 = 0
|
||||||
|
|
||||||
|
[sub_resource type="TileSet" id="TileSet_2mye8"]
|
||||||
|
tile_shape = 1
|
||||||
|
tile_layout = 5
|
||||||
|
tile_size = Vector2i(16, 8)
|
||||||
|
sources/0 = SubResource("TileSetAtlasSource_dxrqb")
|
||||||
|
sources/1 = SubResource("TileSetAtlasSource_j7eew")
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_s8q4l"]
|
||||||
|
radius = 134.7
|
||||||
|
|
||||||
[node name="Main" type="Node2D"]
|
[node name="Main" type="Node2D"]
|
||||||
|
|
||||||
|
@ -10,3 +37,26 @@ anchors_preset = 0
|
||||||
offset_right = 40.0
|
offset_right = 40.0
|
||||||
offset_bottom = 40.0
|
offset_bottom = 40.0
|
||||||
theme = ExtResource("1_xbn5h")
|
theme = ExtResource("1_xbn5h")
|
||||||
|
|
||||||
|
[node name="TileMap" type="TileMap" parent="."]
|
||||||
|
tile_set = SubResource("TileSet_2mye8")
|
||||||
|
rendering_quadrant_size = 128
|
||||||
|
format = 2
|
||||||
|
layer_1/name = "Layer1"
|
||||||
|
layer_2/name = "Layer2"
|
||||||
|
layer_3/name = "Layer3"
|
||||||
|
layer_4/name = "Layer4"
|
||||||
|
layer_5/name = "Layer5"
|
||||||
|
script = ExtResource("5_v47eg")
|
||||||
|
|
||||||
|
[node name="MouseHandler" parent="TileMap" instance=ExtResource("5_6lpdu")]
|
||||||
|
position = Vector2(318, 178)
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="TileMap/MouseHandler"]
|
||||||
|
shape = SubResource("CircleShape2D_s8q4l")
|
||||||
|
|
||||||
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
|
offset = Vector2(50, 150)
|
||||||
|
|
||||||
|
[connection signal="clicked" from="TileMap/MouseHandler" to="TileMap" method="_on_mouse_handler_clicked"]
|
||||||
|
[connection signal="rclicked" from="TileMap/MouseHandler" to="TileMap" method="_on_mouse_handler_rclicked"]
|
||||||
|
|
BIN
iso_building.png
Normal file
BIN
iso_building.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 427 B |
34
iso_building.png.import
Normal file
34
iso_building.png.import
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://bsrh0u02bckhy"
|
||||||
|
path="res://.godot/imported/iso_building.png-07fa6cdf1b52a70a76ecc45b8890244f.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://iso_building.png"
|
||||||
|
dest_files=["res://.godot/imported/iso_building.png-07fa6cdf1b52a70a76ecc45b8890244f.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
|
BIN
iso_tile.png
Normal file
BIN
iso_tile.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 300 B |
34
iso_tile.png.import
Normal file
34
iso_tile.png.import
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://bvn5lewpp7pmd"
|
||||||
|
path="res://.godot/imported/iso_tile.png-22fe1886c3f7d12f0ecefdbde6a3adae.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://iso_tile.png"
|
||||||
|
dest_files=["res://.godot/imported/iso_tile.png-22fe1886c3f7d12f0ecefdbde6a3adae.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
|
100
tile_map.gd
Normal file
100
tile_map.gd
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
extends TileMap
|
||||||
|
|
||||||
|
var GridSize = 33
|
||||||
|
var Dic = {}
|
||||||
|
var Building_Mode: bool = false
|
||||||
|
|
||||||
|
func generate_percentage(percentages: Array):
|
||||||
|
var array_length = 0
|
||||||
|
for percentage in percentages.size():
|
||||||
|
if percentages[percentage] < 0:
|
||||||
|
percentages[percentage] = 0
|
||||||
|
array_length += percentages[percentage]
|
||||||
|
|
||||||
|
var arr: Array
|
||||||
|
arr.resize(array_length)
|
||||||
|
var sum = 0
|
||||||
|
for percentage in percentages.size():
|
||||||
|
for num in percentages[percentage]:
|
||||||
|
arr[num + sum] = percentage
|
||||||
|
sum += percentages[percentage]
|
||||||
|
return arr[randi()%array_length] + 1
|
||||||
|
|
||||||
|
func abs(num: int):
|
||||||
|
if num < 0:
|
||||||
|
num = -num
|
||||||
|
return num
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
for x in GridSize:
|
||||||
|
for y in GridSize:
|
||||||
|
var layer_number: int
|
||||||
|
var x_value: int = abs(GridSize/2 - x)
|
||||||
|
var y_value: int = abs(GridSize/2 - y)
|
||||||
|
var max_value: int = maxi(x_value, y_value)
|
||||||
|
match max_value:
|
||||||
|
16,15:
|
||||||
|
layer_number = 1
|
||||||
|
14:
|
||||||
|
layer_number = generate_percentage([3,1])
|
||||||
|
13:
|
||||||
|
layer_number = generate_percentage([2,1])
|
||||||
|
12:
|
||||||
|
layer_number = generate_percentage([1,1])
|
||||||
|
11:
|
||||||
|
layer_number = generate_percentage([1,2,1])
|
||||||
|
10:
|
||||||
|
layer_number = generate_percentage([0,3,2])
|
||||||
|
9:
|
||||||
|
layer_number = generate_percentage([0,1,1])
|
||||||
|
8:
|
||||||
|
layer_number = generate_percentage([0,1,2,1])
|
||||||
|
7:
|
||||||
|
layer_number = generate_percentage([0,0,3,2])
|
||||||
|
6:
|
||||||
|
layer_number = generate_percentage([0,0,1,1])
|
||||||
|
5:
|
||||||
|
layer_number = generate_percentage([0,0,1,2,1])
|
||||||
|
4:
|
||||||
|
layer_number = generate_percentage([0,0,0,3,2])
|
||||||
|
3:
|
||||||
|
layer_number = generate_percentage([0,0,0,1,1])
|
||||||
|
2:
|
||||||
|
layer_number = generate_percentage([0,0,0,1,2])
|
||||||
|
1,0:
|
||||||
|
layer_number = 5
|
||||||
|
print("x- ",x," y- ",y," layer- ",layer_number)
|
||||||
|
for layer in layer_number:
|
||||||
|
set_cell(layer, Vector2(x, y), 0, Vector2i(0,0), 0)
|
||||||
|
Dic[str(Vector2(x,y))] = {
|
||||||
|
"Layer": layer_number,
|
||||||
|
"Placed": false
|
||||||
|
}
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
if Building_Mode:
|
||||||
|
var tile = local_to_map(get_global_mouse_position())
|
||||||
|
|
||||||
|
for x in GridSize:
|
||||||
|
for y in GridSize:
|
||||||
|
if !Dic[str(Vector2(x,y))].get("Placed"):
|
||||||
|
erase_cell(Dic[str(Vector2(x,y))].get("Layer"), Vector2(x,y))
|
||||||
|
pass
|
||||||
|
|
||||||
|
if Dic.has(str(tile)):
|
||||||
|
set_cell(Dic[str(tile)].get("Layer"), tile, 1, Vector2i(0,0), 0)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_mouse_handler_clicked():
|
||||||
|
if Building_Mode:
|
||||||
|
var tile = local_to_map(get_global_mouse_position())
|
||||||
|
Dic[str(tile)]["Placed"] = true
|
||||||
|
|
||||||
|
|
||||||
|
func _on_mouse_handler_rclicked():
|
||||||
|
Building_Mode = !Building_Mode
|
||||||
|
for x in GridSize:
|
||||||
|
for y in GridSize:
|
||||||
|
if !Dic[str(Vector2(x,y))].get("Placed"):
|
||||||
|
erase_cell(Dic[str(Vector2(x,y))].get("Layer"), Vector2(x,y))
|
||||||
|
pass
|
Loading…
Reference in a new issue