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


Python Ball.pause方法代码示例

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


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

示例1: __init__

# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import pause [as 别名]
class Arkanoid:

    def __init__(self):
    
        from utilities import pygame, load_stages
        from text import Score, Timer, Name, Text
        from paddle import Paddle
        from ball import Ball
        from brick import Brick
        from stage import Stage
        
        C = Constants()
        self.C = C
        self.pygame = pygame

        # setup FPS governor
        self.clock = pygame.time.Clock()

        # set the window size
        divTop = int(C.DIV_POS*C.SIZE[1]) # top of divider. Affects bounds for ball
        divBot = divTop + C.DIV_WIDTH
        self.screen = pygame.display.set_mode(C.SIZE)
        area = pygame.Rect(0, divBot, C.SIZE[0], C.SIZE[1]-divBot)

        # create game screen objects/sprites
        self.score = Score(C.SCORE_POS, self.screen, C.SCORE_START, C.SCORE_COLOR, C.SCORE_SIZE)
        self.scoreText = Text(C.S_LABEL_POS, self.screen, C.S_LABEL_TEXT, C.S_LABEL_COLOR, C.S_LABEL_SIZE)
        self.timer = Timer(C.TIMER_POS, self.screen, C.TIMER_START, C.TIMER_COLOR, C.TIMER_SIZE)
        self.timerText = Text(C.T_LABEL_POS, self.screen, C.T_LABEL_TEXT, C.T_LABEL_COLOR, C.T_LABEL_SIZE)
        self.name = Name(C.NAME_POS, self.screen, '', C.NAME_COLOR)
        self.paddle = Paddle(area)
        self.ball = Ball(area)
        self.stages = load_stages(self.screen)
        self.divider = (self.screen, C.DIV_COLOR, [0, divTop], [C.SIZE[0], divTop], C.DIV_WIDTH)
        self.sprites = pygame.sprite.RenderPlain((self.paddle, self.ball))

        self.paused = True # flag to indicate if the stage is paused or moving 
        self.pausedReset = False # flag to indicate pause was due to reset, in which case dont pause timer


    # stage_event() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
    def stage_event(self, event):
        """Handles stage events"""
        
        C = self.C
        
        # quit the game
        if event.type == C.QUIT: return 2
        elif event.type == C.KEYDOWN:
        
            # quit the game
            if event.key == C.K_ESCAPE: return 2
            
            # move the paddle
            else: self.paddle.move(event.key)
            
        # key has been un-pressed
        elif event.type == C.KEYUP:
            
            # stop moving the paddle
            self.paddle.move(None)
        
            # reset the ball and paddle (dont reset stage)
            if event.key == C.K_r:
                self.ball.reset()
                self.paddle.reset()
                self.paused = True
                self.pausedReset = True
                
            # pause the game
            elif event.key == C.K_p:
                self.ball.pause()
                self.paddle.pause()
                if self.paused: self.paused = False
                else: self.paused = True
                
            elif event.key == C.K_SPACE:
            
                # start the stage
                if self.paused:
                    self.ball.pause()
                    if self.paddle.paused: self.paddle.pause()
                    self.paused = False
                    self.pausedReset = False
                    
        return 0
        

    # update_ball() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
    def update_ball(self):
        """Updates the ball and does ball related actions"""

        from brick import Brick
        
        if self.ball.inbounds:
            if (
                isinstance(self.ball.bouncedOff, Brick) and
                self.ball.bouncedOff.destroyed
            ): 
                self.score.change_by(self.ball.bouncedOff.points * self.timer.value)
#.........这里部分代码省略.........
开发者ID:DuhPhd,项目名称:Arkanoid,代码行数:103,代码来源:arkanoid.py


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