From 781e9a452acb6c5ff3961e3c4b0f61381c82125e Mon Sep 17 00:00:00 2001 From: NnYGames Date: Sun, 8 Sep 2024 23:49:37 +0300 Subject: [PATCH 1/5] Added placing buildings --- Main.tscn | 4 +++- Test_Building.tscn | 6 ++++++ main.gd | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 Test_Building.tscn create mode 100644 main.gd diff --git a/Main.tscn b/Main.tscn index 336395e..e6a4dec 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,8 +1,10 @@ -[gd_scene load_steps=2 format=3 uid="uid://5ske2hm55rce"] +[gd_scene load_steps=3 format=3 uid="uid://5ske2hm55rce"] [ext_resource type="Theme" uid="uid://d035h7upxrw3h" path="res://theme.tres" id="1_xbn5h"] +[ext_resource type="Script" path="res://main.gd" id="1_xjws2"] [node name="Main" type="Node2D"] +script = ExtResource("1_xjws2") [node name="Control" type="Control" parent="."] layout_mode = 3 diff --git a/Test_Building.tscn b/Test_Building.tscn new file mode 100644 index 0000000..0db25ad --- /dev/null +++ b/Test_Building.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://bxf8c2vnv1cs6"] + +[ext_resource type="Texture2D" uid="uid://bi03hh1ousovx" path="res://icon.svg" id="1_5dc4m"] + +[node name="TestBulding" type="Sprite2D"] +texture = ExtResource("1_5dc4m") diff --git a/main.gd b/main.gd new file mode 100644 index 0000000..938c332 --- /dev/null +++ b/main.gd @@ -0,0 +1,9 @@ +extends Node2D + +var test_building_scene: PackedScene = preload("res://Test_Building.tscn") + +func _process(_delta): + if Input.is_action_just_pressed("lclick"): + var test_building: Sprite2D = test_building_scene.instantiate() + test_building.position = get_global_mouse_position() + $".".add_child(test_building) From 17f4e92df08f37e09e5414c38c1b92c27e013227 Mon Sep 17 00:00:00 2001 From: NnYGames Date: Mon, 9 Sep 2024 20:46:51 +0300 Subject: [PATCH 2/5] Added basic placing of building Added placing of buildings on the tile map using get input, will try to do it using mouse handler --- Main.tscn | 36 +++++++++++++++++++++++++++++++++--- Test_Building.tscn | 6 ------ iso_building.png | Bin 0 -> 427 bytes iso_building.png.import | 34 ++++++++++++++++++++++++++++++++++ iso_tile.png | Bin 0 -> 300 bytes iso_tile.png.import | 34 ++++++++++++++++++++++++++++++++++ main.gd | 9 --------- tile_map.gd | 30 ++++++++++++++++++++++++++++++ 8 files changed, 131 insertions(+), 18 deletions(-) delete mode 100644 Test_Building.tscn create mode 100644 iso_building.png create mode 100644 iso_building.png.import create mode 100644 iso_tile.png create mode 100644 iso_tile.png.import delete mode 100644 main.gd create mode 100644 tile_map.gd diff --git a/Main.tscn b/Main.tscn index e6a4dec..77a4589 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,10 +1,31 @@ -[gd_scene load_steps=3 format=3 uid="uid://5ske2hm55rce"] +[gd_scene load_steps=8 format=3 uid="uid://5ske2hm55rce"] [ext_resource type="Theme" uid="uid://d035h7upxrw3h" path="res://theme.tres" id="1_xbn5h"] -[ext_resource type="Script" path="res://main.gd" id="1_xjws2"] +[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="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") [node name="Main" type="Node2D"] -script = ExtResource("1_xjws2") [node name="Control" type="Control" parent="."] layout_mode = 3 @@ -12,3 +33,12 @@ 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" +script = ExtResource("5_v47eg") + +[node name="Camera2D" type="Camera2D" parent="."] diff --git a/Test_Building.tscn b/Test_Building.tscn deleted file mode 100644 index 0db25ad..0000000 --- a/Test_Building.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://bxf8c2vnv1cs6"] - -[ext_resource type="Texture2D" uid="uid://bi03hh1ousovx" path="res://icon.svg" id="1_5dc4m"] - -[node name="TestBulding" type="Sprite2D"] -texture = ExtResource("1_5dc4m") diff --git a/iso_building.png b/iso_building.png new file mode 100644 index 0000000000000000000000000000000000000000..1617483844dbd0e9c0c3f54cdf072ff1bf13c336 GIT binary patch literal 427 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTC#^NA%Cx&(BWL^T<-kvUwAsLNt zryJ%m849@WUo0}Gr7P_rljej=1x*)<8<#j~3Yq}9nih^yDqMODw*v|r<}{wuJaGEf z8UX|2H6nk**Y1%zUvvKZEp7oP4#gIMPx>G0p6|V1d0OUN)}t*2&u6LaoTsD4%HWfB zH2L0tQ}1M@1MBViR@=`MJu04js^hlQnny90=ZfykP`F<nRq%_?2JC;xElV9luf z85d$5&@QpDVa-;SfOvHmraJ{8m8?5leX9Q{?K;QmT)ifU; zpFgo1nwjGZ`4~WS6hE-Q?b-@hkJilyjfzE;R**M@zZ{WxO*BWQm+2_F>!1y~p!+XMg+| zF-^?Cc=NidTK;~|{ojADU9xtjmcuvIj-n4f(hAkwLWUJ$!V0goUcaAxLF{PzkNX@S z@{clJ`e^doC@S{aQSq7IG!2VZ_R1z5eGqvjIZq%(!ol)~f5q(`k9L9_!jL>q?2YBw mc>=C>Kn`DOglC$sFM}44%>j}Hf=j`ZL6oPfpUXO@geCx>QF3tr literal 0 HcmV?d00001 diff --git a/iso_tile.png.import b/iso_tile.png.import new file mode 100644 index 0000000..57f7797 --- /dev/null +++ b/iso_tile.png.import @@ -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 diff --git a/main.gd b/main.gd deleted file mode 100644 index 938c332..0000000 --- a/main.gd +++ /dev/null @@ -1,9 +0,0 @@ -extends Node2D - -var test_building_scene: PackedScene = preload("res://Test_Building.tscn") - -func _process(_delta): - if Input.is_action_just_pressed("lclick"): - var test_building: Sprite2D = test_building_scene.instantiate() - test_building.position = get_global_mouse_position() - $".".add_child(test_building) diff --git a/tile_map.gd b/tile_map.gd new file mode 100644 index 0000000..663690d --- /dev/null +++ b/tile_map.gd @@ -0,0 +1,30 @@ +extends TileMap + +var GridSize = 16 +var Dic = {} +var placed = [] + +func _ready(): + for x in GridSize: + for y in GridSize: + Dic[str(Vector2(x,y))] = { + "Type": "Ground", + "Position": str(Vector2(x,y)), + "Placed": false + } + set_cell(0, Vector2(x, y), 0, Vector2i(0,0), 0) + +func _process(delta): + 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(1, Vector2(x,y)) + + if Dic.has(str(tile)): + set_cell(1, tile, 1, Vector2i(0,0), 0) + #print(Dic[str(tile)]) + + if Input.is_action_just_pressed("lclick"): + Dic[str(tile)]["Placed"] = true From 285479f89b8a56a9752311ad7e54d4c66c7a4311 Mon Sep 17 00:00:00 2001 From: NnYGames Date: Mon, 9 Sep 2024 20:55:23 +0300 Subject: [PATCH 3/5] Added building mode Added going in and out of building mode by pressing right click, still didn't fully underdstand how to use mouse node --- Main.tscn | 13 ++++++++++++- tile_map.gd | 42 ++++++++++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/Main.tscn b/Main.tscn index 77a4589..4e5397e 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=8 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="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"] @@ -25,6 +26,8 @@ tile_size = Vector2i(16, 8) sources/0 = SubResource("TileSetAtlasSource_dxrqb") sources/1 = SubResource("TileSetAtlasSource_j7eew") +[sub_resource type="CircleShape2D" id="CircleShape2D_s8q4l"] + [node name="Main" type="Node2D"] [node name="Control" type="Control" parent="."] @@ -41,4 +44,12 @@ format = 2 layer_1/name = "Layer1" script = ExtResource("5_v47eg") +[node name="MouseHandler" parent="TileMap" instance=ExtResource("5_6lpdu")] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="TileMap/MouseHandler"] +shape = SubResource("CircleShape2D_s8q4l") + [node name="Camera2D" type="Camera2D" parent="."] + +[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"] diff --git a/tile_map.gd b/tile_map.gd index 663690d..480291a 100644 --- a/tile_map.gd +++ b/tile_map.gd @@ -2,29 +2,43 @@ extends TileMap var GridSize = 16 var Dic = {} -var placed = [] +var Building_Mode: bool = false func _ready(): for x in GridSize: for y in GridSize: Dic[str(Vector2(x,y))] = { - "Type": "Ground", - "Position": str(Vector2(x,y)), + #"Type": "Ground", "Placed": false } set_cell(0, Vector2(x, y), 0, Vector2i(0,0), 0) func _process(delta): - var tile = local_to_map(get_global_mouse_position()) + if (Input.is_action_just_pressed("rclick")): + Building_Mode = !Building_Mode + for x in GridSize: + for y in GridSize: + if !Dic[str(Vector2(x,y))].get("Placed"): + erase_cell(1, Vector2(x,y)) - for x in GridSize: - for y in GridSize: - if !Dic[str(Vector2(x,y))].get("Placed"): - erase_cell(1, Vector2(x,y)) - - if Dic.has(str(tile)): - set_cell(1, tile, 1, Vector2i(0,0), 0) - #print(Dic[str(tile)]) + if Building_Mode: + var tile = local_to_map(get_global_mouse_position()) - if Input.is_action_just_pressed("lclick"): - Dic[str(tile)]["Placed"] = true + for x in GridSize: + for y in GridSize: + if !Dic[str(Vector2(x,y))].get("Placed"): + erase_cell(1, Vector2(x,y)) + + if Dic.has(str(tile)): + set_cell(1, tile, 1, Vector2i(0,0), 0) + + if Input.is_action_just_pressed("lclick"): + Dic[str(tile)]["Placed"] = true + + +func _on_mouse_handler_clicked(): + pass # Replace with function body. + + +func _on_mouse_handler_rclicked(): + pass # Replace with function body. From ab188c54e05a88e9886a12a5f34dbc59f4114f90 Mon Sep 17 00:00:00 2001 From: Ategon Date: Mon, 9 Sep 2024 14:19:38 -0400 Subject: [PATCH 4/5] Make tilemap use mouse handler --- Main.tscn | 2 ++ tile_map.gd | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Main.tscn b/Main.tscn index 4e5397e..ff92e98 100644 --- a/Main.tscn +++ b/Main.tscn @@ -27,6 +27,7 @@ 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"] @@ -45,6 +46,7 @@ layer_1/name = "Layer1" 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") diff --git a/tile_map.gd b/tile_map.gd index 480291a..7926b84 100644 --- a/tile_map.gd +++ b/tile_map.gd @@ -14,12 +14,8 @@ func _ready(): set_cell(0, Vector2(x, y), 0, Vector2i(0,0), 0) func _process(delta): - if (Input.is_action_just_pressed("rclick")): - Building_Mode = !Building_Mode - for x in GridSize: - for y in GridSize: - if !Dic[str(Vector2(x,y))].get("Placed"): - erase_cell(1, Vector2(x,y)) + #if (Input.is_action_just_pressed("rclick")): + if Building_Mode: var tile = local_to_map(get_global_mouse_position()) @@ -31,14 +27,17 @@ func _process(delta): if Dic.has(str(tile)): set_cell(1, tile, 1, Vector2i(0,0), 0) - - if Input.is_action_just_pressed("lclick"): - Dic[str(tile)]["Placed"] = true func _on_mouse_handler_clicked(): - pass # Replace with function body. + if Building_Mode: + var tile = local_to_map(get_global_mouse_position()) + Dic[str(tile)]["Placed"] = true func _on_mouse_handler_rclicked(): - pass # Replace with function body. + Building_Mode = !Building_Mode + for x in GridSize: + for y in GridSize: + if !Dic[str(Vector2(x,y))].get("Placed"): + erase_cell(1, Vector2(x,y)) From 45f9c3ba88a16fe8ff7681ca480f6f8c327a3e33 Mon Sep 17 00:00:00 2001 From: NnYGames Date: Tue, 10 Sep 2024 04:34:30 +0300 Subject: [PATCH 5/5] Added map Added map that is randomly generated but has a pattern of placing tiles in a higher layer near the center Also made it so placing a tower would change according to the top layer --- Mai8E8B.tmp | 62 ++++++++++++++++++++++++++++++++++++++++++ MaiD4A.tmp | 62 ++++++++++++++++++++++++++++++++++++++++++ Main.tscn | 5 ++++ tile_map.gd | 77 ++++++++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 196 insertions(+), 10 deletions(-) create mode 100644 Mai8E8B.tmp create mode 100644 MaiD4A.tmp diff --git a/Mai8E8B.tmp b/Mai8E8B.tmp new file mode 100644 index 0000000..259b84e --- /dev/null +++ b/Mai8E8B.tmp @@ -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"] diff --git a/MaiD4A.tmp b/MaiD4A.tmp new file mode 100644 index 0000000..259b84e --- /dev/null +++ b/MaiD4A.tmp @@ -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"] diff --git a/Main.tscn b/Main.tscn index ff92e98..259b84e 100644 --- a/Main.tscn +++ b/Main.tscn @@ -43,6 +43,10 @@ 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")] @@ -52,6 +56,7 @@ position = Vector2(318, 178) 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"] diff --git a/tile_map.gd b/tile_map.gd index 7926b84..c0ed080 100644 --- a/tile_map.gd +++ b/tile_map.gd @@ -1,32 +1,88 @@ extends TileMap -var GridSize = 16 +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))] = { - #"Type": "Ground", + "Layer": layer_number, "Placed": false } - set_cell(0, Vector2(x, y), 0, Vector2i(0,0), 0) - + func _process(delta): - #if (Input.is_action_just_pressed("rclick")): - - 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(1, Vector2(x,y)) + erase_cell(Dic[str(Vector2(x,y))].get("Layer"), Vector2(x,y)) + pass if Dic.has(str(tile)): - set_cell(1, tile, 1, Vector2i(0,0), 0) + set_cell(Dic[str(tile)].get("Layer"), tile, 1, Vector2i(0,0), 0) func _on_mouse_handler_clicked(): @@ -40,4 +96,5 @@ func _on_mouse_handler_rclicked(): for x in GridSize: for y in GridSize: if !Dic[str(Vector2(x,y))].get("Placed"): - erase_cell(1, Vector2(x,y)) + erase_cell(Dic[str(Vector2(x,y))].get("Layer"), Vector2(x,y)) + pass