def generateWorld(self, start_autonomous): now = int(time.time()) worldage = now - self.last_worldgen logging.debug("World regenerated after {} seconds".format(worldage)) self.last_worldgen = now # run garbage collection gc.collect() # log memory usage usage = resource.getrusage(resource.RUSAGE_SELF) logging.debug("Process memory usage is: {}".format(usage.ru_maxrss)) self.surface.fill((0,0,0)) # show notice font = pygame.font.Font(None, 52) textBitmap = font.render("Flat Flip Friends", True, colors.WHITE) textWidth = textBitmap.get_rect().width textHeight = textBitmap.get_rect().height self.surface.blit(textBitmap, [self.display.getDisplaySize()[0]/2 - textWidth/2, self.display.getDisplaySize()[1]/2 - textHeight*2]) font = pygame.font.Font(None, 30) textBitmap = font.render("Generating world...", True, colors.WHITE) textWidth = textBitmap.get_rect().width self.surface.blit(textBitmap, [self.display.getDisplaySize()[0]/2 - textWidth/2, self.display.getDisplaySize()[1]/2]) pygame.display.update() # Create the world, passing through the grid size theworld = World(self.gridDisplaySize) logging.debug("rendered world:\n{0}".format(theworld.to_s())) # Create the world map, passing through the display size and world map self.map = Map(self.mapSize, self.display, self.character_size, theworld) art = theworld.addArt(self.map) shapes = self.map.addShapes() self.sprites = pygame.sprite.Group(shapes, art) # Create the player object and add it's shape to a sprite group self.player = Player() self.player.selectShape(self.map.shapes[0]) # just grab the first shape for the player self.player.shape.autonomous = self.start_autonomous self.map.player = self.player
print("USING RANDOM SEED: {0}".format(crazySeed)) random.seed(crazySeed) #gridDisplaySize = (20, 10) gridDisplaySize = (40, 20) #gridDisplaySize = (100, 35) # Create the world, passing through the display size theworld = World(gridDisplaySize) start = 0, 0 goal = gridDisplaySize[1]-1, gridDisplaySize[0]-1 pf = PathFinder(theworld.successors, theworld.move_cost, theworld.move_cost) import time t = time.clock() logging.debug("Computing path for world map:\n"+theworld.to_s()) path = list(pf.compute_path(start, goal)) print("Elapsed: %s" % (time.clock() - t)) if(path): print("Path from {0} to {1} is: {2}".format(start,goal,path)) # show the final product print("world map with path:") print(theworld.to_s(path)) else: print("Path could not be found from {0} to {1}".format(start,goal)) print("world map is:") print(theworld.to_s())