def create_blocks(): """loads all used block pngs as pygame image objects and return them in a tuple""" global grass;global dirt;global tree;global wood;global leaves;global sand;global gravel;global clay;global stone;global iron;global coal;global gold;global diamond;global none;global overlay;global head_front;global head_left;global head_back;global head_right grass = pygame.image.load('gras_erde_block.png') dirt = pygame.image.load('erde_block.png') tree = pygame.image.load('baum_block.png') wood = pygame.image.load('holz_block.png') leaves = pygame.image.load('blatt_block.png') sand = pygame.image.load('sand_block.png') gravel = pygame.image.load('schotter_block.png') clay = pygame.image.load('lehm_block.png') stone = pygame.image.load('stein_block.png') iron = pygame.image.load('eisen_block.png') coal = pygame.image.load('kohle_block.png') gold = pygame.image.load('gold_block.png') diamond = pygame.image.load('diamant_block.png') none = pygame.Surface((0,0)) overlay = pygame.image.load('overlay.png') head_front = pygame.image.load('kopf-vorne.png') head_left = pygame.image.load('kopf-links.png') head_back = pygame.image.load('kopf-hinten.png') head_right = pygame.image.load('kopf-rechts.png') newblocknames = [] nbnstr = [] for elem in new_blocks()[0]: name = elem()[0].popitem()[0] exec(name+" = pygame.image.load('"+elem()[2]+"')") exec("newblocknames.append("+name+")") nbnstr.append(name) blocktypes = [grass,dirt,tree,wood,leaves,sand,gravel,clay,stone,iron,coal,gold,diamond,none,overlay,head_front,head_left,head_back,head_right] blocktypes.extend(newblocknames) return blocktypes,none,newblocknames,nbnstr
def create_items(): """like create_blocks, just with items""" grassitem = pygame.image.load('gras_item.png') dirtitem = pygame.image.load('erde_item.png') treeitem = pygame.image.load('baum_item.png') wooditem = pygame.image.load('holz_item.png') leavesitem = pygame.image.load('blatt_item.png') sanditem = pygame.image.load('sand_item.png') gravelitem = pygame.image.load('schotter_item.png') clayitem = pygame.image.load('lehm_item.png') stoneitem = pygame.image.load('stein_item.png') ironitem = pygame.image.load('eisen_item.png') coalitem = pygame.image.load('kohle_item.png') golditem = pygame.image.load('gold_item.png') diamonditem = pygame.image.load('diamant_item.png') newitemnames = [] ninstr = [] for elem in new_blocks()[0]: name = elem()[0].popitem()[0] name += 'item' exec(name+"=pygame.image.load('"+elem()[3]+"')") exec("newitemnames.append("+name+")") ninstr.append(name[0:-4]) itemtypes = [grassitem,dirtitem,treeitem,wooditem,leavesitem,sanditem,gravelitem,clayitem,stoneitem,ironitem,coalitem,golditem,diamonditem] itemtypes.extend(newitemnames) return itemtypes, ninstr
def getMainRandomNumber(): random.seed(time.time()) return random.random() MAXWIDTH = 128 MAXLENGTH = 128 MAXHEIGHT = 4 SCREENWIDTH = 18 SCREENLENGTH = 18 diffPosx = 0 diffPosy = 0 RANDOMNUMBER = getMainRandomNumber() viewdirc = 0 ba = {"grass":"","dirt":"","tree":"","wood":"","leaves":"","sand":"","gravel":"","clay":"","stone":"","iron":"","coal":"","gold":"","diamond":"","none":""} da = {"grass":"","dirt":"","tree":"","wood":"","leaves":"","sand":"","gravel":"","clay":"","stone":"","iron":"","coal":"","gold":"","diamond":"","none":""} newblocks = new_blocks()[0] for elem in newblocks: ba.update(elem()[0]) da.update(elem()[1]) if __name__ == "__main__": pygame.init() window = pygame.display.set_mode((384,216))#create window #pygame.font.init() blocktypes,none,newblocknames,nbnstr = create_blocks()#creates all blocks itemsbar,ninstr = create_items()#creates all items itemsbar.append(none) for i in range(len(newblocknames)):#makes all new blocks global variables so they can be used in draw() exec(nbnstr[i]+"=newblocknames[i]") #blocks = generate_blockslist(none) blocks = None