Example #1
0
def mainGenerate():
    '''Perform a full generation run, from array, png to world creation'''
    #Generate the world and tree
    world, root = generateWorld()
    #Create the bases from the world and the tree
    world, bases = createBases(world, root)

    #Create the robots from the bases
    robots = addRobots(bases)
    #Convert the bases to world space
    baseBlocks = createBaseBlocks(bases)
    #Convert the robot positions to world space
    robotPositions = convertRobotsToWorld(robots)

    #Create a list of obstacles
    obstacles = generateObstacles()

    #Output the world as a picture
    printWorld(world, "")

    #Generate the wall parts for the tree
    generateWallParts(root, world)
    #Generate the edges of the map to mark as used
    used = generateEdges(world)
    #Calculate all the wall blocks for the tree (exclude used pixels)
    walls, used = createAllWallBlocks(root, used)

    #Make a map from the walls
    WorldCreator.makeFile(walls, baseBlocks, obstacles, robotPositions)

    #Print to indicate the program completed properly
    print("Generation Successful")
Example #2
0
def generateWorldFile(world, obstacles, startPos, window):
    #Array of wall tiles
    walls = []

    #Iterate vertically
    for y in range(0, len(world) + 1):
        #Create a row
        row = []
        #Iterate horizontally
        for x in range(0, len(world[0]) + 1):
            #Add each tile [present, [uWall,rWall,dWall,lWall], checkpoint, trap, goal, swamp, humanType, humanWall]
            row.append([
                False, [False, False, False, False], False, False, False,
                False, 0, 0
            ])
        #Add row to array
        walls.append(row)

    #Iterate for each of the tiles
    for y in range(0, len(world)):
        for x in range(0, len(world[0])):
            #If there is a tile there
            if world[y][x] != None:
                #Get the human data
                humanInfo = world[y][x].getHumanData()
                #Add the wall data
                walls[y][x] = [
                    True, world[y][x].getWalls(), world[y][x].getCheckpoint(),
                    world[y][x].getTrap(), world[y][x].getGoal(),
                    world[y][x].getSwamp(), humanInfo[0], humanInfo[1]
                ]

    #Make a map from the walls and objects
    WorldCreator.makeFile(walls, obstacles, startPos, window)
Example #3
0
def generateWorldFile (world, root, baseBlocks, obstacles, robotPositons, numHumans, numChildren, activities, bounds, doors, window):
    #Generate the wall parts for the tree
    generateWallParts(root, world)
    #Generate the edges of the map to mark as used
    used = generateEdges(world)
    #Calculate all the wall blocks for the tree (exclude used pixels)
    walls, used = createAllWallBlocks(root, used)

    #Convert the bounds positions to world space
    bounds = convertBoundsToWorld(bounds)

    doors = convertDoorsToWorld(doors, bounds)

    #Make a map from the walls and objects
    WorldCreator.makeFile(walls, baseBlocks, obstacles, robotPositions, numHumans, numChildren, activities, bounds, doors, window)
Example #4
0
def convertDoorsToWorld(doors, bounds):
    '''Convert door positions and directions from array space to world space and determine room connections'''
    #List to contain final door data
    finalDoors = []

    #Adjustments to enter rooms [[vert+, vert-] , [horiz+, horiz-]]
    additions = [[[0, 0.085], [0, -0.085]], [[0.085, 0], [-0.085, 0]]]

    #Iterate through the doors
    for door in doors:
        #If the door exists
        if door[0][0] != None and door[0][1] != None:
            #Get the position of the centre of the door
            doorPos = WorldCreator.transformFromBounds(door[0], door[0])[0]
            #Get the positions to check for the rooms
            room1Pos = [doorPos[0] + additions[door[1]][0][0], doorPos[1] + additions[door[1]][0][1]]
            room2Pos = [doorPos[0] + additions[door[1]][1][0], doorPos[1] + additions[door[1]][1][1]]
            #Determine which room each position is in
            room1Id = determineRoomIndex(room1Pos, bounds)
            room2Id = determineRoomIndex(room2Pos, bounds)
            #Add the door to the list [[x, y], [room1, room2]]
            finalDoors.append([doorPos, [room1Id, room2Id]])

    #Return the completed list of doors
    return finalDoors
Example #5
0
def convertBoundsToWorld(originalBounds):
    '''Takes the list of bounds in array space and converts to world space'''
    #List to contain final boundary positions
    finalBounds = []

    #Iterate list of positions
    for bound in originalBounds:
        #Calculate minimum and maximum
        minPos = WorldCreator.transformFromBounds(bound[0], bound[0])[0]
        #Adjust for wall thickness
        minPos[0] = minPos[0] + 0.075
        minPos[1] = minPos[1] + 0.075
        maxPos = WorldCreator.transformFromBounds(bound[1], bound[1])[0]
        #Adjust for wall thickness
        maxPos[0] = maxPos[0] - 0.075
        maxPos[1] = maxPos[1] - 0.075
        #Append data to final array
        finalBounds.append([minPos, maxPos])

    #Return world space bounds
    return finalBounds
Example #6
0
def convertRobotsToWorld(robots):
    '''Create the world space positions list for the robots'''
    newRobots = []

    #Iterate for the robots
    for robot in robots:
        #Convert the robot position to world space ([0] is because position only is needed, not scale)
        r = WorldCreator.transformFromBounds(robot, robot)[0]
        #Add to list of robot world positions
        newRobots.append(r)

    #Return the list of robot world positions    
    return newRobots
Example #7
0
def createBaseBlocks(bases):
    '''Create the world space base blocks from the base positions'''
    newBases = []

    #Iterate for the bases
    for base in bases:
        #Convert the base positions to world space
        b = WorldCreator.transformFromBounds(base[0], base[1])
        #Add to list of created bases
        newBases.append(b)
    
    #Return the list of world space bases
    return newBases
Example #8
0
def createAllWallBlocks(rootNode, usedPos):
    '''Create a list of all the wall objects needed (position and scale) (Recursive)'''
    #Empty list to contain all the wall blocks
    wallData = []
    
    #Get the wall parts for this node
    wallParts = rootNode.getWallParts()

    #If there were some parts in this node
    if len(wallParts) > 0:
        #Iterate parts
        for part in wallParts:
            
            #Remove and parts of the wall that have already been placed
            for bit in part:
                if bit in usedPos:
                    part.remove(bit)

            if len(part) > 0:
                #Convert the wall to position and scale then append to the data list
                wallData.append(WorldCreator.transformFromBounds(part[0], part[-1]))

            #Add all the parts used to the list of used parts
            for bit in part:
                usedPos.append(bit)
            
    
    #Get the Children of this node
    children = rootNode.getChildren()

    #If there is a left child
    if children[0] != None:
        #Add to the data the data generated from the left child
        wallDataPart, usedPos = createAllWallBlocks(children[0], usedPos)
        wallData = wallData + wallDataPart
    #If there is a right child
    if children[1] != None:
        #Add to the data the data generated from the right child
        wallDataPart, usedPos = createAllWallBlocks(children[1], usedPos)
        wallData = wallData + wallDataPart
    
    #Return the wall data
    return wallData, usedPos