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


Python Level.map方法代码示例

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


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

示例1: __init__

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

#.........这里部分代码省略.........
            if game_started is True:
                self.ball.move(ball_direction_y)
                self.ball.move(ball_direction_x)

            # ball/boundary collision control
            # left / right of border
            if self.ball.left <= self.window_border_left:
                ball_direction_x = self.ball.direction.RIGHT
            if self.ball.right >= self.window_border_right:
                ball_direction_x = self.ball.direction.LEFT
            if self.ball.top <= self.window_border_top:
                ball_direction_y = self.ball.direction.DOWN
            # bottom of border
            if self.ball.bottom >= self.window_border_bottom:
                deaths += 1
                game_started = False

            # ball/paddle collision control
            if self.ball.bottom + self.ball.velocity()/2 >= self.paddle.top and self.ball.top < self.paddle.bottom \
                    and ball_direction_y == self.ball.direction.DOWN:

                if self.ball.left >= self.paddle.left and self.ball.right <= self.paddle.right:
                    ball_direction_y = self.ball.direction.opposite(ball_direction_y)

                if self.ball.left >= self.paddle.left \
                        and self.ball.right <= self.paddle.left + self.paddle_divert_range \
                        and ball_direction_x == self.ball.direction.RIGHT \
                        or self.ball.right <= self.paddle.right \
                        and self.ball.left >= self.paddle.right - self.paddle_divert_range \
                        and ball_direction_x == self.ball.direction.LEFT:
                    ball_direction_x = self.ball.direction.opposite(ball_direction_x)

            # ball/block collision control
            for block in self.level.map():

                # go to the next level once map is cleared
                if self.level.cleared():
                    game_started = False

                block_rect = pygame.Rect(block[1])
                if self.ball.top >= block_rect.top \
                        and self.ball.bottom <= block_rect.bottom \
                        and self.ball.left - self.ball.velocity() <= block_rect.right < self.ball.right:
                    ball_direction_x = self.ball.direction.opposite(ball_direction_x)
                    self.level.hit(block)

                    score += 1

                    if score % 4 == 0 and level != 5:
                        level += 1
                        self.ball.velocity(self.ball.velocity() + 2)

                if self.ball.top >= block_rect.top \
                        and self.ball.bottom <= block_rect.bottom \
                        and self.ball.right + self.ball.velocity() >= block_rect.left > self.ball.left:
                    ball_direction_x = self.ball.direction.opposite(ball_direction_x)
                    self.level.hit(block)

                    score += 1

                    if score % 4 == 0 and level != 3:
                        level += 1
                        self.ball.velocity(self.ball.velocity() + 2)

                # bottom of block, top of ball
                if self.ball.right <= block_rect.right \
开发者ID:edkotkas,项目名称:PyBreak,代码行数:70,代码来源:game.py


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