def readIndivSheet(fileType, path): spriteSheet1 = Spritesheet(("%s1%s" % (path, fileType))) spriteSheet2 = Spritesheet(("%s2%s" % (path, fileType))) instances = [] cnt = make while cnt > 0: animatedSprites = [] animatedSprites.append([ AnimatedSprite(spriteSheet1.img_extract(9, 1, 40, 40), ("%stext.txt" % (path)), 10), [(40 * cnt), 0, 2, 2] ]) animatedSprites[0][0].addImages(spriteSheet2.img_extract(9, 1, 40, 40)) animatedSprites.append([ AnimatedSprite(spriteSheet1.img_extract(9, 1, 40, 40), ("%stext.txt" % (path)), 10), [(40 * cnt), 40, 2, 2] ]) animatedSprites[1][0].addImages(spriteSheet2.img_extract(9, 1, 40, 40)) instances.append(animatedSprites) cnt = cnt - 1 trials = 0 while trials < 5: groups = len(instances) - 1 while groups >= 0: instances[groups][0][1][0] = 40 * groups instances[groups][0][1][1] = 0 instances[groups][1][1][0] = 40 * groups instances[groups][1][1][1] = 40 groups = groups - 1 changes = 0 start = time.time() while changes < 500: groups = len(instances) - 1 while groups >= 0: instances[groups][0][0].nextAnimFrame("anim1") instances[groups][1][0].nextAnimFrame("anim2") if instances[groups][0][1][0] < 0 or instances[groups][0][1][ 0] > WIDTH - 40: instances[groups][0][1][ 2] = instances[groups][0][1][2] * -1 if instances[groups][0][1][1] < 0 or instances[groups][0][1][ 1] > HEIGHT - 40: instances[groups][0][1][ 3] = instances[groups][0][1][3] * -1 if instances[groups][1][1][0] < 0 or instances[groups][1][1][ 0] > WIDTH - 40: instances[groups][1][1][ 2] = instances[groups][1][1][2] * -1 if instances[groups][1][1][1] < 0 or instances[groups][1][1][ 1] > HEIGHT - 40: instances[groups][1][1][ 3] = instances[groups][1][1][3] * -1 instances[groups][0][1][0] += instances[groups][0][1][2] instances[groups][0][1][1] += instances[groups][0][1][3] instances[groups][1][1][0] += instances[groups][1][1][2] instances[groups][1][1][1] += instances[groups][1][1][3] screen.blit(instances[groups][0][0].image, (instances[groups][0][0].image.get_rect().move( instances[groups][0][1][0], instances[groups][0][1][1]))) screen.blit(instances[groups][1][0].image, (instances[groups][1][0].image.get_rect().move( instances[groups][1][1][0], instances[groups][1][1][1]))) groups = groups - 1 pygame.display.flip() screen.fill((BACKGROUNDR, BACKGROUNDG, BACKGROUNDB)) changes = changes + 1 trials = trials + 1 print(trials) print(1 / ((time.time() - start) / 500))
def __init__(self, options, spelltype, magic_list, scene): """Initialize the EzMenu! options should be a sequence of lists in the format of [option_name, option_function]""" self.scene = scene self.buttons = [] self.options = options self.x = 0 self.y = 0 self.cols = 2 self.option = 0 self.width = 2 self.spelltype = spelltype self.magic_list = magic_list self.reference = [] lightning = [] fire = [] missile = [] heal = [] fire = Spritesheet(PUZZLE_PATH + "FireGlyph.gif").img_extract( 2, 2, 150, 150, (255, 0, 255)) lightning = Spritesheet(PUZZLE_PATH + "LightningGlyph.gif").img_extract( 2, 2, 150, 150, (255, 0, 255)) missile = Spritesheet(PUZZLE_PATH + "MissileGlyph.gif").img_extract( 2, 2, 150, 150, (255, 0, 255)) heal = Spritesheet(PUZZLE_PATH + "HealGlyph.gif").img_extract( 2, 2, 150, 150, (255, 0, 255)) if (spelltype == 0): #fire attack for i in range(4): self.buttons.append( DrawableObject([pygame.transform.scale(fire[i], (60, 60))], "")) #filler buttons for i in range(0, 2): self.buttons.append( DrawableObject( [pygame.transform.scale(lightning[i], (60, 60))], "")) random.seed() self.buttons.append( DrawableObject([ pygame.transform.scale(heal[random.randint(0, 3)], (60, 60)) ], "")) self.buttons.append( DrawableObject([ pygame.transform.scale(missile[random.randint(0, 3)], (60, 60)) ], "")) self.mainGlyph = pygame.image.load( PUZZLE_PATH + "FireGlyph.gif").convert_alpha() self.glyphs = fire elif (spelltype == 1): #lightning attack for i in range(4): self.buttons.append( DrawableObject( [pygame.transform.scale(lightning[i], (60, 60))], "")) #filler buttons for i in range(0, 2): self.buttons.append( DrawableObject([pygame.transform.scale(fire[i], (60, 60))], "")) random.seed() self.buttons.append( DrawableObject([ pygame.transform.scale(heal[random.randint(0, 3)], (60, 60)) ], "")) self.buttons.append( DrawableObject([ pygame.transform.scale(missile[random.randint(0, 3)], (60, 60)) ], "")) self.mainGlyph = pygame.image.load( PUZZLE_PATH + "LightningGlyph.gif").convert_alpha() self.glyphs = lightning elif (spelltype == 2): #missile attack for i in range(4): self.buttons.append( DrawableObject( [pygame.transform.scale(missile[i], (60, 60))], "")) #filler buttons for i in range(0, 2): self.buttons.append( DrawableObject( [pygame.transform.scale(lightning[i], (60, 60))], "")) random.seed() self.buttons.append( DrawableObject([ pygame.transform.scale(heal[random.randint(0, 3)], (60, 60)) ], "")) self.buttons.append( DrawableObject([ pygame.transform.scale(fire[random.randint(0, 3)], (60, 60)) ], "")) self.mainGlyph = pygame.image.load( PUZZLE_PATH + "MissileGlyph.gif").convert_alpha() self.glyphs = missile elif (spelltype == 3): #heal for i in range(4): self.buttons.append( DrawableObject([pygame.transform.scale(heal[i], (60, 60))], "")) #filler buttons for i in range(0, 2): self.buttons.append( DrawableObject( [pygame.transform.scale(lightning[i], (60, 60))], "")) random.seed() self.buttons.append( DrawableObject([ pygame.transform.scale(missile[random.randint(0, 3)], (60, 60)) ], "")) self.buttons.append( DrawableObject([ pygame.transform.scale(fire[random.randint(0, 3)], (60, 60)) ], "")) self.mainGlyph = pygame.image.load( PUZZLE_PATH + "HealGlyph.gif").convert_alpha() self.glyphs = heal deck = [0, 1, 2, 3, 4, 5, 6, 7] random.seed() random.shuffle(deck) tOptions = [] tButtons = [] for i in range(8): tOptions.append(self.options[deck[i]]) tButtons.append(self.buttons[deck[i]]) self.buttons = tButtons self.options = tOptions surf = pygame.Surface((60, 60)) surf.fill((4, 119, 152)) self.selectRect = DynamicDrawableObject([surf], "") self.selectRect.setPosition(297, 435) self.scene.addObject(self.selectRect) self.scene.addObjects(self.buttons) self.mainGlyph.set_colorkey((255, 0, 255), pygame.RLEACCEL) self.mainGlyphDO = DrawableObject([self.mainGlyph], "") self.mainGlyphDO.setPosition(485, 350) for image in self.glyphs: tempDO = DrawableObject([image], "", True) #tempDO.makeTransparent(True) self.reference.append(tempDO) self.scene.addObjects(self.reference) self.scene.addObject(self.mainGlyphDO) self.height = (len(self.options) * self.buttons[1].getYSize()) / self.cols