Initial commit
This commit is contained in:
commit
cf7ad3446b
26 changed files with 514 additions and 0 deletions
4
.editorconfig
Normal file
4
.editorconfig
Normal file
|
@ -0,0 +1,4 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
# Normalize EOL for all files that Git considers text files.
|
||||
* text=auto eol=lf
|
15
.gitignore
vendored
Normal file
15
.gitignore
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Godot 4+ specific ignores
|
||||
.godot/
|
||||
|
||||
# Godot-specific ignores
|
||||
.import/
|
||||
export.cfg
|
||||
export_presets.cfg
|
||||
|
||||
# Imported translations (automatically generated from CSV files)
|
||||
*.translation
|
||||
|
||||
# Mono-specific ignores
|
||||
.mono/
|
||||
data_*/
|
||||
mono_crash.*.json
|
2
README.md
Normal file
2
README.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
# ProceduralGenerationGodot
|
||||
Ressources et exemple format CELL Generation Procédurale
|
1
icon.svg
Normal file
1
icon.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128"><rect width="124" height="124" x="2" y="2" fill="#363d52" stroke="#212532" stroke-width="4" rx="14"/><g fill="#fff" transform="translate(12.322 12.322)scale(.101)"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 814 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H446l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c0 34 58 34 58 0v-86c0-34-58-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042" transform="translate(12.322 12.322)scale(.101)"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></svg>
|
After Width: | Height: | Size: 994 B |
37
icon.svg.import
Normal file
37
icon.svg.import
Normal file
|
@ -0,0 +1,37 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://b832t05bsh3ke"
|
||||
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://icon.svg"
|
||||
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.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
|
||||
svg/scale=1.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/convert_colors_with_editor_theme=false
|
23
mazegeneration/2D/main2d.tscn
Normal file
23
mazegeneration/2D/main2d.tscn
Normal file
File diff suppressed because one or more lines are too long
102
mazegeneration/2D/tile_map_layer_maze.gd
Normal file
102
mazegeneration/2D/tile_map_layer_maze.gd
Normal file
|
@ -0,0 +1,102 @@
|
|||
@tool
|
||||
extends TileMapLayer
|
||||
|
||||
# ---------------------
|
||||
# Definir les variables
|
||||
# ---------------------
|
||||
|
||||
# largeur, longeur du labyrinte
|
||||
@export var WIDTH : int
|
||||
@export var HEIGHT : int
|
||||
|
||||
# Les boutons
|
||||
@export_tool_button("Init") var init_action = init_maze
|
||||
@export_tool_button("Step") var step_action = generate_maze_step
|
||||
@export_tool_button("All") var all_action = generate_map_all
|
||||
@export_tool_button("All with wait") var all_wait_action = generate_map_all_wait
|
||||
|
||||
const TILE_FLOOR = Vector2i(0, 0)
|
||||
const TILE_WALL = Vector2i(1, 0)
|
||||
var current_pos = Vector2i(0, 0)
|
||||
|
||||
var undo_stack : Array[Vector2i] = [current_pos] # Pile des positions explores, on depopera la pile pour le backtracking
|
||||
var explored : Dictionary[Vector2i, bool] # Stock les positions explores
|
||||
# Pas besoin d'init a false pour explored, contrairement python la valeur d'une cle pas dans le dico, est null. Qui est interprete comme false en gdscript
|
||||
|
||||
# ---------------------
|
||||
# Fonctions utilitaires
|
||||
# ---------------------
|
||||
|
||||
func set_tile(pos : Vector2i, val : Vector2i) -> void:
|
||||
assert(pos.x >= 0 && pos.x < WIDTH, "x has bad value, x is {}, but should be beetwen 0 and {}".format([pos.x, WIDTH], "{}"))
|
||||
assert(pos.y >= 0 && pos.y < HEIGHT, "y has bad value, y is {}, but should be beetwen 0 and {}".format([pos.y, HEIGHT], "{}"))
|
||||
set_cell(pos, 0, val)
|
||||
|
||||
# Renvoie une direction possible depuis une position dans le labyrinte
|
||||
func get_random_possible_dir(current_pos : Vector2i):
|
||||
var all_dir = [2*Vector2i.UP, 2*Vector2i.DOWN, 2*Vector2i.RIGHT, 2*Vector2i.LEFT]
|
||||
var possible_dir = []
|
||||
for dir in all_dir:
|
||||
var next_pos = current_pos + dir
|
||||
var can_be_explored = not explored.get(next_pos) \
|
||||
&& next_pos.x >= 0 && next_pos.x < WIDTH && next_pos.y >= 0 && next_pos.y < HEIGHT
|
||||
|
||||
if can_be_explored:
|
||||
possible_dir.append(dir)
|
||||
|
||||
if possible_dir.is_empty():
|
||||
return null
|
||||
|
||||
return possible_dir.pick_random()
|
||||
|
||||
# Va dans la direction dir, pour agrandir le labyrinthe
|
||||
func path_move(dir : Vector2i) -> void:
|
||||
var next_pos = current_pos + dir
|
||||
var passway = current_pos + dir / 2
|
||||
set_tile(passway, TILE_FLOOR)
|
||||
set_tile(next_pos, TILE_FLOOR)
|
||||
explored[next_pos] = true
|
||||
undo_stack.append(next_pos)
|
||||
current_pos = next_pos
|
||||
|
||||
# Initialize le labyrinthe
|
||||
func init_maze() -> void:
|
||||
print("init map")
|
||||
current_pos = Vector2i(0, 0)
|
||||
undo_stack = [current_pos]
|
||||
explored = {}
|
||||
clear() # fonction de TileMapLayer, clear les tiles
|
||||
|
||||
current_pos = Vector2i(0, 0)
|
||||
explored[current_pos] = true
|
||||
for x in range(WIDTH):
|
||||
for y in range(HEIGHT):
|
||||
set_cell(Vector2i(x, y), 0, TILE_WALL) # fonction de TileMapLayer
|
||||
|
||||
func _ready() -> void:
|
||||
print("ready")
|
||||
|
||||
# ----------------------------------
|
||||
# Fonctions appeles par les boutons
|
||||
# ----------------------------------
|
||||
|
||||
func generate_maze_step() -> void:
|
||||
var next_dir = get_random_possible_dir(current_pos)
|
||||
|
||||
# Si pas de voisins (next_dir est vide), alors on va en arriere
|
||||
while not next_dir:
|
||||
print("going back")
|
||||
current_pos = undo_stack.pop_back()
|
||||
next_dir = get_random_possible_dir(current_pos)
|
||||
|
||||
print("path move")
|
||||
path_move(next_dir)
|
||||
|
||||
func generate_map_all() -> void:
|
||||
while not undo_stack.is_empty():
|
||||
generate_maze_step()
|
||||
|
||||
func generate_map_all_wait() -> void:
|
||||
while not undo_stack.is_empty():
|
||||
generate_maze_step()
|
||||
await get_tree().create_timer(0.01).timeout
|
1
mazegeneration/2D/tile_map_layer_maze.gd.uid
Normal file
1
mazegeneration/2D/tile_map_layer_maze.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://2fw281l5o16y
|
BIN
mazegeneration/2D/tileset.aseprite
Normal file
BIN
mazegeneration/2D/tileset.aseprite
Normal file
Binary file not shown.
BIN
mazegeneration/2D/tileset.png
Normal file
BIN
mazegeneration/2D/tileset.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 220 B |
34
mazegeneration/2D/tileset.png.import
Normal file
34
mazegeneration/2D/tileset.png.import
Normal file
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://hwfveek70gga"
|
||||
path="res://.godot/imported/tileset.png-d096f978b03dd56545ecbab3756af876.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://mazegeneration/2D/tileset.png"
|
||||
dest_files=["res://.godot/imported/tileset.png-d096f978b03dd56545ecbab3756af876.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
|
93
mazegeneration/3D/grid_map_maze.gd
Normal file
93
mazegeneration/3D/grid_map_maze.gd
Normal file
|
@ -0,0 +1,93 @@
|
|||
@tool
|
||||
extends GridMap
|
||||
# Moralement c'est un labyrinthe 2D, mais les graphiques sont en 3D
|
||||
# Le code sera comme tile_map_layer_maze mais avec des gridmaps au lieu des tilemaps
|
||||
|
||||
# ---------------------
|
||||
# Definir les variables
|
||||
# ---------------------
|
||||
|
||||
# largeur, longeur du labyrinte
|
||||
@export var WIDTH : int
|
||||
@export var HEIGHT : int
|
||||
|
||||
# Les boutons
|
||||
@export_tool_button("Init") var init_action = init_maze
|
||||
@export_tool_button("Step") var step_action = generate_maze_step
|
||||
@export_tool_button("All") var all_action = generate_map_all
|
||||
@export_tool_button("All with wait") var all_wait_action = generate_map_all_wait
|
||||
|
||||
|
||||
const TILE_FLOOR = 1
|
||||
const TILE_WALL = 0
|
||||
|
||||
var current_pos = Vector3i(0, 0, 0)
|
||||
var undo_stack : Array[Vector3i]
|
||||
var explored : Dictionary[Vector3i, bool]
|
||||
|
||||
func set_grid(pos : Vector3i, val : int):
|
||||
assert(pos.x >= 0 && pos.x < WIDTH, "x has bad value, x is {}, but should be beetwen 0 and {}".format([pos.x, WIDTH], "{}"))
|
||||
assert(pos.z >= 0 && pos.z < HEIGHT, "z has bad value, z is {}, but should be beetwen 0 and {}".format([pos.z, HEIGHT], "{}"))
|
||||
set_cell_item(pos, val) #Fonction de gridmap
|
||||
|
||||
# Renvoie une direction possible depuis une position dans le labyrinte
|
||||
func get_random_possible_dir(current_pos : Vector3i):
|
||||
var all_dir = [2*Vector3i.FORWARD, 2*Vector3i.LEFT, 2*Vector3i.RIGHT, 2*Vector3i.BACK]
|
||||
var possible_dir = []
|
||||
for dir in all_dir:
|
||||
var next_pos = current_pos + dir
|
||||
var can_be_explored = not explored.get(next_pos) \
|
||||
&& next_pos.x >= 0 && next_pos.x < WIDTH && next_pos.z >= 0 && next_pos.z < HEIGHT
|
||||
|
||||
if can_be_explored:
|
||||
possible_dir.append(dir)
|
||||
|
||||
if possible_dir.is_empty():
|
||||
return null
|
||||
|
||||
return possible_dir.pick_random()
|
||||
|
||||
# Va dans la direction dir, pour agrandir le labyrinthe
|
||||
func path_move(dir : Vector3i) -> void:
|
||||
var next_pos = current_pos + dir
|
||||
var passway = current_pos + dir / 2
|
||||
set_grid(passway, TILE_FLOOR)
|
||||
set_grid(next_pos, TILE_FLOOR)
|
||||
explored[next_pos] = true
|
||||
undo_stack.append(next_pos)
|
||||
current_pos = next_pos
|
||||
|
||||
# Initialize le labyrinthe
|
||||
func init_maze() -> void:
|
||||
print("init map")
|
||||
current_pos = Vector3i(0, 0, 0)
|
||||
undo_stack = [current_pos]
|
||||
explored = {}
|
||||
clear() # fonction de GridMap, clear les tiles
|
||||
|
||||
current_pos = Vector3i(0, 0, 0)
|
||||
explored[current_pos] = true
|
||||
for x in range(WIDTH):
|
||||
for z in range(HEIGHT):
|
||||
set_cell_item(Vector3i(x, 0, z), TILE_WALL) # fonction de GridMap
|
||||
|
||||
func generate_maze_step() -> void:
|
||||
var next_dir = get_random_possible_dir(current_pos)
|
||||
|
||||
# Si pas de voisins (next_dir est vide), alors on va en arriere
|
||||
while not next_dir:
|
||||
print("going back")
|
||||
current_pos = undo_stack.pop_back()
|
||||
next_dir = get_random_possible_dir(current_pos)
|
||||
|
||||
print("path move")
|
||||
path_move(next_dir)
|
||||
|
||||
func generate_map_all() -> void:
|
||||
while not undo_stack.is_empty():
|
||||
generate_maze_step()
|
||||
|
||||
func generate_map_all_wait() -> void:
|
||||
while not undo_stack.is_empty():
|
||||
generate_maze_step()
|
||||
await get_tree().create_timer(0.01).timeout
|
1
mazegeneration/3D/grid_map_maze.gd.uid
Normal file
1
mazegeneration/3D/grid_map_maze.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://b0bhljevk3h8r
|
11
mazegeneration/3D/grids_tiles/wall.tscn
Normal file
11
mazegeneration/3D/grids_tiles/wall.tscn
Normal file
|
@ -0,0 +1,11 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://brb3771fda52c"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_vu8eu"]
|
||||
albedo_color = Color(3.08037e-06, 0.959929, 0.976304, 1)
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_vu8eu"]
|
||||
material = SubResource("StandardMaterial3D_vu8eu")
|
||||
size = Vector3(2, 4, 2)
|
||||
|
||||
[node name="Wall" type="MeshInstance3D"]
|
||||
mesh = SubResource("BoxMesh_vu8eu")
|
11
mazegeneration/3D/grids_tiles/way.tscn
Normal file
11
mazegeneration/3D/grids_tiles/way.tscn
Normal file
|
@ -0,0 +1,11 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://c20by0tgxdjpc"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_t6cuw"]
|
||||
albedo_color = Color(0.188162, 0.571815, 1.84822e-05, 1)
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_t6cuw"]
|
||||
material = SubResource("StandardMaterial3D_t6cuw")
|
||||
size = Vector3(2, 2, 2)
|
||||
|
||||
[node name="Wall" type="MeshInstance3D"]
|
||||
mesh = SubResource("BoxMesh_t6cuw")
|
15
mazegeneration/3D/main3d.tscn
Normal file
15
mazegeneration/3D/main3d.tscn
Normal file
File diff suppressed because one or more lines are too long
57
mazegeneration/3D/mesh_lib.tres
Normal file
57
mazegeneration/3D/mesh_lib.tres
Normal file
File diff suppressed because one or more lines are too long
10
mazegeneration/3D/mesh_library_scene.tscn
Normal file
10
mazegeneration/3D/mesh_library_scene.tscn
Normal file
|
@ -0,0 +1,10 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://qdw4en85l0eq"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://brb3771fda52c" path="res://3D/grids_tiles/wall.tscn" id="1_2npxr"]
|
||||
[ext_resource type="PackedScene" uid="uid://c20by0tgxdjpc" path="res://3D/grids_tiles/way.tscn" id="2_t4liu"]
|
||||
|
||||
[node name="MeshLibraryScene" type="Node3D"]
|
||||
|
||||
[node name="Wall" parent="." instance=ExtResource("1_2npxr")]
|
||||
|
||||
[node name="Way" parent="." instance=ExtResource("2_t4liu")]
|
BIN
noisebased/2D/SpriteSheet.aseprite
Normal file
BIN
noisebased/2D/SpriteSheet.aseprite
Normal file
Binary file not shown.
BIN
noisebased/2D/SpriteSheet.png
Normal file
BIN
noisebased/2D/SpriteSheet.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 711 B |
34
noisebased/2D/SpriteSheet.png.import
Normal file
34
noisebased/2D/SpriteSheet.png.import
Normal file
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://colf2egr7qaim"
|
||||
path="res://.godot/imported/SpriteSheet.png-b57f0c24384f7a632d0e320745b5b85e.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://noisebased/2D/SpriteSheet.png"
|
||||
dest_files=["res://.godot/imported/SpriteSheet.png-b57f0c24384f7a632d0e320745b5b85e.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
|
24
noisebased/2D/main2d.tscn
Normal file
24
noisebased/2D/main2d.tscn
Normal file
|
@ -0,0 +1,24 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://dec38suo3xt5j"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://colf2egr7qaim" path="res://noisebased/2D/SpriteSheet.png" id="1_067u0"]
|
||||
[ext_resource type="Script" uid="uid://c1j2itgknxbv6" path="res://noisebased/2D/noise_gen_tile_map_layer.gd" id="2_c4myh"]
|
||||
|
||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_c4myh"]
|
||||
texture = ExtResource("1_067u0")
|
||||
0:0/0 = 0
|
||||
1:0/0 = 0
|
||||
2:0/0 = 0
|
||||
3:0/0 = 0
|
||||
4:0/0 = 0
|
||||
5:0/0 = 0
|
||||
6:0/0 = 0
|
||||
7:0/0 = 0
|
||||
|
||||
[sub_resource type="TileSet" id="TileSet_rguwg"]
|
||||
sources/0 = SubResource("TileSetAtlasSource_c4myh")
|
||||
|
||||
[node name="Main2d" type="Node2D"]
|
||||
|
||||
[node name="TileMapLayer" type="TileMapLayer" parent="."]
|
||||
tile_set = SubResource("TileSet_rguwg")
|
||||
script = ExtResource("2_c4myh")
|
16
noisebased/2D/noise_gen_tile_map_layer.gd
Normal file
16
noisebased/2D/noise_gen_tile_map_layer.gd
Normal file
|
@ -0,0 +1,16 @@
|
|||
@tool
|
||||
extends TileMapLayer
|
||||
|
||||
# ---------------------
|
||||
# Definir les variables
|
||||
# ---------------------
|
||||
|
||||
# largeur, longeur de la map
|
||||
@export var WIDTH : int
|
||||
@export var HEIGHT : int
|
||||
|
||||
# Les boutons
|
||||
@export_tool_button("All") var all_action = generate_map
|
||||
|
||||
func generate_map():
|
||||
return
|
1
noisebased/2D/noise_gen_tile_map_layer.gd.uid
Normal file
1
noisebased/2D/noise_gen_tile_map_layer.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://c1j2itgknxbv6
|
20
project.godot
Normal file
20
project.godot
Normal file
|
@ -0,0 +1,20 @@
|
|||
; 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=5
|
||||
|
||||
[application]
|
||||
|
||||
config/name="Proceduralgeneration"
|
||||
config/features=PackedStringArray("4.4", "GL Compatibility")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[rendering]
|
||||
|
||||
renderer/rendering_method="gl_compatibility"
|
||||
renderer/rendering_method.mobile="gl_compatibility"
|
Loading…
Add table
Add a link
Reference in a new issue