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


Python Level.bottom方法代码示例

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


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

示例1: __init__

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import bottom [as 别名]

#.........这里部分代码省略.........
    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)

        offset = (self.width / 2) - self.player.rect.x, (self.height / 1.5) - self.player.rect.y
        while len(self.enemy_group) < self.max_badguys:
            xpos = random.randint(0, self.width-64) - offset[0]
            ypos = random.randint(0, self.height-64) - offset[1]
            h = HealthBar(4, 4, "res/healthbar.png", (32, 4))
            b = BadGuy((self.width, self.height), 4, h, (xpos, ypos))
            self.health_bar_sprites.add(h)
            self.enemy_group.add(b)

        keys = pygame.key.get_pressed()

        if keys[pygame.K_d]:
            self.player.move(pygame.K_d)
        elif keys[pygame.K_a]:
            self.player.move(pygame.K_a)

        if keys[pygame.K_SPACE] or keys[pygame.K_UP]:
            self.player.move(pygame.K_SPACE)

        if keys[pygame.K_RIGHT]:
            if self.player.can_shoot():
                bullet = Bullet("right", self.level.size, self.player.rect)
                self.player_bullet_group.add(bullet)
            self.player.shoot(pygame.K_RIGHT)
        elif keys[pygame.K_LEFT]:
            if self.player.can_shoot():
                bullet = Bullet("left", self.level.size, self.player.rect)
                self.player_bullet_group.add(bullet)
            self.player.shoot(pygame.K_LEFT)

        for guy in self.enemy_group:
            if guy.is_shooting():
                bullet = Bullet(guy.shoot_dir, self.level.size, guy.rect)
                self.enemy_bullet_group.add(bullet)

        # remove bullets that hit terrain
        pygame.sprite.groupcollide(self.enemy_bullet_group, self.level, True, False)
        pygame.sprite.groupcollide(self.player_bullet_group, self.level, True, False)

        damaged_guys = pygame.sprite.groupcollide(self.enemy_group, self.player_bullet_group, False, True)
        for d in damaged_guys:
            d.damage(1)
            if d.hp == 0:
                self.guys_killed += 1
                d.kill()

        if pygame.sprite.groupcollide(self.player_group, self.enemy_bullet_group, False, True):
            self.player_healthbar.set_hp(self.player_healthbar.cur_hp-1)
            if self.player_healthbar.cur_hp <= 0:
                self.state = "die"
                self.player.kill()



        guys = self.enemy_group.sprites() + self.player_group.sprites()

        for guy in guys:
            if guy.rect.top > self.level.bottom():
                guy.kill()
                if isinstance(guy, Player):
                    self.state = "die"
            else:
                guy.collide_with(self.level.collisions_for(guy))

        self.bdrop2.update()
        self.bdrop2.draw(self.screen, (offset[0]/4, offset[1]/4))
        self.bdrop1.update()
        self.bdrop1.draw(self.screen, (offset[0]/2, offset[1]/2))
        self.player_bullet_group.update()
        self.player_bullet_group.draw(self.screen, offset)
        self.enemy_bullet_group.update()
        self.enemy_bullet_group.draw(self.screen, offset)
        self.enemy_group.update(self.player.rect)
        self.enemy_group.draw(self.screen, offset)
        self.player_group.update()
        self.player_group.draw(self.screen, offset)
        self.health_bar_sprites.update()
        self.health_bar_sprites.draw(self.screen, offset)
        self.level.update()
        self.level.draw(self.screen, offset)
        self.player_hb_group.update()
        self.player_hb_group.draw(self.screen)
开发者ID:larsendt,项目名称:ld26,代码行数:104,代码来源:main.py


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