aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Polo <op@xglobe.in>2020-05-01 12:40:46 +0200
committerOmar Polo <op@xglobe.in>2020-05-01 12:40:46 +0200
commit0294f5a4b583af6f5e86b181cca96ed394208da5 (patch)
tree4edcaaa81a7128d2cf79ce61dd61da467a4aefe3
downloaddungeon-generator-0294f5a4b583af6f5e86b181cca96ed394208da5.tar.gz
dungeon-generator-0294f5a4b583af6f5e86b181cca96ed394208da5.tar.bz2
initial commit
-rw-r--r--.import/cave.png-ed16753e4f303f3628391e4f3e9d3793.md53
-rw-r--r--.import/cave.png-ed16753e4f303f3628391e4f3e9d3793.stexbin0 -> 587 bytes
-rw-r--r--.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md53
-rw-r--r--.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stexbin0 -> 3413 bytes
-rw-r--r--World.gd129
-rw-r--r--World.tscn155
-rw-r--r--cave.pngbin0 -> 1017 bytes
-rw-r--r--cave.png.import34
-rw-r--r--default_env.tres7
-rw-r--r--icon.pngbin0 -> 3305 bytes
-rw-r--r--icon.png.import34
-rw-r--r--project.godot38
12 files changed, 403 insertions, 0 deletions
diff --git a/.import/cave.png-ed16753e4f303f3628391e4f3e9d3793.md5 b/.import/cave.png-ed16753e4f303f3628391e4f3e9d3793.md5
new file mode 100644
index 0000000..4a6463c
--- /dev/null
+++ b/.import/cave.png-ed16753e4f303f3628391e4f3e9d3793.md5
@@ -0,0 +1,3 @@
+source_md5="a7c9085a59fc24e41c69c0a792956376"
+dest_md5="0df7cfc42c05a7cf8eea5b38bafcb6e1"
+
diff --git a/.import/cave.png-ed16753e4f303f3628391e4f3e9d3793.stex b/.import/cave.png-ed16753e4f303f3628391e4f3e9d3793.stex
new file mode 100644
index 0000000..f344f0a
--- /dev/null
+++ b/.import/cave.png-ed16753e4f303f3628391e4f3e9d3793.stex
Binary files differ
diff --git a/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 b/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5
new file mode 100644
index 0000000..7b61c3e
--- /dev/null
+++ b/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5
@@ -0,0 +1,3 @@
+source_md5="47313fa4c47a9963fddd764e1ec6e4a8"
+dest_md5="2ded9e7f9060e2b530aab678b135fc5b"
+
diff --git a/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex b/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex
new file mode 100644
index 0000000..3ca6461
--- /dev/null
+++ b/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex
Binary files differ
diff --git a/World.gd b/World.gd
new file mode 100644
index 0000000..a64b0bc
--- /dev/null
+++ b/World.gd
@@ -0,0 +1,129 @@
+extends Node2D
+
+enum Tiles { WALL, GROUND }
+
+export (int) var iterations := 20
+export (Vector2) var size := Vector2(60, 40)
+
+export (int) var death_limit := 3
+export (int) var born_limit := 4
+export (float) var chance_to_start_alive := 0.45
+
+onready var _tilemap : TileMap = $TileMap
+onready var _label : Label = $Progress
+
+
+func _ready() -> void:
+ pass
+
+
+func _process(delta: float) -> void:
+ if Input.is_action_just_pressed("quit"):
+ get_tree().quit()
+
+
+func _on_Button_pressed() -> void:
+ _tilemap.clear()
+ _generate_map()
+
+
+func _new_map() -> Array:
+ var map := []
+ map.resize(int(size.x))
+ for x in size.x:
+ map[x] = []
+ map[x].resize(int(size.y))
+ return map
+
+
+func _copy_map(from : Array, to : Array) -> void:
+ for x in from.size():
+ for y in from[x].size():
+ to[x][y] = from[x][y]
+
+
+func _count_alive_neighborurs(map : Array, x : int, y : int) -> int:
+ var count := 0
+
+ for i in range(-1, 2):
+ for j in range(-1, 2):
+ var nx := x+i
+ var ny := y+j
+
+ if i == 0 and j == 0:
+ continue
+
+ if nx < 0 or ny < 0 or nx >= size.x or ny >= size.y:
+ count += 1
+ elif map[nx][ny] == true:
+ count += 1
+
+ return count
+
+
+func _simulate_step(oldmap : Array, newmap : Array) -> Array:
+ for x in oldmap.size():
+ for y in oldmap[x].size():
+ var neighbours := _count_alive_neighborurs(oldmap, x, y)
+
+ if oldmap[x][y] == true:
+ if neighbours < death_limit:
+ newmap[x][y] = false
+ else:
+ newmap[x][y] = true
+ else:
+ if neighbours > born_limit:
+ newmap[x][y] = true
+ else:
+ newmap[x][y] = false
+
+ return [oldmap, newmap]
+
+
+func _initialize(map : Array):
+ for x in map.size():
+ for y in map[x].size():
+ map[x][y] = randf() < chance_to_start_alive
+
+
+func _generate_map():
+ var map := _new_map()
+ var tmp := _new_map()
+
+ _initialize(map)
+ _copy_map(map, tmp)
+
+ for i in iterations:
+ var r = _simulate_step(map, tmp)
+ map = r[0]
+ tmp = r[1]
+ _copy_map(tmp, map)
+ _draw_map(map)
+ _label.text = str(i+1) + "/" + str(iterations)
+ yield(get_tree().create_timer(0.1), "timeout")
+
+
+func _draw_map(map : Array):
+ for x in map.size():
+ for y in map[x].size():
+ _tilemap.set_cell(x, y, Tiles.GROUND if map[x][y] else Tiles.WALL)
+
+
+func _on_death_limit_value_changed(value: float) -> void:
+ $death_limit_label.text = "death_limit: " + str(int(value))
+ death_limit = value
+
+
+func _on_born_limit_value_changed(value: float) -> void:
+ $born_limit_label.text = "born_limit: " + str(int(value))
+ born_limit = value
+
+
+func _on_initial_probability_value_changed(value: float) -> void:
+ $initial_probability_label.text = "initial_probability: " + str(value)
+ chance_to_start_alive = value
+
+
+func _on_iterations_value_changed(value: float) -> void:
+ $iterations_label.text = "iterations: " + str(int(value))
+ iterations = value
diff --git a/World.tscn b/World.tscn
new file mode 100644
index 0000000..ab54e59
--- /dev/null
+++ b/World.tscn
@@ -0,0 +1,155 @@
+[gd_scene load_steps=4 format=2]
+
+[ext_resource path="res://cave.png" type="Texture" id=1]
+[ext_resource path="res://World.gd" type="Script" id=2]
+
+[sub_resource type="TileSet" id=1]
+0/name = "wall"
+0/texture = ExtResource( 1 )
+0/tex_offset = Vector2( 0, 0 )
+0/modulate = Color( 1, 1, 1, 1 )
+0/region = Rect2( 0, 0, 16, 16 )
+0/tile_mode = 0
+0/occluder_offset = Vector2( 0, 0 )
+0/navigation_offset = Vector2( 0, 0 )
+0/shape_offset = Vector2( 0, 0 )
+0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
+0/shape_one_way = false
+0/shape_one_way_margin = 0.0
+0/shapes = [ ]
+0/z_index = 0
+1/name = "ground"
+1/texture = ExtResource( 1 )
+1/tex_offset = Vector2( 0, 0 )
+1/modulate = Color( 1, 1, 1, 1 )
+1/region = Rect2( 16, 0, 16, 16 )
+1/tile_mode = 0
+1/occluder_offset = Vector2( 0, 0 )
+1/navigation_offset = Vector2( 0, 0 )
+1/shape_offset = Vector2( 0, 0 )
+1/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
+1/shape_one_way = false
+1/shape_one_way_margin = 0.0
+1/shapes = [ ]
+1/z_index = 0
+
+[node name="World" type="Node2D"]
+script = ExtResource( 2 )
+
+[node name="Progress" type="Label" parent="."]
+margin_left = 16.0
+margin_top = 24.0
+margin_right = 69.0
+margin_bottom = 38.0
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="Button" type="Button" parent="."]
+margin_left = 79.0
+margin_top = 24.0
+margin_right = 188.0
+margin_bottom = 44.0
+text = "GENERATE!"
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="TileMap" type="TileMap" parent="."]
+position = Vector2( 40, 70 )
+tile_set = SubResource( 1 )
+cell_size = Vector2( 16, 16 )
+format = 1
+
+[node name="death_limit" type="HSlider" parent="."]
+margin_left = 304.0
+margin_top = 8.0
+margin_right = 406.0
+margin_bottom = 24.0
+min_value = 1.0
+max_value = 8.0
+value = 3.0
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="death_limit_label" type="Label" parent="."]
+margin_left = 208.0
+margin_top = 8.0
+margin_right = 297.0
+margin_bottom = 28.0
+text = "death_limit: 3"
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="born_limit" type="HSlider" parent="."]
+margin_left = 504.0
+margin_top = 8.0
+margin_right = 613.0
+margin_bottom = 24.0
+min_value = 1.0
+max_value = 8.0
+value = 4.0
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="born_limit_label" type="Label" parent="."]
+margin_left = 416.0
+margin_top = 8.0
+margin_right = 497.0
+margin_bottom = 22.0
+text = "born_limit: 2"
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="initial_probability" type="HSlider" parent="."]
+margin_left = 632.0
+margin_top = 40.0
+margin_right = 1008.0
+margin_bottom = 56.0
+min_value = 0.01
+max_value = 1.0
+step = 0.01
+value = 0.45
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="initial_probability_label" type="Label" parent="."]
+margin_left = 480.0
+margin_top = 40.0
+margin_right = 626.0
+margin_bottom = 54.0
+text = "initial_probability: 0.45"
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="iterations" type="HSlider" parent="."]
+margin_left = 304.0
+margin_top = 40.0
+margin_right = 464.0
+margin_bottom = 56.0
+min_value = 1.0
+value = 20.0
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="iterations_label" type="Label" parent="."]
+margin_left = 209.0
+margin_top = 42.0
+margin_right = 294.0
+margin_bottom = 56.0
+text = "iterations: 20"
+__meta__ = {
+"_edit_use_anchors_": false
+}
+[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"]
+[connection signal="value_changed" from="death_limit" to="." method="_on_death_limit_value_changed"]
+[connection signal="value_changed" from="born_limit" to="." method="_on_born_limit_value_changed"]
+[connection signal="value_changed" from="initial_probability" to="." method="_on_initial_probability_value_changed"]
+[connection signal="value_changed" from="iterations" to="." method="_on_iterations_value_changed"]
diff --git a/cave.png b/cave.png
new file mode 100644
index 0000000..5c4d6c4
--- /dev/null
+++ b/cave.png
Binary files differ
diff --git a/cave.png.import b/cave.png.import
new file mode 100644
index 0000000..aa62b7f
--- /dev/null
+++ b/cave.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/cave.png-ed16753e4f303f3628391e4f3e9d3793.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://cave.png"
+dest_files=[ "res://.import/cave.png-ed16753e4f303f3628391e4f3e9d3793.stex" ]
+
+[params]
+
+compress/mode=0
+compress/lossy_quality=0.7
+compress/hdr_mode=0
+compress/bptc_ldr=0
+compress/normal_map=0
+flags/repeat=0
+flags/filter=true
+flags/mipmaps=false
+flags/anisotropic=false
+flags/srgb=2
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/HDR_as_SRGB=false
+process/invert_color=false
+stream=false
+size_limit=0
+detect_3d=true
+svg/scale=1.0
diff --git a/default_env.tres b/default_env.tres
new file mode 100644
index 0000000..20207a4
--- /dev/null
+++ b/default_env.tres
@@ -0,0 +1,7 @@
+[gd_resource type="Environment" load_steps=2 format=2]
+
+[sub_resource type="ProceduralSky" id=1]
+
+[resource]
+background_mode = 2
+background_sky = SubResource( 1 )
diff --git a/icon.png b/icon.png
new file mode 100644
index 0000000..c98fbb6
--- /dev/null
+++ b/icon.png
Binary files differ
diff --git a/icon.png.import b/icon.png.import
new file mode 100644
index 0000000..96cbf46
--- /dev/null
+++ b/icon.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://icon.png"
+dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
+
+[params]
+
+compress/mode=0
+compress/lossy_quality=0.7
+compress/hdr_mode=0
+compress/bptc_ldr=0
+compress/normal_map=0
+flags/repeat=0
+flags/filter=true
+flags/mipmaps=false
+flags/anisotropic=false
+flags/srgb=2
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/HDR_as_SRGB=false
+process/invert_color=false
+stream=false
+size_limit=0
+detect_3d=true
+svg/scale=1.0
diff --git a/project.godot b/project.godot
new file mode 100644
index 0000000..47d1360
--- /dev/null
+++ b/project.godot
@@ -0,0 +1,38 @@
+; Engine configuration file.
+; It's best edited using the editor UI and not directly,
+; since the parameters that go here are not all obvious.
+;
+; Format:
+; [section] ; section goes between []
+; param=value ; assign values to parameters
+
+config_version=4
+
+_global_script_classes=[ ]
+_global_script_class_icons={
+
+}
+
+[application]
+
+config/name="Dungeon Generator"
+run/main_scene="res://World.tscn"
+config/icon="res://icon.png"
+
+[display]
+
+window/size/height=800
+
+[input]
+
+quit={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":81,"unicode":0,"echo":false,"script":null)
+, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777217,"unicode":0,"echo":false,"script":null)
+, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":true,"control":false,"meta":false,"command":false,"pressed":false,"scancode":81,"unicode":0,"echo":false,"script":null)
+ ]
+}
+
+[rendering]
+
+environment/default_environment="res://default_env.tres"