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


Python Ball.y方法代码示例

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


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

示例1: run

# 需要导入模块: from Ball import Ball [as 别名]
# 或者: from Ball.Ball import y [as 别名]
def run():
    
    CENTER         = [COMMONS.WINDOWWIDTH/2, COMMONS.WINDOWHEIGHT/2]
    DISK_HOLE      = 10
    RADIUS         = 15
    PADDLE_SPEED   = 7
    PADDLE_HEIGHT  = 100
    PADDLE_WIDTH   = 10

    BALL_VELS      = [[3,1], [2,1], [-3,1], [3,-1], [-3,-1], [-2,-2], [-2,1], [2,2]]
    BALL_VEL       = random.choice(BALL_VELS)
    WIN_BANNER_POS = {'left': [100, 50], 'right': [458, 50]}

    ball           = Ball(CENTER, RADIUS, BALL_VEL, DISK_HOLE, COMMONS.REDDISH)
    paddle_1       = Paddle(0, 150, PADDLE_WIDTH, PADDLE_HEIGHT, COMMONS.BLUEISH, PADDLE_SPEED, ball)
    paddle_2       = Paddle(COMMONS.WINDOWWIDTH - PADDLE_WIDTH, 150, PADDLE_WIDTH, PADDLE_HEIGHT, COMMONS.BLUEISH, PADDLE_SPEED, ball)
    ball_copy 	   = copy.deepcopy(ball)

    scoreLeft 	   = 0
    scoreRight     = 0

    pygame.init()
    pygame.event.set_allowed([QUIT, KEYDOWN, KEYUP])

    spaces         = "                            " # hack to display both scores at once (avoid double blitting the score Font objects)
    score_Font     = pygame.font.SysFont("Verdana", 35)
    windowSurface  = pygame.display.set_mode((COMMONS.WINDOWWIDTH, COMMONS.WINDOWHEIGHT), DOUBLEBUF, 32)

    pygame.display.set_caption('Pong')
    pygame.draw.circle(windowSurface, ball.color, (ball.x, ball.y), ball.radius)
    pygame.draw.circle(windowSurface, COMMONS.WHITE, (ball.x, ball.y), ball.radius + 2, ball.radius - DISK_HOLE)
    pygame.display.update()

    time.sleep(1)        

    while max(scoreLeft, scoreRight) < 3:
        in_game        = True
        paddle_1_down  = paddle_1_up = paddle_2_down = paddle_2_up = False
        mainCLock      = pygame.time.Clock()
        
        while in_game == True:
            for event in pygame.event.get():
                
                if event.type == KEYDOWN:
                    if event.key == K_DOWN:
                        paddle_2_down = True
                    elif event.key == K_UP:
                        paddle_2_up = True
                    elif event.key == ord('s'):
                        paddle_1_down = True
                    elif event.key == ord('w'):
                        paddle_1_up = True
                    elif event.key == ord('r'):
                        scoreRight  = scoreLeft = 0
                        ball.x      = COMMONS.WINDOWWIDTH/2
                        ball.y      = COMMONS.WINDOWHEIGHT/2
                        ball.vel    = random.choice(BALL_VELS)
                        in_game     = True
                    elif event.key == ord('q'):
                        pygame.quit()
                        sys.exit()

                elif event.type == KEYUP:
                    if event.key == K_DOWN:
                        paddle_2_down = False
                    elif event.key == K_UP:
                        paddle_2_up = False
                    elif event.key == ord('s'):
                        paddle_1_down = False
                    elif event.key == ord('w'):
                        paddle_1_up = False
                
                elif event.type == QUIT:
                    pygame.quit()
                    sys.exit()
                    
            if paddle_1_down:
                paddle_1.move(1)
            elif paddle_1_up:
                paddle_1.move(-1)
            if paddle_2_down:
                paddle_2.move(1)
            elif paddle_2_up:
                paddle_2.move(-1)
                
            ball.check_board_bounce() 
            ball.move()   
            
            if ball.x - ball.radius <= 0: 
                if ball.y >= paddle_1.y and ball.y <= paddle_1.y + paddle_1.height:
                    ball.vel[0] = -int(math.floor(1.1*ball.vel[0]))
                else:
                    scoreRight += 1
                    in_game = False
                    
                    
            elif ball.x + ball.radius >= COMMONS.WINDOWWIDTH:
                if ball.y >= paddle_2.y and ball.y <= paddle_2.y + paddle_2.height:
                    ball.vel[0] = int(math.floor(-1.1*ball.vel[0]))
                else:
#.........这里部分代码省略.........
开发者ID:rectified95,项目名称:Pong,代码行数:103,代码来源:Pong.py


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