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


Python Die.draw方法代码示例

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


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

示例1: __init__

# 需要导入模块: from die import Die [as 别名]
# 或者: from die.Die import draw [as 别名]
class LD26Main:
    def __init__(self, width=800,height=600):
        pygame.init()
        self.width = width
        self.height = height
        self.screen = pygame.display.set_mode((self.width, self.height))
        self.state = "menu"
        pygame.display.set_caption("Shoot Guys")

    def load_sprites(self):
        self.player_group = CameraSpriteGroup()
        self.player_bullet_group = CameraSpriteGroup()
        self.player_max_hp = 20
        self.player_healthbar = HealthBar(self.player_max_hp, self.player_max_hp, "res/player_healthbar.png", (128, 16))
        self.player_healthbar.rect.x = -55
        self.player_healthbar.rect.y = 10
        self.player_hb_group = CameraSpriteGroup()
        self.player_hb_group.add(self.player_healthbar)

        self.enemy_group = CameraSpriteGroup()
        self.enemy_bullet_group = CameraSpriteGroup()
        self.health_bar_sprites = CameraSpriteGroup()
        self.max_badguys = 0
        self.guys_killed = 0

        self.levels = [{"img":"res/levels/level1.png", "badguys":2, "goal":6}, {"img":"res/levels/level2.png", "badguys":5, "goal":10}]
        self.cur_level = 0

        self.load_level(0)
        self.menu = Menu()
        self.win = Win()
        self.die = Die()

    def load_level(self, levelnum):
        if levelnum >= len(self.levels):
            self.state = "win"
        else:
            leveldict = self.levels[levelnum]
            self.player = Player((self.width, self.height))
            self.player_group.add(self.player)
            self.level = Level((self.width, self.height), leveldict["img"])
            self.bdrop1 = Backdrop(self.level.dims, 1)
            self.bdrop2 = Backdrop(self.level.dims, 2)
            self.max_badguys = leveldict["badguys"]
            self.guys_killed = 0
            self.kill_goal = leveldict["goal"]
            self.player_healthbar.set_hp(self.player_max_hp)

    def go(self):
        self.load_sprites()
        self.clock = pygame.time.Clock()
        while 1:
            self.clock.tick(60)
            self.screen.fill((0, 0, 0))

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
                elif event.type == pygame.KEYDOWN:
                    if event.key == K_ESCAPE:
                        if self.state == "game":
                            self.state = "menu"
                        else:
                            sys.exit()

                    elif event.key == K_RETURN:
                        if self.state == "menu":
                            self.state = "game"
                        elif self.state == "win" or self.state == "die":
                            self.load_level(0)
                            self.state = "game"

            if self.state == "menu":
                self.do_menu()
            elif self.state == "game":
                self.do_main_game()
            elif self.state == "win":
                self.do_win()
            else:
                self.do_die()

            pygame.display.flip()

    def do_die(self):
        self.die.update()
        self.die.draw(self.screen)

    def do_win(self):
        self.win.update()
        self.win.draw(self.screen)

    def do_menu(self):
        self.menu.update()
        self.menu.draw(self.screen)

    def do_main_game(self):
        if self.guys_killed > self.kill_goal:
            self.cur_level += 1
            self.player.kill()
            self.load_level(self.cur_level)
#.........这里部分代码省略.........
开发者ID:larsendt,项目名称:ld26,代码行数:103,代码来源:main.py


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