diff --git a/maps/tampere_256px.png b/maps/tampere_256px.png new file mode 100644 index 0000000..07ef149 Binary files /dev/null and b/maps/tampere_256px.png differ diff --git a/maps/tampere_256px.png.import b/maps/tampere_256px.png.import new file mode 100644 index 0000000..a1776ed --- /dev/null +++ b/maps/tampere_256px.png.import @@ -0,0 +1,14 @@ +[remap] + +importer="image" +type="Image" +uid="uid://yk3g53wyij7a" +path="res://.godot/imported/tampere_256px.png-38b633294ccf62346eb68368a3148123.image" + +[deps] + +source_file="res://maps/tampere_256px.png" +dest_files=["res://.godot/imported/tampere_256px.png-38b633294ccf62346eb68368a3148123.image"] + +[params] + diff --git a/project.godot b/project.godot index 5f5dd92..d65016d 100644 --- a/project.godot +++ b/project.godot @@ -25,8 +25,8 @@ gdscript/warnings/integer_division=0 [display] +window/size/viewport_width=1920 window/size/viewport_height=1080 -window/size/mode=2 window/size/resizable=false [input] diff --git a/scenes/Building.gd b/scenes/Building.gd index 5e5df28..689a198 100644 --- a/scenes/Building.gd +++ b/scenes/Building.gd @@ -1,4 +1,9 @@ +class_name Building extends TileMap +func _init(): + print("perse") + func _process(_delta): - position = get_viewport().get_mouse_position() + #position = get_viewport().get_mouse_position() + pass diff --git a/scenes/Building.tscn b/scenes/Building.tscn index e4d0e09..3a58c83 100644 --- a/scenes/Building.tscn +++ b/scenes/Building.tscn @@ -1,6 +1,8 @@ -[gd_scene load_steps=2 format=3 uid="uid://sqvd1ev6ubp"] +[gd_scene load_steps=3 format=3 uid="uid://sqvd1ev6ubp"] +[ext_resource type="Texture2D" uid="uid://cxn2fno1j7vf5" path="res://icon.svg" id="1_pe5ue"] [ext_resource type="Script" path="res://scenes/Building.gd" id="1_uqlnt"] [node name="Building" type="Sprite2D"] +texture = ExtResource("1_pe5ue") script = ExtResource("1_uqlnt") diff --git a/scenes/Chunk.gd b/scenes/Chunk.gd new file mode 100644 index 0000000..14d8c08 --- /dev/null +++ b/scenes/Chunk.gd @@ -0,0 +1,32 @@ +class_name Chunk +extends TileMap + +var x:int = -1 +var y:int = -1 + +# Called when the node enters the scene tree for the first time. +func _init(xpos:int, ypos:int): + self.x = xpos + self.y = ypos + +func _draw(): + draw_circle(Vector2(x,y), 25.0, Color(0,0,0)) + +func generate_chunk() -> void: + for row in Globals.CHUNK_SIZE: + for col in Globals.CHUNK_SIZE: + var tile_data: Array = Globals.map_tile_data[row+y*Globals.CHUNK_SIZE][col+x*Globals.CHUNK_SIZE] + #var msg = "%s %s %s" + #print(msg % [tile_data, row, col]) + + # layer | tile coords at tilemap | tilemap id | coords of the tile at tileset | alternative tile + self.set_cell( + Globals.LAYER_TERRAIN, + Vector2i(col, row), + 0, + tile_data[0], + tile_data[1] + ) + + + diff --git a/scenes/Chunk.tres b/scenes/Chunk.tres new file mode 100644 index 0000000..1337482 --- /dev/null +++ b/scenes/Chunk.tres @@ -0,0 +1,990 @@ +[gd_resource type="TileSet" load_steps=3 format=3 uid="uid://cxiva1a6jdae2"] + +[ext_resource type="Texture2D" uid="uid://djy5ne2grdc03" path="res://art/terrain/terrain.png" id="1_iaopt"] + +[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_lruho"] +texture = ExtResource("1_iaopt") +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 = 0 +5:0/0 = 0 +6:0/0 = 0 +7:0/0 = 0 +8:0/0 = 0 +9:0/0 = 0 +10:0/0 = 0 +11:0/0 = 0 +12:0/0 = 0 +13:0/0 = 0 +14:0/0 = 0 +15:0/0 = 0 +16:0/0 = 0 +17:0/0 = 0 +18:0/0 = 0 +19:0/0 = 0 +20:0/0 = 0 +21:0/0 = 0 +22:0/0 = 0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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 + +[resource] +sources/0 = SubResource("TileSetAtlasSource_lruho") diff --git a/scenes/Chunk.tscn b/scenes/Chunk.tscn new file mode 100644 index 0000000..040f771 --- /dev/null +++ b/scenes/Chunk.tscn @@ -0,0 +1,9 @@ +[gd_scene load_steps=3 format=3 uid="uid://54iw2fjk2oth"] + +[ext_resource type="Script" path="res://scenes/Chunk.gd" id="1_lawsj"] +[ext_resource type="TileSet" uid="uid://cxiva1a6jdae2" path="res://scenes/Chunk.tres" id="1_x70ay"] + +[node name="Chunk" type="TileMap"] +tile_set = ExtResource("1_x70ay") +format = 2 +script = ExtResource("1_lawsj") diff --git a/scenes/Main.tscn b/scenes/Main.tscn index 8dd1ab3..ed31510 100644 --- a/scenes/Main.tscn +++ b/scenes/Main.tscn @@ -1,16 +1,21 @@ -[gd_scene load_steps=6 format=3 uid="uid://ciperl36hv26g"] +[gd_scene load_steps=7 format=3 uid="uid://nfayf78xiuap"] [ext_resource type="Script" path="res://scripts/Main.gd" id="1_ysxum"] -[ext_resource type="Script" path="res://scripts/TileMapGenerator.gd" id="2_cbjcm"] +[ext_resource type="Script" path="res://scripts/ChunkHandler.gd" id="2_2e0t1"] [ext_resource type="Script" path="res://scripts/Control.gd" id="3_1t1c8"] +[ext_resource type="Texture2D" uid="uid://cxn2fno1j7vf5" path="res://icon.svg" id="3_c64oi"] [ext_resource type="PackedScene" uid="uid://2we3txfr812u" path="res://scenes/Camera_zoom_2d.tscn" id="4_rx82t"] [ext_resource type="Script" path="res://scripts/EntityPlacer.gd" id="5_8jju5"] -[node name="Main" type="Node"] +[node name="Main" type="Node2D"] script = ExtResource("1_ysxum") -[node name="TileMapGenerator" type="CanvasLayer" parent="."] -script = ExtResource("2_cbjcm") +[node name="ChunkHandler" type="Node2D" parent="."] +script = ExtResource("2_2e0t1") + +[node name="Sprite2D" type="Sprite2D" parent="ChunkHandler"] +position = Vector2(952, 536) +texture = ExtResource("3_c64oi") [node name="EntityPlacer" type="Control" parent="."] layout_mode = 3 diff --git a/scripts/CameraZoom2D.gd b/scripts/CameraZoom2D.gd index ae73441..22a148e 100644 --- a/scripts/CameraZoom2D.gd +++ b/scripts/CameraZoom2D.gd @@ -24,8 +24,9 @@ func _set_camera_zoom_level(value: float) -> void: Globals.CAMERA_ZOOM_DURATION ) -func _on_set_camera_position(pos: Vector2) -> void: - self.position = pos +func _on_set_camera_position(_pos: Vector2) -> void: + #self.position = pos + pass func _unhandled_input(event): if event.is_action_pressed("camera_zoom_in"): diff --git a/scripts/ChunkHandler.gd b/scripts/ChunkHandler.gd new file mode 100644 index 0000000..58fe173 --- /dev/null +++ b/scripts/ChunkHandler.gd @@ -0,0 +1,43 @@ +class_name ChunkHandler +extends Node2D + +# 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 + +var chunks:Dictionary = {} +var unused_chunks:Dictionary = {} + +func _ready(): + #thread = Thread.new() + pass + +#var map_tiles:Array[Array] = [[]] +# +#func start_handler() -> void: +# # Initialize the map tile array with enough chunks to cover the whole map +# map_tiles.resize(Globals.map_size/Globals.CHUNK_SIZE) +# for y in map_tiles.size(): +# map_tiles[y].resize(Globals.map_size/Globals.CHUNK_SIZE) +# for x in map_tiles.size(): +# map_tiles[y][x] = chunk.instantiate() + +func add_chunk(x:int, y:int): + var chunk = Chunk.new(x,y) + self.add_child(chunk) + + chunk.generate_chunk() + chunk.set_position(Vector2(x*Globals.CHUNK_SIZE,y*Globals.CHUNK_SIZE)) + chunk.set_visible(true) + + + + print("nodes in children: ", self.get_children()[0].get_used_cells(Globals.LAYER_TERRAIN).size()) + print("chunk visible in tree? : ", self.get_children()[0].is_visible_in_tree()) + print("handler visible? ", self.is_visible_in_tree()) + + #map_tiles[chunk_pos.y][chunk_pos.x].clear() diff --git a/scripts/Globals.gd b/scripts/Globals.gd index 78fbb50..6dc1938 100644 --- a/scripts/Globals.gd +++ b/scripts/Globals.gd @@ -3,6 +3,9 @@ extends Node +# world map chunk size +const CHUNK_SIZE:int = 128 + # tilemap tile types enum {TILE_WATER, TILE_TERRAIN, TILE_FOREST, TILE_BOG} @@ -21,7 +24,7 @@ func choose_randomly(list_of_entries): return list_of_entries[randi() % list_of_entries.size()] # map size is based on input image x*y pixel size -var map_size:Vector2i +var map_size:int # store terrain type (water, land, forest etc. for every map cell) var map_terrain_data:Array[Array] = [[]] diff --git a/scripts/Main.gd b/scripts/Main.gd index 49b2b3f..49e453c 100644 --- a/scripts/Main.gd +++ b/scripts/Main.gd @@ -7,7 +7,7 @@ # - etc. class_name Main -extends Node +extends Node2D signal set_camera_position(pos:Vector2) @@ -15,11 +15,12 @@ signal set_camera_position(pos:Vector2) var map_filenames:Array = [ "res://maps/tampere_10x10km_1000px.png", "res://maps/tampere_10x10km_1024px.png", - "res://maps/varkaus_256x256px_test.png" + "res://maps/varkaus_256x256px_test.png", + "res://maps/tampere_256px.png" ] -var map_filename:String = map_filenames[2] +var map_filename:String = map_filenames[3] var _world_generator:WorldGenerator -var _tilemap_generator:TileMapGenerator +var _chunk_handler:ChunkHandler func _init(): @@ -33,25 +34,27 @@ func _init(): func _ready(): # create a new world and worldgenerator _world_generator = WorldGenerator.new() - _tilemap_generator = TileMapGenerator.new() + _chunk_handler = ChunkHandler.new() + add_child(_chunk_handler) + + var result = _world_generator.generate_world(map_filename) - # generate terrain. quit game if generation fails. - if !_world_generator.generate_world(map_filename): - push_error(Globals.ERROR_WHILE_GENERATING_MAP) - quit_game() - - if !_tilemap_generator: - push_error(Globals.ERROR_MAKING_WORLD_INSTANCE) - quit_game() + if result: + #_chunk_handler.start_handler() + _chunk_handler.set_visible(true) + _chunk_handler.add_chunk(0, 0) + #_chunk_handler.show() + #_chunk_handler.set_visible(true) + print("main visible? ", is_visible_in_tree()) - _tilemap_generator.start() - _tilemap_generator.test_func() + else: + push_error("World generation failed :-(") # center camera to world map emit_signal( "set_camera_position", - Vector2(Globals.map_size.x / 2.0 * Globals.TILE_SIZE_X, - Globals.map_size.y / 2.0 * Globals.TILE_SIZE_Y) + Vector2(Globals.map_size / 2.0 * Globals.TILE_SIZE_X, + Globals.map_size / 2.0 * Globals.TILE_SIZE_Y) ) # Called every frame. 'delta' is the elapsed time since the previous frame. diff --git a/scripts/Snippets.gd b/scripts/Snippets.gd deleted file mode 100644 index 94aaa8a..0000000 --- a/scripts/Snippets.gd +++ /dev/null @@ -1,8 +0,0 @@ -extends Node - - -# Called when the node enters the scene tree for the first time. -func placeholder(): - # print all children of the node - for _i in self.get_children(): - print(_i diff --git a/scripts/TileMapGenerator.gd b/scripts/TileMapGenerator.gd deleted file mode 100644 index 2e3bbbc..0000000 --- a/scripts/TileMapGenerator.gd +++ /dev/null @@ -1,57 +0,0 @@ -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/WorldGenerator.gd b/scripts/WorldGenerator.gd index 6327970..2d33cf6 100644 --- a/scripts/WorldGenerator.gd +++ b/scripts/WorldGenerator.gd @@ -16,7 +16,7 @@ func choose_tile(tile:Vector2i, selected, surrounding) -> 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_size.y) or (tile.x+dir.x >= Globals.map_size.x): + if (tile.y+dir.y >= Globals.map_size) or (tile.x+dir.x >= Globals.map_size): surrounding_tiles.append(surrounding) elif Globals.map_terrain_data[tile.y+dir.y][tile.x+dir.x] == surrounding: surrounding_tiles.append(surrounding) @@ -61,7 +61,7 @@ func generate_biomes() -> void: # don't put forest next to water for dir in directions: - if (y+dir.y >= Globals.map_size.y) or (x+dir.x >= Globals.map_size.x): + if (y+dir.y >= Globals.map_size) or (x+dir.x >= Globals.map_size): continue if Globals.map_terrain_data[y+dir.y][x+dir.x] == Globals.TILE_WATER: water_next_to_tile = true @@ -74,6 +74,8 @@ func generate_biomes() -> void: # can add other tresholds here for other biomes func generate_world(filename) -> bool: + var image_size:Vector2i + # Try to load the image which we used to place water & ground to world map image = load(filename) if image == null: @@ -81,11 +83,18 @@ func generate_world(filename) -> bool: push_error(errmsg % filename) return false - # Check if image is too small or too large - Globals.map_size = image.get_size() - if !validate_mapgen_params(): + if (image.get_size().x / image.get_size().y) != 1: + push_error("Error: image size was invalidin world generator") return false + + image_size = image.get_size() + Globals.map_size = image_size.x + if !validate_mapgen_params(): + push_error("Error: invalid mapgen size parameters in world generator") + return false + + print("Worldgen speed stats:") var start = Time.get_ticks_usec() read_image_pixel_data() var end = Time.get_ticks_usec() @@ -107,30 +116,30 @@ func generate_world(filename) -> bool: print("smooth forest ", (end-start)/1000.0, "ms") start = Time.get_ticks_usec() - set_tilemap_tiles() + select_tilemap_tiles() end = Time.get_ticks_usec() - print("set tiles ", (end-start)/1000.0, "ms") + print("select tiles ", (end-start)/1000.0, "ms") return true func read_image_pixel_data(): # initialize the array to have enough rows - Globals.map_terrain_data.resize(Globals.map_size.y) - Globals.map_tile_data.resize(Globals.map_size.y) + Globals.map_terrain_data.resize(Globals.map_size) + Globals.map_tile_data.resize(Globals.map_size) - for y in Globals.map_size.y: + for y in Globals.map_size: #initialize the row to have enough columns - Globals.map_terrain_data[y].resize(Globals.map_size.y) - Globals.map_tile_data[y].resize(Globals.map_size.y) + Globals.map_terrain_data[y].resize(Globals.map_size) + Globals.map_tile_data[y].resize(Globals.map_size) - for x in Globals.map_size.x: + for x in Globals.map_size: if image.get_pixel(x, y) == Globals.WATER_TILE_COLOR_IN_MAP_FILE: Globals.map_terrain_data[y][x] = Globals.TILE_WATER else: Globals.map_terrain_data[y][x] = Globals.TILE_TERRAIN -func set_tilemap_tiles() -> void: +func select_tilemap_tiles() -> void: 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 @@ -152,8 +161,8 @@ 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_size.y-1): - for x in range(1, Globals.map_size.x-1): + for y in range(1, Globals.map_size-1): + for x in range(1, Globals.map_size-1): if Globals.map_terrain_data[y][x] != tile_type: continue @@ -178,7 +187,10 @@ func smooth_forest_recursively(pos:Vector2i, selected:int, comp:int) -> void: # determine which directions have land around the tile for dir in directions: - if Globals.map_terrain_data[pos.y+dir.y][pos.x+dir.x] == comp: + # avoid out of bounds hack + if (pos.y+dir.y >= Globals.map_size) or (pos.x+dir.x >= Globals.map_size): + surrounding_tiles.append(comp) + elif Globals.map_terrain_data[pos.y+dir.y][pos.x+dir.x] == comp: surrounding_tiles.append(comp) elif Globals.map_terrain_data[pos.y+dir.y][pos.x+dir.x] == selected: surrounding_tiles.append(selected) @@ -210,7 +222,10 @@ func smooth_recursively(pos:Vector2i, selected:int, comp:int) -> void: # determine which directions have land around the tile for dir in directions: - if Globals.map_terrain_data[pos.y+dir.y][pos.x+dir.x] == comp: + # avoid out of bounds hack + if (pos.y+dir.y >= Globals.map_size) or (pos.x+dir.x >= Globals.map_size): + surrounding_tiles.append(comp) + elif Globals.map_terrain_data[pos.y+dir.y][pos.x+dir.x] == comp: surrounding_tiles.append(comp) elif Globals.map_terrain_data[pos.y+dir.y][pos.x+dir.x] == selected: surrounding_tiles.append(selected) @@ -235,13 +250,13 @@ func smooth_recursively(pos:Vector2i, selected:int, comp:int) -> void: func validate_mapgen_params() -> bool: if !Globals.are_coords_valid( - Globals.map_size.y, + Globals.map_size, Vector2i(Globals.MAP_MIN_HEIGHT, Globals.MAP_MAX_HEIGHT), Globals.ERROR_IMAGE_HEIGHT_INCORRECT): return false elif !Globals.are_coords_valid( - Globals.map_size.x, + Globals.map_size, Vector2i(Globals.MAP_MIN_WIDTH, Globals.MAP_MAX_WIDTH), Globals.ERROR_IMAGE_WIDTH_INCORRECT): return false