Пример #1
0
    def bgscroll(self):
    #Handles Background Updating

    #Backgrounds are special Obstacle instances with no Collision check
    #Background (re)placement, updating, and draw function calling
    #is handled here, unlike other Obstacle instances

        if ( self.bginit ):
        #Initial Background placement, runs only when Game instance starts
           sl = random.choice(streetlist)
           street1 = Obstacle(sl[0], sl[1], sl[2], sl[3], sl[4])
           bg1 = Obstacle(self.bg, -21, False, 1, 0)
           house1 = Obstacle(self.house, 0, False, 1.5, 0)
           sl = random.choice(streetlist)
           street2 = Obstacle(sl[0], sl[1], sl[2], sl[3], sl[4])
           bg2 = Obstacle(self.bg, -21, False, 1, 0)
           house2 = Obstacle(self.house, 0, False, 1.5, 0)

           self.BgGr.add(street1, street2, bg1, bg2, house1, house2)

        #Declaring local position variables
           street1.xpos = 0
           bg1.xpos = 0
           house1.xpos = 0
           street2.xpos= 1300
           bg2.xpos = 1000
           house2.xpos = 1000

           self.bginit = False


        for item in self.BgGr:
        #After initial placement, only repositioning and drawing takes place
        #Level progress calculation is based on Background instances which
        #left the screen
            item.update()
            if item.xpos <= -(item.rect[2]):
               item.xpos = item.rect[2]
               self.levelprogress += 1
            item.draw(self.gameDisplay)