コード例 #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))
コード例 #2
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))
コード例 #3
0
ファイル: AnimTestMod.py プロジェクト: FOSSRIT/fortunehunter
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))