diff --git a/maps/tampere_10x10km_1024px.png b/maps/tampere_10x10km_1024px.png new file mode 100644 index 0000000..8176c88 Binary files /dev/null and b/maps/tampere_10x10km_1024px.png differ diff --git a/maps/tampere_10x10km_1024px.png.import b/maps/tampere_10x10km_1024px.png.import new file mode 100644 index 0000000..bd32059 --- /dev/null +++ b/maps/tampere_10x10km_1024px.png.import @@ -0,0 +1,14 @@ +[remap] + +importer="image" +type="Image" +uid="uid://dprlyk4ednkp8" +path="res://.godot/imported/tampere_10x10km_1024px.png-569f3285557c876bd7277d49b8414424.image" + +[deps] + +source_file="res://maps/tampere_10x10km_1024px.png" +dest_files=["res://.godot/imported/tampere_10x10km_1024px.png-569f3285557c876bd7277d49b8414424.image"] + +[params] + diff --git a/maps/tampere_10x10km_4096px.png b/maps/tampere_10x10km_4096px.png new file mode 100644 index 0000000..1488a1b Binary files /dev/null and b/maps/tampere_10x10km_4096px.png differ diff --git a/maps/tampere_10x10km_4096px.png.import b/maps/tampere_10x10km_4096px.png.import new file mode 100644 index 0000000..7dc78c6 --- /dev/null +++ b/maps/tampere_10x10km_4096px.png.import @@ -0,0 +1,14 @@ +[remap] + +importer="image" +type="Image" +uid="uid://bl4xbe4vb3nft" +path="res://.godot/imported/tampere_10x10km_4096px.png-a656fcf9b79fbe6e529e735982b88a37.image" + +[deps] + +source_file="res://maps/tampere_10x10km_4096px.png" +dest_files=["res://.godot/imported/tampere_10x10km_4096px.png-a656fcf9b79fbe6e529e735982b88a37.image"] + +[params] + diff --git a/project.godot b/project.godot index ab7ce6c..5f5dd92 100644 --- a/project.godot +++ b/project.godot @@ -19,6 +19,10 @@ config/icon="res://icon.svg" Globals="*res://scripts/Globals.gd" +[debug] + +gdscript/warnings/integer_division=0 + [display] window/size/viewport_height=1080 diff --git a/scenes/Main.tscn b/scenes/Main.tscn index acab0fd..8dd1ab3 100644 --- a/scenes/Main.tscn +++ b/scenes/Main.tscn @@ -1,1472 +1,25 @@ -[gd_scene load_steps=12 format=3 uid="uid://ciperl36hv26g"] +[gd_scene load_steps=6 format=3 uid="uid://ciperl36hv26g"] [ext_resource type="Script" path="res://scripts/Main.gd" id="1_ysxum"] -[ext_resource type="Texture2D" uid="uid://byy4k72uxx7sj" path="res://art/buildings/residential/med/med20x20res001.png" id="2_sfv1p"] +[ext_resource type="Script" path="res://scripts/TileMapGenerator.gd" id="2_cbjcm"] [ext_resource type="Script" path="res://scripts/Control.gd" id="3_1t1c8"] -[ext_resource type="Script" path="res://scripts/World.gd" id="3_6q5ju"] -[ext_resource type="Texture2D" uid="uid://dakvtfpnjuwwl" path="res://art/placeholder/outdoors.png" id="3_yddbk"] [ext_resource type="PackedScene" uid="uid://2we3txfr812u" path="res://scenes/Camera_zoom_2d.tscn" id="4_rx82t"] -[ext_resource type="Texture2D" uid="uid://djy5ne2grdc03" path="res://art/terrain/terrain.png" id="5_bqev6"] - -[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_3q7ue"] -texture = ExtResource("2_sfv1p") -0:0/size_in_atlas = Vector2i(20, 20) -0:0/next_alternative_id = 2 -0:0/0 = 0 - -[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_s55i2"] -texture = ExtResource("3_yddbk") -0:0/0 = 0 -1:0/0 = 0 -2:0/0 = 0 -3:0/0 = 0 -8:0/0 = 0 -9:0/0 = 0 -10:0/0 = 0 -14:0/0 = 0 -15:0/0 = 0 -16:0/0 = 0 -17:0/0 = 0 -20:0/0 = 0 -21:0/0 = 0 -22:0/0 = 0 -23:0/0 = 0 -24:0/0 = 0 -25:0/0 = 0 -26:0/0 = 0 -27:0/0 = 0 -0:1/0 = 0 -1:1/0 = 0 -2:1/0 = 0 -3:1/0 = 0 -8:1/0 = 0 -9:1/0 = 0 -10:1/0 = 0 -14:1/0 = 0 -15:1/0 = 0 -16:1/0 = 0 -17:1/0 = 0 -21:1/0 = 0 -23:1/0 = 0 -25:1/0 = 0 -27:1/0 = 0 -28:1/0 = 0 -0:2/0 = 0 -1:2/0 = 0 -2:2/0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 0 -20:11/0 = 0 -21:11/0 = 0 -22:11/0 = 0 -23:11/0 = 0 -24:11/0 = 0 -25:11/0 = 0 -26:11/0 = 0 -0:12/0 = 0 -8:12/0 = 0 -9:12/0 = 0 -10:12/0 = 0 -11:12/0 = 0 -12:12/0 = 0 -13:12/0 = 0 -14:12/0 = 0 -15:12/0 = 0 -16:12/0 = 0 -17:12/0 = 0 -18:12/0 = 0 -19:12/0 = 0 -21:12/0 = 0 -22:12/0 = 0 -24:12/0 = 0 -25:12/0 = 0 -26:12/0 = 0 -0:13/0 = 0 -8:13/0 = 0 -9:13/0 = 0 -10:13/0 = 0 -11:13/0 = 0 -12:13/0 = 0 -13:13/0 = 0 -14:13/0 = 0 -15:13/0 = 0 -16:13/0 = 0 -17:13/0 = 0 -18:13/0 = 0 -19:13/0 = 0 -21:13/0 = 0 -22:13/0 = 0 -24:13/0 = 0 -25:13/0 = 0 -26:13/0 = 0 -0:14/0 = 0 -8:14/0 = 0 -9:14/0 = 0 -10:14/0 = 0 -11:14/0 = 0 -12:14/0 = 0 -13:14/0 = 0 -14:14/0 = 0 -15:14/0 = 0 -16:14/0 = 0 -17:14/0 = 0 -18:14/0 = 0 -19:14/0 = 0 -24:14/0 = 0 -10:15/0 = 0 -11:15/0 = 0 -12:15/0 = 0 -13:15/0 = 0 -14:15/0 = 0 -15:15/0 = 0 -16:15/0 = 0 -17:15/0 = 0 -18:15/0 = 0 -19:15/0 = 0 -21:15/0 = 0 -22:15/0 = 0 -23:15/0 = 0 -24:15/0 = 0 -25:15/0 = 0 -26:15/0 = 0 -27:15/0 = 0 -28:15/0 = 0 -21:16/0 = 0 -22:16/0 = 0 -23:16/0 = 0 -24:16/0 = 0 -25:16/0 = 0 -26:16/0 = 0 -27:16/0 = 0 -28:16/0 = 0 -21:17/0 = 0 -22:17/0 = 0 -23:17/0 = 0 -24:17/0 = 0 -25:17/0 = 0 -26:17/0 = 0 -27:17/0 = 0 -28:17/0 = 0 -8:18/0 = 0 -9:18/0 = 0 -10:18/0 = 0 -11:18/0 = 0 -21:18/0 = 0 -22:18/0 = 0 -23:18/0 = 0 -24:18/0 = 0 -25:18/0 = 0 -26:18/0 = 0 -27:18/0 = 0 -28:18/0 = 0 -8:19/0 = 0 -11:19/0 = 0 -21:19/0 = 0 -22:19/0 = 0 -23:19/0 = 0 -24:19/0 = 0 -25:19/0 = 0 -26:19/0 = 0 -27:19/0 = 0 -28:19/0 = 0 -8:20/0 = 0 -9:20/0 = 0 -10:20/0 = 0 -11:20/0 = 0 -21:20/0 = 0 -22:20/0 = 0 -23:20/0 = 0 -24:20/0 = 0 -25:20/0 = 0 -26:20/0 = 0 -27:20/0 = 0 -28:20/0 = 0 -9:21/0 = 0 -10:21/0 = 0 -11:21/0 = 0 -21:21/0 = 0 -22:21/0 = 0 -23:21/0 = 0 -24:21/0 = 0 -25:21/0 = 0 -26:21/0 = 0 -27:21/0 = 0 -28:21/0 = 0 -9:22/0 = 0 -10:22/0 = 0 -21:22/0 = 0 -22:22/0 = 0 -23:22/0 = 0 -24:22/0 = 0 -25:22/0 = 0 -26:22/0 = 0 -27:22/0 = 0 -28:22/0 = 0 -21:23/0 = 0 -22:23/0 = 0 -23:23/0 = 0 -24:23/0 = 0 -21:24/0 = 0 -22:24/0 = 0 -23:24/0 = 0 -24:24/0 = 0 -7:0/size_in_atlas = Vector2i(1, 3) -7:0/0 = 0 -7:3/0 = 0 -4:3/size_in_atlas = Vector2i(3, 1) -4:3/0 = 0 -4:0/size_in_atlas = Vector2i(3, 3) -4:0/0 = 0 -13:18/size_in_atlas = Vector2i(2, 5) -13:18/0 = 0 -12:20/size_in_atlas = Vector2i(1, 3) -12:20/0 = 0 -15:20/size_in_atlas = Vector2i(1, 3) -15:20/0 = 0 -4:24/size_in_atlas = Vector2i(3, 3) -4:24/0 = 0 -4:27/size_in_atlas = Vector2i(3, 1) -4:27/0 = 0 -7:27/0 = 0 -7:24/size_in_atlas = Vector2i(1, 3) -7:24/0 = 0 -4:20/size_in_atlas = Vector2i(3, 3) -4:20/0 = 0 -4:23/size_in_atlas = Vector2i(3, 1) -4:23/0 = 0 -7:23/0 = 0 -7:20/size_in_atlas = Vector2i(1, 3) -7:20/0 = 0 -4:16/size_in_atlas = Vector2i(3, 3) -4:16/0 = 0 -4:19/size_in_atlas = Vector2i(3, 1) -4:19/0 = 0 -7:19/0 = 0 -7:16/size_in_atlas = Vector2i(1, 3) -7:16/0 = 0 -7:15/0 = 0 -4:15/size_in_atlas = Vector2i(3, 1) -4:15/0 = 0 -4:12/size_in_atlas = Vector2i(3, 3) -4:12/0 = 0 -7:12/size_in_atlas = Vector2i(1, 3) -7:12/0 = 0 -4:4/size_in_atlas = Vector2i(3, 3) -4:4/0 = 0 -7:4/size_in_atlas = Vector2i(1, 3) -7:4/0 = 0 -7:7/0 = 0 -4:7/size_in_atlas = Vector2i(3, 1) -4:7/0 = 0 -4:8/size_in_atlas = Vector2i(3, 3) -4:8/0 = 0 -7:8/size_in_atlas = Vector2i(1, 3) -7:8/0 = 0 -7:11/0 = 0 -4:11/size_in_atlas = Vector2i(3, 1) -4:11/0 = 0 -8:15/size_in_atlas = Vector2i(2, 3) -8:15/0 = 0 -10:16/size_in_atlas = Vector2i(3, 2) -10:16/0 = 0 -13:16/size_in_atlas = Vector2i(3, 2) -13:16/0 = 0 -16:16/size_in_atlas = Vector2i(2, 2) -16:16/0 = 0 -14:2/size_in_atlas = Vector2i(4, 4) -14:2/0 = 0 - -[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_hwjm3"] -texture = ExtResource("5_bqev6") -0:0/next_alternative_id = 4 -0:0/0 = 0 -0:0/1 = 1 -0:0/1/flip_h = true -0:0/2 = 2 -0:0/2/flip_v = true -0:0/3 = 3 -0:0/3/transpose = true -1:0/next_alternative_id = 4 -1:0/0 = 0 -1:0/1 = 1 -1:0/1/flip_h = true -1:0/2 = 2 -1:0/2/flip_v = true -1:0/3 = 3 -1:0/3/transpose = true -2:0/0 = 0 -3:0/0 = 0 -4:0/0 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-20:8/0 = 0 -21:8/0 = 0 -22:8/0 = 0 -23:8/0 = 0 -24:8/0 = 0 -25:8/0 = 0 -26:8/0 = 0 -27:8/0 = 0 -28:8/0 = 0 -29:8/0 = 0 -30:8/0 = 0 -31:8/0 = 0 -0:9/0 = 0 -1:9/0 = 0 -2:9/0 = 0 -3:9/0 = 0 -4:9/0 = 0 -5:9/0 = 0 -6:9/0 = 0 -7:9/0 = 0 -8:9/0 = 0 -9:9/0 = 0 -10:9/0 = 0 -11:9/0 = 0 -12:9/0 = 0 -13:9/0 = 0 -14:9/0 = 0 -15:9/0 = 0 -16:9/0 = 0 -17:9/0 = 0 -18:9/0 = 0 -19:9/0 = 0 -20:9/0 = 0 -21:9/0 = 0 -22:9/0 = 0 -23:9/0 = 0 -24:9/0 = 0 -25:9/0 = 0 -26:9/0 = 0 -27:9/0 = 0 -28:9/0 = 0 -29:9/0 = 0 -30:9/0 = 0 -31:9/0 = 0 -0:10/0 = 0 -1:10/0 = 0 -2:10/0 = 0 -3:10/0 = 0 -4:10/0 = 0 -5:10/0 = 0 -6:10/0 = 0 -7:10/0 = 0 -8:10/0 = 0 -9:10/0 = 0 -10:10/0 = 0 -11:10/0 = 0 -12:10/0 = 0 -13:10/0 = 0 -14:10/0 = 0 -15:10/0 = 0 -16:10/0 = 0 -17:10/0 = 0 -18:10/0 = 0 -19:10/0 = 0 -20:10/0 = 0 -21:10/0 = 0 -22:10/0 = 0 -23:10/0 = 0 -24:10/0 = 0 -25:10/0 = 0 -26:10/0 = 0 -27:10/0 = 0 -28:10/0 = 0 -29:10/0 = 0 -30:10/0 = 0 -31:10/0 = 0 -0:11/0 = 0 -1:11/0 = 0 -2:11/0 = 0 -3:11/0 = 0 -4:11/0 = 0 -5:11/0 = 0 -6:11/0 = 0 -7:11/0 = 0 -8:11/0 = 0 -9:11/0 = 0 -10:11/0 = 0 -11:11/0 = 0 -12:11/0 = 0 -13:11/0 = 0 -14:11/0 = 0 -15:11/0 = 0 -16:11/0 = 0 -17:11/0 = 0 -18:11/0 = 0 -19:11/0 = 0 -20:11/0 = 0 -21:11/0 = 0 -22:11/0 = 0 -23:11/0 = 0 -24:11/0 = 0 -25:11/0 = 0 -26:11/0 = 0 -27:11/0 = 0 -28:11/0 = 0 -29:11/0 = 0 -30:11/0 = 0 -31:11/0 = 0 -0:12/0 = 0 -1:12/0 = 0 -2:12/0 = 0 -3:12/0 = 0 -4:12/0 = 0 -5:12/0 = 0 -6:12/0 = 0 -7:12/0 = 0 -8:12/0 = 0 -9:12/0 = 0 -10:12/0 = 0 -11:12/0 = 0 -12:12/0 = 0 -13:12/0 = 0 -14:12/0 = 0 -15:12/0 = 0 -16:12/0 = 0 -17:12/0 = 0 -18:12/0 = 0 -19:12/0 = 0 -20:12/0 = 0 -21:12/0 = 0 -22:12/0 = 0 -23:12/0 = 0 -24:12/0 = 0 -25:12/0 = 0 -26:12/0 = 0 -27:12/0 = 0 -28:12/0 = 0 -29:12/0 = 0 -30:12/0 = 0 -31:12/0 = 0 -0:13/0 = 0 -1:13/0 = 0 -2:13/0 = 0 -3:13/0 = 0 -4:13/0 = 0 -5:13/0 = 0 -6:13/0 = 0 -7:13/0 = 0 -8:13/0 = 0 -9:13/0 = 0 -10:13/0 = 0 -11:13/0 = 0 -12:13/0 = 0 -13:13/0 = 0 -14:13/0 = 0 -15:13/0 = 0 -16:13/0 = 0 -17:13/0 = 0 -18:13/0 = 0 -19:13/0 = 0 -20:13/0 = 0 -21:13/0 = 0 -22:13/0 = 0 -23:13/0 = 0 -24:13/0 = 0 -25:13/0 = 0 -26:13/0 = 0 -27:13/0 = 0 -28:13/0 = 0 -29:13/0 = 0 -30:13/0 = 0 -31:13/0 = 0 -0:14/0 = 0 -1:14/0 = 0 -2:14/0 = 0 -3:14/0 = 0 -4:14/0 = 0 -5:14/0 = 0 -6:14/0 = 0 -7:14/0 = 0 -8:14/0 = 0 -9:14/0 = 0 -10:14/0 = 0 -11:14/0 = 0 -12:14/0 = 0 -13:14/0 = 0 -14:14/0 = 0 -15:14/0 = 0 -16:14/0 = 0 -17:14/0 = 0 -18:14/0 = 0 -19:14/0 = 0 -20:14/0 = 0 -21:14/0 = 0 -22:14/0 = 0 -23:14/0 = 0 -24:14/0 = 0 -25:14/0 = 0 -26:14/0 = 0 -27:14/0 = 0 -28:14/0 = 0 -29:14/0 = 0 -30:14/0 = 0 -31:14/0 = 0 -0:15/0 = 0 -1:15/0 = 0 -2:15/0 = 0 -3:15/0 = 0 -4:15/0 = 0 -5:15/0 = 0 -6:15/0 = 0 -7:15/0 = 0 -8:15/0 = 0 -9:15/0 = 0 -10:15/0 = 0 -11:15/0 = 0 -12:15/0 = 0 -13:15/0 = 0 -14:15/0 = 0 -15:15/0 = 0 -16:15/0 = 0 -17:15/0 = 0 -18:15/0 = 0 -19:15/0 = 0 -20:15/0 = 0 -21:15/0 = 0 -22:15/0 = 0 -23:15/0 = 0 -24:15/0 = 0 -25:15/0 = 0 -26:15/0 = 0 -27:15/0 = 0 -28:15/0 = 0 -29:15/0 = 0 -30:15/0 = 0 -31:15/0 = 0 -0:16/0 = 0 -1:16/0 = 0 -2:16/0 = 0 -3:16/0 = 0 -4:16/0 = 0 -5:16/0 = 0 -6:16/0 = 0 -7:16/0 = 0 -8:16/0 = 0 -9:16/0 = 0 -10:16/0 = 0 -11:16/0 = 0 -12:16/0 = 0 -13:16/0 = 0 -14:16/0 = 0 -15:16/0 = 0 -16:16/0 = 0 -17:16/0 = 0 -18:16/0 = 0 -19:16/0 = 0 -20:16/0 = 0 -21:16/0 = 0 -22:16/0 = 0 -23:16/0 = 0 -24:16/0 = 0 -25:16/0 = 0 -26:16/0 = 0 -27:16/0 = 0 -28:16/0 = 0 -29:16/0 = 0 -30:16/0 = 0 -31:16/0 = 0 -0:17/0 = 0 -1:17/0 = 0 -2:17/0 = 0 -3:17/0 = 0 -4:17/0 = 0 -5:17/0 = 0 -6:17/0 = 0 -7:17/0 = 0 -8:17/0 = 0 -9:17/0 = 0 -10:17/0 = 0 -11:17/0 = 0 -12:17/0 = 0 -13:17/0 = 0 -14:17/0 = 0 -15:17/0 = 0 -16:17/0 = 0 -17:17/0 = 0 -18:17/0 = 0 -19:17/0 = 0 -20:17/0 = 0 -21:17/0 = 0 -22:17/0 = 0 -23:17/0 = 0 -24:17/0 = 0 -25:17/0 = 0 -26:17/0 = 0 -27:17/0 = 0 -28:17/0 = 0 -29:17/0 = 0 -30:17/0 = 0 -31:17/0 = 0 -0:18/0 = 0 -1:18/0 = 0 -2:18/0 = 0 -3:18/0 = 0 -4:18/0 = 0 -5:18/0 = 0 -6:18/0 = 0 -7:18/0 = 0 -8:18/0 = 0 -9:18/0 = 0 -10:18/0 = 0 -11:18/0 = 0 -12:18/0 = 0 -13:18/0 = 0 -14:18/0 = 0 -15:18/0 = 0 -16:18/0 = 0 -17:18/0 = 0 -18:18/0 = 0 -19:18/0 = 0 -20:18/0 = 0 -21:18/0 = 0 -22:18/0 = 0 -23:18/0 = 0 -24:18/0 = 0 -25:18/0 = 0 -26:18/0 = 0 -27:18/0 = 0 -28:18/0 = 0 -29:18/0 = 0 -30:18/0 = 0 -31:18/0 = 0 -0:19/0 = 0 -1:19/0 = 0 -2:19/0 = 0 -3:19/0 = 0 -4:19/0 = 0 -5:19/0 = 0 -6:19/0 = 0 -7:19/0 = 0 -8:19/0 = 0 -9:19/0 = 0 -10:19/0 = 0 -11:19/0 = 0 -12:19/0 = 0 -13:19/0 = 0 -14:19/0 = 0 -15:19/0 = 0 -16:19/0 = 0 -17:19/0 = 0 -18:19/0 = 0 -19:19/0 = 0 -20:19/0 = 0 -21:19/0 = 0 -22:19/0 = 0 -23:19/0 = 0 -24:19/0 = 0 -25:19/0 = 0 -26:19/0 = 0 -27:19/0 = 0 -28:19/0 = 0 -29:19/0 = 0 -30:19/0 = 0 -31:19/0 = 0 -0:20/0 = 0 -1:20/0 = 0 -2:20/0 = 0 -3:20/0 = 0 -4:20/0 = 0 -5:20/0 = 0 -6:20/0 = 0 -7:20/0 = 0 -8:20/0 = 0 -9:20/0 = 0 -10:20/0 = 0 -11:20/0 = 0 -12:20/0 = 0 -13:20/0 = 0 -14:20/0 = 0 -15:20/0 = 0 -16:20/0 = 0 -17:20/0 = 0 -18:20/0 = 0 -19:20/0 = 0 -20:20/0 = 0 -21:20/0 = 0 -22:20/0 = 0 -23:20/0 = 0 -24:20/0 = 0 -25:20/0 = 0 -26:20/0 = 0 -27:20/0 = 0 -28:20/0 = 0 -29:20/0 = 0 -30:20/0 = 0 -31:20/0 = 0 -0:21/0 = 0 -1:21/0 = 0 -2:21/0 = 0 -3:21/0 = 0 -4:21/0 = 0 -5:21/0 = 0 -6:21/0 = 0 -7:21/0 = 0 -8:21/0 = 0 -9:21/0 = 0 -10:21/0 = 0 -11:21/0 = 0 -12:21/0 = 0 -13:21/0 = 0 -14:21/0 = 0 -15:21/0 = 0 -16:21/0 = 0 -17:21/0 = 0 -18:21/0 = 0 -19:21/0 = 0 -20:21/0 = 0 -21:21/0 = 0 -22:21/0 = 0 -23:21/0 = 0 -24:21/0 = 0 -25:21/0 = 0 -26:21/0 = 0 -27:21/0 = 0 -28:21/0 = 0 -29:21/0 = 0 -30:21/0 = 0 -31:21/0 = 0 -0:22/0 = 0 -1:22/0 = 0 -2:22/0 = 0 -3:22/0 = 0 -4:22/0 = 0 -5:22/0 = 0 -6:22/0 = 0 -7:22/0 = 0 -8:22/0 = 0 -9:22/0 = 0 -10:22/0 = 0 -11:22/0 = 0 -12:22/0 = 0 -13:22/0 = 0 -14:22/0 = 0 -15:22/0 = 0 -16:22/0 = 0 -17:22/0 = 0 -18:22/0 = 0 -19:22/0 = 0 -20:22/0 = 0 -21:22/0 = 0 -22:22/0 = 0 -23:22/0 = 0 -24:22/0 = 0 -25:22/0 = 0 -26:22/0 = 0 -27:22/0 = 0 -28:22/0 = 0 -29:22/0 = 0 -30:22/0 = 0 -31:22/0 = 0 -0:23/0 = 0 -1:23/0 = 0 -2:23/0 = 0 -3:23/0 = 0 -4:23/0 = 0 -5:23/0 = 0 -6:23/0 = 0 -7:23/0 = 0 -8:23/0 = 0 -9:23/0 = 0 -10:23/0 = 0 -11:23/0 = 0 -12:23/0 = 0 -13:23/0 = 0 -14:23/0 = 0 -15:23/0 = 0 -16:23/0 = 0 -17:23/0 = 0 -18:23/0 = 0 -19:23/0 = 0 -20:23/0 = 0 -21:23/0 = 0 -22:23/0 = 0 -23:23/0 = 0 -24:23/0 = 0 -25:23/0 = 0 -26:23/0 = 0 -27:23/0 = 0 -28:23/0 = 0 -29:23/0 = 0 -30:23/0 = 0 -31:23/0 = 0 -0:24/0 = 0 -1:24/0 = 0 -2:24/0 = 0 -3:24/0 = 0 -4:24/0 = 0 -5:24/0 = 0 -6:24/0 = 0 -7:24/0 = 0 -8:24/0 = 0 -9:24/0 = 0 -10:24/0 = 0 -11:24/0 = 0 -12:24/0 = 0 -13:24/0 = 0 -14:24/0 = 0 -15:24/0 = 0 -16:24/0 = 0 -17:24/0 = 0 -18:24/0 = 0 -19:24/0 = 0 -20:24/0 = 0 -21:24/0 = 0 -22:24/0 = 0 -23:24/0 = 0 -24:24/0 = 0 -25:24/0 = 0 -26:24/0 = 0 -27:24/0 = 0 -28:24/0 = 0 -29:24/0 = 0 -30:24/0 = 0 -31:24/0 = 0 -0:25/0 = 0 -1:25/0 = 0 -2:25/0 = 0 -3:25/0 = 0 -4:25/0 = 0 -5:25/0 = 0 -6:25/0 = 0 -7:25/0 = 0 -8:25/0 = 0 -9:25/0 = 0 -10:25/0 = 0 -11:25/0 = 0 -12:25/0 = 0 -13:25/0 = 0 -14:25/0 = 0 -15:25/0 = 0 -16:25/0 = 0 -17:25/0 = 0 -18:25/0 = 0 -19:25/0 = 0 -20:25/0 = 0 -21:25/0 = 0 -22:25/0 = 0 -23:25/0 = 0 -24:25/0 = 0 -25:25/0 = 0 -26:25/0 = 0 -27:25/0 = 0 -28:25/0 = 0 -29:25/0 = 0 -30:25/0 = 0 -31:25/0 = 0 -0:26/0 = 0 -1:26/0 = 0 -2:26/0 = 0 -3:26/0 = 0 -4:26/0 = 0 -5:26/0 = 0 -6:26/0 = 0 -7:26/0 = 0 -8:26/0 = 0 -9:26/0 = 0 -10:26/0 = 0 -11:26/0 = 0 -12:26/0 = 0 -13:26/0 = 0 -14:26/0 = 0 -15:26/0 = 0 -16:26/0 = 0 -17:26/0 = 0 -18:26/0 = 0 -19:26/0 = 0 -20:26/0 = 0 -21:26/0 = 0 -22:26/0 = 0 -23:26/0 = 0 -24:26/0 = 0 -25:26/0 = 0 -26:26/0 = 0 -27:26/0 = 0 -28:26/0 = 0 -29:26/0 = 0 -30:26/0 = 0 -31:26/0 = 0 -0:27/0 = 0 -1:27/0 = 0 -2:27/0 = 0 -3:27/0 = 0 -4:27/0 = 0 -5:27/0 = 0 -6:27/0 = 0 -7:27/0 = 0 -8:27/0 = 0 -9:27/0 = 0 -10:27/0 = 0 -11:27/0 = 0 -12:27/0 = 0 -13:27/0 = 0 -14:27/0 = 0 -15:27/0 = 0 -16:27/0 = 0 -17:27/0 = 0 -18:27/0 = 0 -19:27/0 = 0 -20:27/0 = 0 -21:27/0 = 0 -22:27/0 = 0 -23:27/0 = 0 -24:27/0 = 0 -25:27/0 = 0 -26:27/0 = 0 -27:27/0 = 0 -28:27/0 = 0 -29:27/0 = 0 -30:27/0 = 0 -31:27/0 = 0 -0:28/0 = 0 -1:28/0 = 0 -2:28/0 = 0 -3:28/0 = 0 -4:28/0 = 0 -5:28/0 = 0 -6:28/0 = 0 -7:28/0 = 0 -8:28/0 = 0 -9:28/0 = 0 -10:28/0 = 0 -11:28/0 = 0 -12:28/0 = 0 -13:28/0 = 0 -14:28/0 = 0 -15:28/0 = 0 -16:28/0 = 0 -17:28/0 = 0 -18:28/0 = 0 -19:28/0 = 0 -20:28/0 = 0 -21:28/0 = 0 -22:28/0 = 0 -23:28/0 = 0 -24:28/0 = 0 -25:28/0 = 0 -26:28/0 = 0 -27:28/0 = 0 -28:28/0 = 0 -29:28/0 = 0 -30:28/0 = 0 -31:28/0 = 0 -0:29/0 = 0 -1:29/0 = 0 -2:29/0 = 0 -3:29/0 = 0 -4:29/0 = 0 -5:29/0 = 0 -6:29/0 = 0 -7:29/0 = 0 -8:29/0 = 0 -9:29/0 = 0 -10:29/0 = 0 -11:29/0 = 0 -12:29/0 = 0 -13:29/0 = 0 -14:29/0 = 0 -15:29/0 = 0 -16:29/0 = 0 -17:29/0 = 0 -18:29/0 = 0 -19:29/0 = 0 -20:29/0 = 0 -21:29/0 = 0 -22:29/0 = 0 -23:29/0 = 0 -24:29/0 = 0 -25:29/0 = 0 -26:29/0 = 0 -27:29/0 = 0 -28:29/0 = 0 -29:29/0 = 0 -30:29/0 = 0 -31:29/0 = 0 - -[sub_resource type="TileSet" id="TileSet_t3bbo"] -terrain_set_0/mode = 0 -sources/1 = SubResource("TileSetAtlasSource_s55i2") -sources/0 = SubResource("TileSetAtlasSource_3q7ue") -sources/2 = SubResource("TileSetAtlasSource_hwjm3") +[ext_resource type="Script" path="res://scripts/EntityPlacer.gd" id="5_8jju5"] [node name="Main" type="Node"] script = ExtResource("1_ysxum") -[node name="World" type="TileMap" parent="."] -tile_set = SubResource("TileSet_t3bbo") -format = 2 -layer_0/name = "Terrain" -layer_1/name = "Buildings" -layer_1/enabled = true -layer_1/modulate = Color(1, 1, 1, 1) -layer_1/y_sort_enabled = false -layer_1/y_sort_origin = 0 -layer_1/z_index = 0 -layer_1/tile_data = PackedInt32Array() -script = ExtResource("3_6q5ju") +[node name="TileMapGenerator" type="CanvasLayer" parent="."] +script = ExtResource("2_cbjcm") -[node name="CameraZoom2D" parent="World" instance=ExtResource("4_rx82t")] +[node name="EntityPlacer" type="Control" parent="."] +layout_mode = 3 +anchors_preset = 0 +offset_right = 40.0 +offset_bottom = 40.0 +script = ExtResource("5_8jju5") + +[node name="CameraZoom2D" parent="." instance=ExtResource("4_rx82t")] position = Vector2(960, 536) limit_left = -40000 limit_top = -40000 @@ -1535,8 +88,7 @@ offset_right = 936.0 offset_bottom = 256.0 horizontal_alignment = 2 -[connection signal="set_camera_position" from="." to="World/CameraZoom2D" method="_on_set_camera_position"] -[connection signal="button_pressed" from="UILayer/Control" to="World" method="_on_control_button_pressed"] +[connection signal="set_camera_position" from="." to="CameraZoom2D" method="_on_set_camera_position"] [connection signal="pressed" from="UILayer/Control/ConstructionPanel/button_residental" to="UILayer/Control" method="_on_button_residental_pressed"] [connection signal="pressed" from="UILayer/Control/ConstructionPanel/button_commercial" to="UILayer/Control" method="_on_button_commercial_pressed"] [connection signal="pressed" from="UILayer/Control/ConstructionPanel/button_industrial" to="UILayer/Control" method="_on_button_industrial_pressed"] diff --git a/scripts/Control.gd b/scripts/Control.gd index a125fb3..ab6a5db 100644 --- a/scripts/Control.gd +++ b/scripts/Control.gd @@ -22,7 +22,11 @@ func _ready(): # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(_delta): - debug_info.set_text(str(get_viewport().get_mouse_position()) +"\n" + "FPS " + str(Engine.get_frames_per_second())) + debug_info.set_text( + str(get_viewport().get_mouse_position()) +"\n" + + "FPS " + str(Engine.get_frames_per_second()) + "\n" + + "Zoom lvl: " + str(Globals.CAMERA_ZOOM_LEVEL) + ) # defines construction toolbar buttons func create_buttons(): diff --git a/scripts/World.gd b/scripts/EntityPlacer.gd similarity index 59% rename from scripts/World.gd rename to scripts/EntityPlacer.gd index cec4a31..d6a1275 100644 --- a/scripts/World.gd +++ b/scripts/EntityPlacer.gd @@ -1,22 +1,11 @@ -class_name World -extends TileMap +class_name EntityPlacer +extends Control var has_placeable_building: bool = false var building var building_type: String var scene -func _init(): - Globals.world_map = self - -# Called when the node enters the scene tree for the first time. -func _ready(): - pass - -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(_delta): - pass - func get_building_properties() -> Array: var tileset_id = 0 # default value var tilemap_tile_coords: Vector2i @@ -62,40 +51,40 @@ func _on_control_button_pressed(type): scene = load(Globals.SCENE_PATH + "Building.tscn") building = scene.instantiate() #building.set_cell(0, Vector2i(0,0), building_properties[0], building_properties[1], 0) - add_child(building) + #add_child(building) has_placeable_building = true -func _input(event): - # place the building - if event.is_action_pressed("place_building") and has_placeable_building: - has_placeable_building = false - place_building_to_map() - - # cancel placement - if event.is_action_pressed("cancel"): - if has_placeable_building: - pass +#func _input(event): +# # place the building +# if event.is_action_pressed("place_building") and has_placeable_building: +# has_placeable_building = false +# place_building_to_map() +# +# # cancel placement +# if event.is_action_pressed("cancel"): +# if has_placeable_building: +# pass func calculate_grid_coordinates(map_position: Vector2) -> Vector2: return (map_position).floor() -func place_building_to_map(): - var building_properties = get_building_properties() - var tile_on_mouse = local_to_map(get_global_mouse_position()) - - if !Globals.are_coords_valid( - tile_on_mouse.y, - Vector2i(0, Globals.map_image_size.y), - Globals.ERROR_TILE_Y_COORDS_OUT_OF_BOUNDS - ): - return false - elif !Globals.are_coords_valid( - tile_on_mouse.x, - Vector2i(0, Globals.map_image_size.x), - Globals.ERROR_TILE_X_COORDS_OUT_OF_BOUNDS - ): - return false +#func place_building_to_map(): +# var building_properties = get_building_properties() +# #var tile_on_mouse = local_to_map(get_global_mouse_position()) +# +# if !Globals.are_coords_valid( +# tile_on_mouse.y, +# Vector2i(0, Globals.map_image_size.y), +# Globals.ERROR_TILE_Y_COORDS_OUT_OF_BOUNDS +# ): +# return false +# elif !Globals.are_coords_valid( +# tile_on_mouse.x, +# Vector2i(0, Globals.map_image_size.x), +# Globals.ERROR_TILE_X_COORDS_OUT_OF_BOUNDS +# ): +# return false - set_cell(Globals.LAYER_BUILDINGS, tile_on_mouse, building_properties[0], building_properties[1], 0) +# set_cell(Globals.LAYER_BUILDINGS, tile_on_mouse, building_properties[0], building_properties[1], 0) diff --git a/scripts/Globals.gd b/scripts/Globals.gd index dd5fd1b..78fbb50 100644 --- a/scripts/Globals.gd +++ b/scripts/Globals.gd @@ -20,8 +20,17 @@ func are_coords_valid(value:int, bounds:Vector2i, errmsg:String) -> bool: func choose_randomly(list_of_entries): return list_of_entries[randi() % list_of_entries.size()] -var world_map: TileMap -var map_image_size:Vector2i +# map size is based on input image x*y pixel size +var map_size:Vector2i + +# store terrain type (water, land, forest etc. for every map cell) +var map_terrain_data:Array[Array] = [[]] + +# preprocess and store exact tile for every map cell to speed up setting tiles +var map_tile_data:Array[Array] = [[]] + +# current camera zoom level +var CAMERA_ZOOM_LEVEL: float = 1.0 # FILE PATHS const SCENE_PATH:String = "res://scenes/" @@ -52,8 +61,6 @@ const TYPE_ROADS:String = "roads" const TYPE_DEMOLISH:String = "demolish" # camera movement settings -var CAMERA_ZOOM_LEVEL: float = 1.0 - const CAMERA_MIN_ZOOM_LEVEL: float = 0.1 const CAMERA_MAX_ZOOM_LEVEL: float = 2.0 const CAMERA_ZOOM_FACTOR: float = 0.1 @@ -65,10 +72,10 @@ const GROUND_TILE_COLOR_IN_MAP_FILE: Color = Color(0,0,0,1) const WATER_TILE_COLOR_IN_MAP_FILE: Color = Color(1,1,1,1) # min and max sizes for a map so the map won't be unreasonably small or large -const MAP_MIN_HEIGHT:int = 100 -const MAP_MAX_HEIGHT:int = 1000 -const MAP_MIN_WIDTH:int = 100 -const MAP_MAX_WIDTH:int = 1000 +const MAP_MIN_HEIGHT:int = 128 +const MAP_MAX_HEIGHT:int = 4096 +const MAP_MIN_WIDTH:int = 128 +const MAP_MAX_WIDTH:int = 4096 # tile size const TILE_SIZE_X:int = 16 diff --git a/scripts/Main.gd b/scripts/Main.gd index 13241f7..49b2b3f 100644 --- a/scripts/Main.gd +++ b/scripts/Main.gd @@ -12,10 +12,15 @@ extends Node signal set_camera_position(pos:Vector2) # The idea is for the user to be able to choose the map from GUI later -#var map_filename: String = "res://maps/tampere_10x10km_1000px.png" -var map_filename:String = "res://maps/tampere_200px_crop.png" -var _world := World.new() -var _world_generator := WorldGeneration.new() +var map_filenames:Array = [ + "res://maps/tampere_10x10km_1000px.png", + "res://maps/tampere_10x10km_1024px.png", + "res://maps/varkaus_256x256px_test.png" + ] +var map_filename:String = map_filenames[2] +var _world_generator:WorldGenerator +var _tilemap_generator:TileMapGenerator + func _init(): # DisplayServer.window_set_size( @@ -26,20 +31,27 @@ func _init(): # Called when the node enters the scene tree for the first time. func _ready(): - if !_world: - push_error(Globals.ERROR_MAKING_WORLD_INSTANCE) - quit_game() - + # create a new world and worldgenerator + _world_generator = WorldGenerator.new() + _tilemap_generator = TileMapGenerator.new() + # generate terrain. quit game if generation fails. if !_world_generator.generate_world(map_filename): push_error(Globals.ERROR_WHILE_GENERATING_MAP) - quit_game() + quit_game() + + if !_tilemap_generator: + push_error(Globals.ERROR_MAKING_WORLD_INSTANCE) + quit_game() + + _tilemap_generator.start() + _tilemap_generator.test_func() # center camera to world map emit_signal( "set_camera_position", - Vector2(Globals.map_image_size.x / 2.0 * Globals.TILE_SIZE_X, - Globals.map_image_size.y / 2.0 * Globals.TILE_SIZE_Y) + Vector2(Globals.map_size.x / 2.0 * Globals.TILE_SIZE_X, + Globals.map_size.y / 2.0 * Globals.TILE_SIZE_Y) ) # Called every frame. 'delta' is the elapsed time since the previous frame. diff --git a/scripts/TileMapGenerator.gd b/scripts/TileMapGenerator.gd new file mode 100644 index 0000000..2e3bbbc --- /dev/null +++ b/scripts/TileMapGenerator.gd @@ -0,0 +1,57 @@ +class_name TileMapGenerator +extends CanvasLayer + +# one tilemap is one chunk +# map consists of many chunks +# chunks are loaded to view when needed +# chunks are deleted after they are no longer needed (in view) + +# This is done to speed up game loading and avoiding setting one large tilemap in one go +# which is extremely slow in godot 4.0, 4096x4096 takes minutes to fill with set_cell() commands + +const CHUNK_SIZE = Vector2i(128,128) + +var map_tiles:Array[Array] = [[]] + +func start() -> void: + # Initialize the map tile array with enough chunks to cover the whole map + + var ms:int = Globals.map_size.y/CHUNK_SIZE.y + map_tiles.resize(2) + print("map tiles size y: ", map_tiles.size()) + + for y in ms: + map_tiles[y].resize(2) + print("map tiles size x: ", map_tiles[y].size()) + for x in ms: + map_tiles[y][x] = TileMap.new() + +func test_func(): + self.set_chunk_tiles(Vector2i(1,0)) + #self.map_tiles[0][1].visible() + print(map_tiles[0][1]) + +func clear_chunk_tiles(chunk_pos:Vector2i) -> void: + map_tiles[chunk_pos.y][chunk_pos.x].clear() + +func set_chunk_tiles(chunk_pos:Vector2i) -> void: + # Set an invidiual chunk's tiles based on map terrain data + + # Try to load the world tilemap where we place the tiles + if (map_tiles[chunk_pos.y][chunk_pos.x] == null): + var errmsg = Globals.ERROR_TILEMAP_NODE_MISSING + push_error(errmsg % str(chunk_pos)) + #return false + + for y in CHUNK_SIZE.y: + for x in CHUNK_SIZE.x: + var tile_data: Array = Globals.map_tile_data[chunk_pos.y*CHUNK_SIZE.y][chunk_pos.x*CHUNK_SIZE.x] + + # layer | tile coords at tilemap | tilemap id | coords of the tile at tileset | alternative tile + map_tiles[chunk_pos.y][chunk_pos.x].set_cell( + Globals.LAYER_TERRAIN, + Vector2i(x, y), + 2, + tile_data[0], + tile_data[1] + ) diff --git a/scripts/WorldGeneration.gd b/scripts/WorldGenerator.gd similarity index 62% rename from scripts/WorldGeneration.gd rename to scripts/WorldGenerator.gd index fb27efd..6327970 100644 --- a/scripts/WorldGeneration.gd +++ b/scripts/WorldGenerator.gd @@ -1,8 +1,8 @@ -class_name WorldGeneration +class_name WorldGenerator extends RefCounted var image:Image = Image.new() -var map_tile_data:Array[Array] = [[]] # store map tile info to a 2d array + var directions:Array = [ Vector2i(0,1), # south Vector2i(1,0), # east @@ -10,15 +10,15 @@ var directions:Array = [ Vector2i(-1,0) # west ] -func choose_tile(tile:Vector2i, selected, surrounding) -> void: +func choose_tile(tile:Vector2i, selected, surrounding) -> Array: var surrounding_tiles:Array = [] # determine which directions have land around the tile for dir in directions: # avoid index out of bounds - if (tile.y+dir.y >= Globals.map_image_size.y) or (tile.x+dir.x >= Globals.map_image_size.x): + if (tile.y+dir.y >= Globals.map_size.y) or (tile.x+dir.x >= Globals.map_size.x): surrounding_tiles.append(surrounding) - elif map_tile_data[tile.y+dir.y][tile.x+dir.x] == surrounding: + elif Globals.map_terrain_data[tile.y+dir.y][tile.x+dir.x] == surrounding: surrounding_tiles.append(surrounding) else: surrounding_tiles.append(selected) @@ -33,14 +33,10 @@ func choose_tile(tile:Vector2i, selected, surrounding) -> void: else: tile_coords = selected_tile[0] - # layer | position coords | tilemap id | coords of the tile at tilemap | alternative tile - Globals.world_map.set_cell( - Globals.LAYER_TERRAIN, - Vector2i(tile.x, tile.y), - 2, + return [ tile_coords, 0 if selected_tile else Globals.choose_randomly([0,1,2,3]) - ) + ] # Generates biomes, like forest and bog func generate_biomes() -> void: @@ -56,25 +52,25 @@ func generate_biomes() -> void: var water_next_to_tile:bool = false - for y in map_tile_data.size(): - for x in map_tile_data[y].size(): + for y in Globals.map_terrain_data.size(): + for x in Globals.map_terrain_data[y].size(): # replace non-water with biomes - if map_tile_data[y][x] > 0: + if Globals.map_terrain_data[y][x] > 0: water_next_to_tile = false # don't put forest next to water for dir in directions: - if (y+dir.y >= Globals.map_image_size.y) or (x+dir.x >= Globals.map_image_size.x): + if (y+dir.y >= Globals.map_size.y) or (x+dir.x >= Globals.map_size.x): continue - if map_tile_data[y+dir.y][x+dir.x] == Globals.TILE_WATER: + if Globals.map_terrain_data[y+dir.y][x+dir.x] == Globals.TILE_WATER: water_next_to_tile = true # if there's no water next to a land tile, it can be replaced with forest if !water_next_to_tile: var noise_sample = fnl.get_noise_2d(x,y) if noise_sample < 0.1: - map_tile_data[y][x] = Globals.TILE_FOREST + Globals.map_terrain_data[y][x] = Globals.TILE_FOREST # can add other tresholds here for other biomes func generate_world(filename) -> bool: @@ -86,58 +82,67 @@ func generate_world(filename) -> bool: return false # Check if image is too small or too large - Globals.map_image_size = image.get_size() + Globals.map_size = image.get_size() if !validate_mapgen_params(): return false + var start = Time.get_ticks_usec() read_image_pixel_data() + var end = Time.get_ticks_usec() + print("read image data ", (end-start)/1000.0, "ms") + + start = Time.get_ticks_usec() smooth_land_features(Globals.TILE_WATER) # smooth water + end = Time.get_ticks_usec() + print("smooth water ", (end-start)/1000.0, "ms") + + start = Time.get_ticks_usec() generate_biomes() + end = Time.get_ticks_usec() + print("generate biomes ", (end-start)/1000.0, "ms") + + start = Time.get_ticks_usec() smooth_land_features(Globals.TILE_FOREST) # smooth out forest - set_tilemap_tiles() + end = Time.get_ticks_usec() + print("smooth forest ", (end-start)/1000.0, "ms") + + start = Time.get_ticks_usec() + set_tilemap_tiles() + end = Time.get_ticks_usec() + print("set tiles ", (end-start)/1000.0, "ms") return true func read_image_pixel_data(): # initialize the array to have enough rows - map_tile_data.resize(Globals.map_image_size.y) + Globals.map_terrain_data.resize(Globals.map_size.y) + Globals.map_tile_data.resize(Globals.map_size.y) - for y in Globals.map_image_size.y: + for y in Globals.map_size.y: #initialize the row to have enough columns - map_tile_data[y].resize(Globals.map_image_size.y) + Globals.map_terrain_data[y].resize(Globals.map_size.y) + Globals.map_tile_data[y].resize(Globals.map_size.y) + - for x in Globals.map_image_size.x: + for x in Globals.map_size.x: if image.get_pixel(x, y) == Globals.WATER_TILE_COLOR_IN_MAP_FILE: - map_tile_data[y][x] = Globals.TILE_WATER + Globals.map_terrain_data[y][x] = Globals.TILE_WATER else: - map_tile_data[y][x] = Globals.TILE_TERRAIN + Globals.map_terrain_data[y][x] = Globals.TILE_TERRAIN func set_tilemap_tiles() -> void: - for y in map_tile_data.size(): - for x in map_tile_data[y].size(): + for y in Globals.map_terrain_data.size(): + for x in Globals.map_terrain_data[y].size(): # layer | position coords | tilemap id | coords of the tile at tilemap | alternative tile - match map_tile_data[y][x]: + match Globals.map_terrain_data[y][x]: Globals.TILE_WATER: # water or shoreline - choose_tile(Vector2i(x, y), Globals.TILE_WATER, Globals.TILE_TERRAIN) + Globals.map_tile_data[y][x] = choose_tile(Vector2i(x, y), Globals.TILE_WATER, Globals.TILE_TERRAIN) Globals.TILE_TERRAIN: #terrain or forest edge -# Globals.world_map.set_cell( -# Globals.LAYER_TERRAIN, -# Vector2i(x, y), -# 2, -# Vector2i(0,0), -# Globals.choose_randomly([0,1,2,3]) -# ) - choose_tile(Vector2i(x,y), Globals.TILE_TERRAIN, Globals.TILE_FOREST) + Globals.map_tile_data[y][x] = choose_tile(Vector2i(x,y), Globals.TILE_TERRAIN, Globals.TILE_FOREST) Globals.TILE_FOREST: - Globals.world_map.set_cell( - Globals.LAYER_TERRAIN, - Vector2i(x, y), - 2, - Vector2i(5,1), - Globals.choose_randomly([0,1,2,3]) - ) + Globals.map_tile_data[y][x] = [Vector2i(5,1), Globals.choose_randomly([0,1,2,3])] _: #default pass @@ -147,9 +152,9 @@ func set_tilemap_tiles() -> void: # Do it recursively with limit of n recursions! func smooth_land_features(tile_type:int) -> void: # TODO for testing avoid map borders to make it simpler to implement - for y in range(1, Globals.map_image_size.y-1): - for x in range(1, Globals.map_image_size.x-1): - if map_tile_data[y][x] != tile_type: + for y in range(1, Globals.map_size.y-1): + for x in range(1, Globals.map_size.x-1): + if Globals.map_terrain_data[y][x] != tile_type: continue match tile_type: @@ -173,26 +178,26 @@ func smooth_forest_recursively(pos:Vector2i, selected:int, comp:int) -> void: # determine which directions have land around the tile for dir in directions: - if map_tile_data[pos.y+dir.y][pos.x+dir.x] == comp: + if Globals.map_terrain_data[pos.y+dir.y][pos.x+dir.x] == comp: surrounding_tiles.append(comp) - elif map_tile_data[pos.y+dir.y][pos.x+dir.x] == selected: + elif Globals.map_terrain_data[pos.y+dir.y][pos.x+dir.x] == selected: surrounding_tiles.append(selected) match surrounding_tiles: [1,1,1,2]: #west - map_tile_data[pos.y][pos.x] = comp + Globals.map_terrain_data[pos.y][pos.x] = comp pos.x -= 1 [1,1,2,1]: #north - map_tile_data[pos.y][pos.x] = comp + Globals.map_terrain_data[pos.y][pos.x] = comp pos.y -= 1 [1,2,1,1]: #east - map_tile_data[pos.y][pos.x] = comp + Globals.map_terrain_data[pos.y][pos.x] = comp pos.x += 1 [2,1,1,1]: #south - map_tile_data[pos.y][pos.x] = comp + Globals.map_terrain_data[pos.y][pos.x] = comp pos.y += 1 [1,1,1,1]: # remove solo forests - map_tile_data[pos.y][pos.x] = comp + Globals.map_terrain_data[pos.y][pos.x] = comp return _: return @@ -205,46 +210,40 @@ func smooth_recursively(pos:Vector2i, selected:int, comp:int) -> void: # determine which directions have land around the tile for dir in directions: - if map_tile_data[pos.y+dir.y][pos.x+dir.x] == comp: + if Globals.map_terrain_data[pos.y+dir.y][pos.x+dir.x] == comp: surrounding_tiles.append(comp) - elif map_tile_data[pos.y+dir.y][pos.x+dir.x] == selected: + elif Globals.map_terrain_data[pos.y+dir.y][pos.x+dir.x] == selected: surrounding_tiles.append(selected) match surrounding_tiles: [1,1,1,0]: #west - map_tile_data[pos.y][pos.x] = comp + Globals.map_terrain_data[pos.y][pos.x] = comp pos.x -= 1 [1,1,0,1]: #north - map_tile_data[pos.y][pos.x] = comp + Globals.map_terrain_data[pos.y][pos.x] = comp pos.y -= 1 [1,0,1,1]: #east - map_tile_data[pos.y][pos.x] = comp + Globals.map_terrain_data[pos.y][pos.x] = comp pos.x += 1 [0,1,1,1]: #south - map_tile_data[pos.y][pos.x] = comp + Globals.map_terrain_data[pos.y][pos.x] = comp pos.y += 1 _: return smooth_recursively(pos, selected, comp) - + func validate_mapgen_params() -> bool: if !Globals.are_coords_valid( - Globals.map_image_size.y, + Globals.map_size.y, Vector2i(Globals.MAP_MIN_HEIGHT, Globals.MAP_MAX_HEIGHT), Globals.ERROR_IMAGE_HEIGHT_INCORRECT): return false elif !Globals.are_coords_valid( - Globals.map_image_size.x, + Globals.map_size.x, Vector2i(Globals.MAP_MIN_WIDTH, Globals.MAP_MAX_WIDTH), Globals.ERROR_IMAGE_WIDTH_INCORRECT): return false - # Try to load the world tilemap where we place the tiles - if (Globals.world_map == null): - var errmsg = Globals.ERROR_WORLD_TILEMAP_NODE_MISSING % Globals.WORLD_NODE - push_error(errmsg) - return false - return true