I’m Japanese.
I am learning English now.
Godot 3.5
Godot GridMap Not Outputting with no error message
Im thinking of developing a roguelike, Mystery Dungeon-like, automatically generated maze game using the game engine Godot 3.5
The automatically generated maze uses a digging method instead of a maze with rooms like Rogue. Reference website for automatic maze generation using hole digging method Reference website 1. Reference website 2 for automatic maze generation using the digging method Reference website 2.
Source code of self-made maze automatic generation program for Godot (GDScript).
extends Spatial
var maze_width = 10
var maze_height = 10
var _maze_width = maze_width * 2 + 1
var _maze_height = maze_height * 2 +1
const grid_wall = 0
const array_out_of_range = -1 #outside the maze
const array_passage = 0 #aisle
const array_wall = 1 #wall
class Array2D:
var _width = 0
var _height = 0
var _pool = []
func _init(w:int,h:int) -> void:
_width = w
_height = h
for j in range(h):
for i in range(w):
_pool.append(0)
func fill(v:int) -> void:
for j in range(_height):
for i in range(_width):
_pool[i + j * _width] = v
func setv(i:int,j:int,v:int) -> void:
if i < 0 + 1 or i >= _width - 1:
return #outside the maze
if j < 0 + 1 or j >= _height - 1:
return #outside the maze
_pool[i + j * _width] = v
func getv(i:int,j:int) -> int:
if i < 0 + 1 or i >= _width - 1:
return array_out_of_range #outside the maze
if j < 0 + 1 or j >= _height - 1:
return array_out_of_range #outside the maze
return _pool[i +j * _width]
func dump() -> void:
print("[array2D]")
for j in range(_height):
var s = ""
for i in range(_width):
s += "%d, "%getv(i,j)
print(s)
var _array = Array2D.new(_maze_width,_maze_height)
onready var gridmap = $GridMap
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
#pass # Replace with function body.
_regenerate()
_redraw()
func _regenerate() -> void:
_array.fill(array_wall)
var xstart = 1
var ystart = 1
while xstart % 2 == 1:
xstart = randi()%_maze_width
while ystart % 2 == 1:
ystart = randi()%_maze_height
_dig(xstart,ystart)
_array.dump()
func _dig(x:int, y:int) -> void:
_array.setv(x,y,array_passage)
var dir_list = [
Vector2(-1, 0),
Vector2(0, -1),
Vector2(1,0),
Vector2(0,1)
]
dir_list.shuffle()
for dir in dir_list:
var dx = dir.x
var dy = dir.y
if _array.getv(x + dx * 2, y + dy * 2) == array_wall:
#2 space ahead is a wall so you can dig
_array.setv(x + dx, y + dy, 0)
#Dig the next hole with recursive call
_dig(x + dx * 2, y + dy * 2)
#GridMapに反映する
func _redraw() -> void:
gridmap.clear()
for j in range(_maze_height):
for i in range(_maze_width):
if _array.getv(i,j) == array_wall:
gridmap.set_cell_item(i, 1, j, 0)
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
Although this source code does not result in a syntax error,
the maze will not be automatically generated.
In the current source code (Godot 3.X) the maze is not actually reflected in the GridMap node.
Are there any descriptions that I am missing? Why won’t any errors show? And why is the node not being generated?
I am at a loss.