当前位置: 首页>>代码示例>>Python>>正文


Python Display.paint_background方法代码示例

本文整理汇总了Python中display.Display.paint_background方法的典型用法代码示例。如果您正苦于以下问题:Python Display.paint_background方法的具体用法?Python Display.paint_background怎么用?Python Display.paint_background使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在display.Display的用法示例。


在下文中一共展示了Display.paint_background方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: BasicMovement

# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import paint_background [as 别名]

#.........这里部分代码省略.........
            x = random.randint(0, self.display.bgmax[0])

            s = Fass([200, y])
            self.barrels.add(s)


    def init_meanies(self, counter):

        move_index = 0
        while counter < self.number_meanies:

            mx = random.randint( 0, self.display.bgmax[0]-40 )
            my = random.randint( 0, self.display.bgmax[1]-40 )

            meanie = Meanie()
            meanie.state.set_random_move_index()
            meanie.rect.center = mx,my
            self.testgroup.add(meanie)

            if meanie.overlaps(self.testgroup):
                self.testgroup.remove(meanie)
                meanie.kill()
                self.init_meanies(counter)
            else:
                self.meanie_list.insert(counter,meanie)
                self.meanies.add(self.meanie_list[counter])
                counter += 1

        if counter == self.number_meanies:
            self.start_game()


    def start_game(self):
        del self.testgroup
        self.gameRunning = True
        self.mainloop()

    def mainloop(self):
        self.clock = pygame.time.Clock()
        self.player.rect.center = [120,220]

        while self.gameRunning:

            dirty = []
            
            self.clock.tick(FPS)
            self.framerate = self.clock.get_fps()

            self.display.paint_background(dirty)

            self.player.state.set_current_state(self)

            # blit player on screen
            d = self.display.paint_sprite(self.player)
            dirty.insert(len(dirty), d)
            
            self.steine.update()
            self.ladders.update()
            self.barrels.update(self)
            self.meanies.update(self, dirty)
            self.hud.showinfo(self, dirty)

            for e in pygame.event.get():

                if e.type == QUIT:
                    self.gameRunning = False
                    pygame.quit()
                    sys.exit()
                elif e.type == KEYDOWN:
                    
                    if e.key == K_ESCAPE:
                        self.gameRunning = False
                        pygame.quit()
                        sys.exit()
                    elif e.key == K_UP and self.player.state.climbing:
                        self.player.movement[1]= - self.player.speed
                            
                    elif e.key == K_DOWN and not self.player.state.falling and self.player.state.climbing:
                        self.player.movement[1]= self.player.speed
                        
                    elif e.key == K_LEFT:
                        if self.player.state.falling:
                            self.player.movement[0] = - self.player.speed/2
                        else:
                            self.player.movement[0] = - self.player.speed
                        
                    elif e.key == K_RIGHT:  
                        if self.player.state.falling:
                            self.player.movement[0] = self.player.speed/2
                        else:
                            self.player.movement[0] = self.player.speed
                
                elif e.type == KEYUP:
                    if e.key == K_UP or e.key == K_DOWN:
                        self.player.movement[1] = 0
                    elif e.key == K_LEFT or e.key == K_RIGHT:
                        self.player.movement[0] = 0

            self.player.update(self)
            pygame.display.update(dirty)
开发者ID:lupo72,项目名称:miner2011,代码行数:104,代码来源:main.py

示例2: Game

# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import paint_background [as 别名]
class Game(Display, Controller):
    
    def __init__(self):

        self.framerate = 0 
        self.number_meanies = 32
        self.bricks_in_level = 0
        self.display = Display()
        self.hud = Hud()
        pygame.key.set_repeat(100,5)
        self.meanies = pygame.sprite.Group()
        
        self.player = Charactor(self)
        self.player.speed = 2
       
        self.level = Level(self)

        self.level.load_level(0)
        self.start_game()
        
#        self.testgroup = pygame.sprite.Group()
#        self.init_meanies(0)
        
        


#    def init_meanies(self, counter):
#
#        while counter < self.number_meanies:
#
#            mx = random.randint( 0, self.display.bgmax[0]-40 )
#            my = random.randint( 0, self.display.bgmax[1]-40 )
#
#            meanie = Meanie()
#            meanie.state.set_random_move_index()
#            meanie.rect.center = mx,my
#            self.testgroup.add(meanie)
#
#            if meanie.overlaps(self.testgroup):
#                self.testgroup.remove(meanie)
#                meanie.kill()
#                self.init_meanies(counter)
#            else:
#                self.meanies.add(meanie)
#                counter += 1
#
#        if counter == self.number_meanies:
#            self.start_game()


    def start_game(self):

        self.gameRunning = True
        self.mainloop()

    def mainloop(self):
        self.clock = pygame.time.Clock()
        self.player.rect.center = [self.display.arena[0]/2, self.display.arena[1]/2]
        controller = Controller()
        while self.gameRunning:

            dirty = []
            
            self.clock.tick(FPS)
            self.framerate = self.clock.get_fps()

            self.display.paint_background(dirty)
            self.player.state.set_current_state(self)
            d = self.display.paint_sprite(self.player)
            dirty.insert(len(dirty), d)

            self.steine.update()
            self.ladders.update()
            self.barrels.update()
            self.meanies.update(dirty)

            self.hud.showinfo(self, dirty)
            controller.handle_keyboard_input(self.player)
            self.player.update()
            pygame.display.update(dirty)
开发者ID:lupo72,项目名称:miner2011,代码行数:82,代码来源:main.py

示例3: Game

# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import paint_background [as 别名]
class Game():
    framerate = 0
    number_meanies = 32
    
    def __init__(self):
        self.display = Display()
        self.player = Charactor(self)
        self.level = Level(self)
        self.hud = Hud()

        self.prepare_stage()

    def prepare_stage(self):
        self.level.load_level(0)
        self.start_game()


    def start_game(self):

        self.gameRunning = True
        self.mainloop()

    def mainloop(self):
        self.clock = pygame.time.Clock()
        self.player.rect.center = [self.display.arena[0]/2, self.display.arena[1]/2]
        controller = Controller()
        while self.gameRunning:

            dirty = []
            
            self.clock.tick(FPS)
            self.framerate = self.clock.get_fps()

            self.display.paint_background(dirty)
            self.player.state.set_current_state()
            d = self.display.paint_sprite(self.player)
            dirty.insert(len(dirty), d)

            self.steine.update()
            self.ladders.update()
            self.barrels.update()
            self.meanies.update(dirty)

            self.hud.showinfo(self, dirty)
            controller.handle_keyboard_input(self.player)
            self.player.update()

## Just for debugging - paint hitareas of charactor ##

            d = self.draw_hitarea(self.player.feet())
            dirty.insert(len(dirty), d)

            d = self.draw_hitarea(self.player.middle(), (0,0,255))
            dirty.insert(len(dirty), d)
            
            d = self.draw_hitarea(self.player.head(), (0,255,255))
            dirty.insert(len(dirty), d)

            pygame.display.update(dirty)

    def draw_hitarea(self, sprite, color=pygame.Color(255,0,0)):
        sfc = pygame.Surface([sprite.rect.width, sprite.rect.height])
        sfc.fill(color)
        dummy = pygame.sprite.Sprite()
        dummy.image = sfc
        dummy.rect = sprite.rect
        d = self.display.paint_sprite(dummy)
        
        return d
开发者ID:lupo72,项目名称:miner2011,代码行数:71,代码来源:main.py

示例4: Game

# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import paint_background [as 别名]

#.........这里部分代码省略.........
            meanie = Meanie()
            meanie.state.set_random_move_index()
            meanie.rect.center = mx,my
            self.testgroup.add(meanie)

            if meanie.overlaps(self.testgroup):
                self.testgroup.remove(meanie)
                meanie.kill()
                self.init_meanies(counter)
            else:
                self.meanies.add(meanie)
                counter += 1

        if counter == self.number_meanies:
            self.start_game()


    def start_game(self):
        del self.testgroup
        self.gameRunning = True
        self.mainloop()

    def mainloop(self):
        self.clock = pygame.time.Clock()
        self.player.rect.center = [self.display.arena[0]/2, self.display.arena[1]/2]
        controller = Controller()
        while self.gameRunning:

            dirty = []
            
            self.clock.tick(FPS)
            self.framerate = self.clock.get_fps()

            self.display.paint_background(dirty)
            self.player.state.set_current_state(self)
            d = self.display.paint_sprite(self.player)
            dirty.insert(len(dirty), d)

            self.steine.update()
            self.ladders.update()
            self.barrels.update()
            self.meanies.update(dirty)

            self.hud.showinfo(self, dirty)
            controller.handle_keyboard_input(self.player)
            
#            for e in pygame.event.get():
#
#                if e.type == QUIT:
#                    self.gameRunning = False
#                    pygame.quit()
#                    sys.exit()
#                elif e.type == KEYDOWN:
#
#                    if e.key == K_ESCAPE:
#                        self.gameRunning = False
#                        pygame.quit()
#                        sys.exit()
#                    elif e.key == K_UP and self.player.state.climbing:
#                        self.player.movement[1]= - self.player.speed
#
#                        self.player.face_up()
#
#                    elif e.key == K_DOWN \
#                     and not self.player.state.falling \
#                     and self.player.state.climbing:
开发者ID:lupo72,项目名称:miner2011,代码行数:70,代码来源:main_2.py


注:本文中的display.Display.paint_background方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。