Ejemplo n.º 1
0
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))
Ejemplo n.º 2
0
def readIndivSheet(fileType, path):

 #creates instances of the spritesheet object witht he given sprite sheet images
 spriteSheet1 = Spritesheet(("%s1.%s"%(path,fileType)))
 spriteSheet2 = Spritesheet(("%s2.%s"%(path,fileType)))
 
 instances= []

 #Increments the cnt object
 cnt = make
 while cnt > 0:
  #animatedSprites is a list that hads two valuse in it. One for the first animation and one for the second animation.
  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 represents the number of trials that is perfor,ed for each test.
 trials = 0
 while trials < 5:

  #This loop is used to go through to the deepest level of this list and modify the positions of each set of animations so that they
  #are not all directly on top of each other.
  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 is a variable that is used to track how many frames have rendered.
  changes = 0
  #start represents the time the test starts
  start = time.time()
  #This is the loop that goes through until 500 frames have passed
  while changes < 500:
   #This loop goes through the first level of the instances list so that every group of animations is updated
   groups = len(instances) - 1
   while groups >= 0:
    instances[groups][0][0].nextFrame()
    instances[groups][1][0].nextFrame()

    #These two ifs are used to check if the first animation is off screen and adjust its velocity if it is so that it will come back
    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
       
    #These two ifs are used to check if the second animation is off screen and adjust its velocity if it is so that it will come back
    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
     

    #These two statements update the position of the first animation based on its velocity
    instances[groups][0][1][0] += instances[groups][0][1][2]
    instances[groups][0][1][1] += instances[groups][0][1][3]

    #These two statements update the position of the second animation based on its velocity
    instances[groups][1][1][0] += instances[groups][1][1][2]
    instances[groups][1][1][1] += instances[groups][1][1][3]

    #blits the new position of both animations
    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])))

    #iterates group object to next one to update
    groups = groups - 1
   #flips the display so that the new frames show up
   pygame.display.flip()
   #fills the screen with the background coor
   screen.fill((backgroundR,backgroundG,backgroundB))
   #iterates the changes object
   changes = changes + 1
  #iterates the trials object
  trials = trials + 1
  #prints what trial we are on and the frame rate.
  print(trials)
  print(1/((time.time() -start)/500))
Ejemplo n.º 3
0
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))
Ejemplo n.º 4
0
    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