Exit / entrance socket based dungeon generator

Strengths = any size room, hallway or tile can be used

since collision is used to ‘cull’ bad rooms, a border can be established to control a build area geometry

weakness at the moment/areas I need help

1.can’t use random.seed correctly at the moment to always make the same maze from the same conditions.

2.having trouble connecting adjacent areas together (like joining two hallways that are growing from diff directions)

3.density - Thinking maybe after maze is ‘landlocked’ (no open places to build) - try replacing I sections (hallways)

  1. landlocking early (too many dead end caps or intersecting paths)

with T’s and rooms.

Maze Generator


import bge
from mathutils import Vector
import random


def multi_delete(list_, args):
    indexes = sorted(list(args), reverse=True)
    for index in indexes:
        try:
            del list_[index]
        except:
            break    
    return list_






def main():
    
    cont = bge.logic.getCurrentController()
    own = cont.owner
    if 'Seed' not in own:
        random.seed ="Dug"
        
    if 'Choices' not in own:
        
        own['Choices']=[]
        pieceList = ["1","1","1","2","3","1","1","1"]
        
        
        choice = random.randint(0, 7)
        piece = own.scene.addObject(pieceList[choice],own,0)
        piece['Spawner']=own.parent
        
    else:
        for objects in own.scene.objects:
            if 'CP' in objects:
                for objects2 in own.scene.objects:
                    if 'CP' in objects2:
                        if objects2!=objects:
                            if objects.getDistanceTo(objects2)<.25:
                                if objects2!=own:
                                    objects2['No']=True
                                if objects!=own:    
                                    objects2['No']=True
        CPL =[]                            
        for objects in own.scene.objects:
            if 'CP' in objects:
                if 'No' not in objects: 
                
                    if objects.name!="Map":
                        CPL.append(objects)
                
        for objects in CPL:            
            if own['E']>=1:
                pieceList = ["1","1","1","2","3","1","1","4"]
                choice = random.randint(0, 7)
                piece = own.scene.addObject(pieceList[choice],objects,0)
                point = Vector(eval(objects['CP']))
                point = objects.worldPosition+(objects.worldOrientation*po  int)
                piece.alignAxisToVect(piece.getVectTo(point)[1],0,1)
                
                
                piece['Spawner']=objects  
                own['E']-=1                      
                
        
        
        


main()



kill overlapping rooms code*



import bge




def main():


    cont = bge.logic.getCurrentController()
    own = cont.owner


    Collision = cont.sensors['Collision']
    
    if Collision.positive:
        for objects in Collision.hitObjectList:
            if objects!=own.parent['Spawner']:
                if objects.parent:
                    if objects.parent!=own.parent['Spawner']:
                        if objects.parent!=own.parent:
                            if not own.parent.invalid:
                                for child in objects.parent.children:
                                    if 'CP' in child:
                                        if 'No' not in child:
                                            for childz in own.parent.children:
                                                if 'CP' in childz:
                                                    D = child.getDistanceTo(childz)
                                                    if D<.25:
                                                        break
                                                    
                                                    
                                                
                                                
                                own.scene.objects['Map']['E']+=1
                                
                                own.parent.endObject()
                                break
                else:
                    if not own.parent.invalid:
                        own.scene.objects['Map']['E']+=1
                         
                        own.parent.endObject()
                        break
                
                
            
main()



it’s raw and prototypish at the moment.

Attachments

Non_repetitive_Random_Dungeon_DesignDocument2.blend (1.13 MB)

lol , almost artistic the “stairs code” :smiley:

well for random.seed , not work since the right syntax is -> random.seed(“Bob”) (not random.seed = “Bob”)
and after that should work in your code (to note that is valid only inside the same function seem , otherwise must be rewritten random.seed(const))

why use gameobject? is not too complex ? problem with orientation? size? yeah, that is a gameobject
not better try to make a virtual maze (basically a pure dictionary) then place the gameobject -> AFTER?

about intersections (road closed?), for a “worm” in a dictionary is not a problem , it can pass over the intersection without problems.
at most overrite the already existent key of dictionary , not add gameobject …

The map pieces will all be different sizes and shapes, (reg rooms, special rooms, unique rooms, etc)

and they will also conform to the ‘boundries’ around them, collision just seems to work well, I was trying to use it to connect sockets in that “artistic stairs code” by preventing deletion.

edit: removed a hacky bit of code that was also slow and now each ‘spawner’ gets the piece it spawns stored in it, and if the piece deletes itself, it removes the property piece from the spawner, opening it to spawn again, also thank you about the seed!

also added ‘cap holes when finished’

Do you have to use all those if’s.Are you just being lazy?You are using a lot of if’s.That is sloopy code.There is a better way.But i forgot how to.Because i am using visual programming in the bge and in unreal game engine.I think the unreal game engine has a lot more to offer now.I am waiting for the upbge to get developed more for openworlds.

in the collision section it looks like all the if’s are necessary but I have cleaned up the maze generation code a bunch


import bge
from mathutils import Vector
import random


def multi_delete(list_, args):
    indexes = sorted(list(args), reverse=True)
    for index in indexes:
        try:
            del list_[index]
        except:
            break    
    return list_






def main():
    
    cont = bge.logic.getCurrentController()
    own = cont.owner
    own['it']+=1
    if 'Seed' not in own:
        stringz = 'Ni'+str(own['it'])
        random.seed(stringz)        
    if 'Choices' not in own:
        
        own['Choices']=[]
        pieceList = ["1","2","3"]
        
        
        choice = random.randint(0, 2)
        piece = own.scene.addObject(pieceList[choice],own,0)
        piece['Spawner']=own.parent
        
    else:
        
        CPL =[]                            
        for objects in own.scene.objects:
            if 'CP' in objects:
                if 'No' not in objects: 
                
                    if objects.name!="Map":
                        CPL.append(objects)
                
        for objects in CPL:            
            if own['E']>=1 and 'Piece' not in objects:
                pieceList = ["1","1","1","2","3","1","1","4"]
                choice = random.randint(0, 7)
                piece = own.scene.addObject(pieceList[choice],objects,0)
                point = Vector(eval(objects['CP']))
                point = objects.worldPosition+(objects.worldOrientation*point)
                piece.alignAxisToVect(piece.getVectTo(point)[1],0,1)
                
                
                piece['Spawner']=objects  
                objects['Piece']=piece
                own['E']-=1                      
                
        
        
        


main()



Looking better keep up the good work.