def prepareRandomLevel(screen, cols=0, rows=0): messages.colorBackground() if not cols: cols = int(getChoiceUnbounded("Room width?", [str(x) for x in range(30, 61, 5)])) if not rows: rows = int(getChoiceUnbounded("Room height?", [str(x) for x in range(20, 61, 5)])) room.globalize_dimensions(rows, cols) lines = [" " * cols for x in range(rows + 1)] room.randomlymodify(lines) tiles = [] for c in range(cols): tiles.append([]) for r in range(rows): tiles[c].append(tile.tile[lines[r][c]]) r = room.Room(tiles, lines) graphics.extract_dimensions(lines) world = pygame.Surface((graphics.world_w, graphics.world_h)) t = topbar.TopBar(screen) test.mark(r.background) r.topbar = t return world, t, r
def load_game(): g = open(os.path.join("data", "saved", "room.txt")) try: print "\nTrying to load saved game." r = pickle.load(g) print 0, graphics.extract_dimensions(r.lines) print 1, r.background = pygame.Surface((graphics.world_w, graphics.world_h)) print 2, r.collisionfield = pygame.Surface((graphics.world_w, graphics.world_h)) print 3, r.pixels = pygame.PixelArray(r.collisionfield) print 3.5, r.globalize_dimensions() print 4, r.draw(r.background) # Note that this sets the start position to wherever the '!' is print 5, r.background.convert() print 6, r.draw(r.collisionfield, collision_only = 1) print 7, r.collisionfield.convert() print 8, r.pixels = pygame.PixelArray(r.collisionfield) print 9, for b in r.bees: b.update_eyes() print "10, let's go!" print "\n\n* * * * * * Loaded Saved Game * * * * * *" return r except: print "Failed to load saved game" g.close() return 0
def __init__(self, tiles, lines): #generateringmap(80, 60, 20, 30) self.lines = lines graphics.extract_dimensions(self.lines) nextmessage = 6 self.cols, self.rows = cols, rows for i in range(rows): for j in range(cols): drawpoint(i, j, lines) self.tiles = tiles self.camera = 0 self.madness = 0 self.stasis = False self.roomnumber = 0 self.signal_new_tree = 0 nextmessage = messages.say("reducing sides", 0, down=nextmessage) self.reduce_sides() nextmessage = messages.say("collision stuff", 0, down=nextmessage) self.optimize_convexes() if (DRAW_RANDOM_CIRCLES): nextmessage = messages.say( "computing density", 0, down=nextmessage) self.compute_densities() self.object_directory = [[[] for r in range(rows)] for c in range(cols)] self.background = pygame.Surface((graphics.world_w, graphics.world_h)) self.collisionfield = pygame.Surface( (graphics.world_w, graphics.world_h)) self.bgw = graphics.world_w self.bgh = graphics.world_h self.a = 0 self.start_position = matrix([100, 100]) for r in range(rows): for c in range(cols): if self.lines[r][c] == '!': self.start_position = matrix( [bw * c + bw / 2, bh * r + bh / 2]) nextmessage = messages.say("drawing background", 0, down=nextmessage) if TIME_INITIALIZATION: backgroundstarttime = time.time() # Note that this sets the start position to wherever the '!' is self.draw(self.background) self.background.convert() self.draw(self.collisionfield, collision_only=1) self.collisionfield.convert() self.pixels = pygame.PixelArray(self.collisionfield) if TIME_INITIALIZATION: print "drawing background took", time.time() - backgroundstarttime, "seconds" self.food = [] self.bees = [] self.deadbees = [] self.player = None self.topbar = None self.beehistory = 0 self.bestbees = [] self.timetosave = 100 self.h = None self.dirtyareas = [] self.visibles = [] self.bullets = [] self.painter = palette.Palette() self.recentdeaths = 0 self.freespots = [(r, c) for r in range(rows) for c in range(cols) if self.lines[r][c] == " "] # for r,c in self.freespots: # pygame.draw.circle(self.background, [255, 255, 255], (int((c+0.5)*bw), int((r+0.5)*bh)), 10, 1) nextmessage = messages.say("precomputing vision", 0, down=nextmessage) self.precompute_vision()