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


Python Ball.x方法代码示例

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


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

示例1: main

# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import x [as 别名]
def main():
    """ Main function for the game. """
    pygame.init()

    # Set the width and height of the screen [width,height]
    size = [800, 600]
    screen = pygame.display.set_mode(size)

    pygame.display.set_caption("CMSC 150 is cool")

    # Loop until the user clicks the close button.
    done = False

    # Used to manage how fast the screen updates
    clock = pygame.time.Clock()


    theBall = Ball()
    theBall.x = 100
    theBall.y = 100
    theBall.change_x = 2
    theBall.change_y = 1
    theBall.color = [255,0,0]

    # -------- Main Program Loop -----------
    while not done:
        # ALL EVENT PROCESSING SHOULD GO BELOW THIS COMMENT
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True
        # ALL EVENT PROCESSING SHOULD GO ABOVE THIS COMMENT

        # ALL GAME LOGIC SHOULD GO BELOW THIS COMMENT

        # ALL GAME LOGIC SHOULD GO ABOVE THIS COMMENT

        # ALL CODE TO DRAW SHOULD GO BELOW THIS COMMENT

        # First, clear the screen to white. Don't put other drawing commands
        # above this, or they will be erased with this command.

        # ALL CODE TO DRAW SHOULD GO ABOVE THIS COMMENT

        screen.fill(BLACK)
        theBall.move()
        theBall.draw(screen)

        # Go ahead and update the screen with what we've drawn.
        pygame.display.flip()

        # Limit to 60 frames per second
        clock.tick(60)

    # Close the window and quit.
    # If you forget this line, the program will 'hang'
    # on exit if running from IDLE.
    pygame.quit()
开发者ID:tazz0009,项目名称:pygameTest1,代码行数:59,代码来源:ball_main.py

示例2:

# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import x [as 别名]
        if leftPaddle.bottom() < HEIGHT:
            leftPaddle.move_down()

    #move right paddle up
    if keys[K_UP]:
        if rightPaddle.top() > 0:
            rightPaddle.move_up()

    #move right paddle down
    if keys[K_DOWN]:
        if rightPaddle.bottom() < HEIGHT:
            rightPaddle.move_down()

    #handling ball motion
    if ball.x <= 0:
        ball.x, ball.y =  WIDTH/2, HEIGHT/2
        rightScore += 1
        scored = True

    elif ball.x >= WIDTH - ball.radius:
        ball.x, ball.y =  WIDTH/2, HEIGHT/2
        leftScore += 1
        scored = True

    if ball.y <= ball.radius or ball.y >= HEIGHT - ball.radius:
        ball.set_yspeed( -ball.yspeed )

    #ball - paddle collision detection
    if (  rightPaddle.left() < (ball.x + ball.radius) and rightPaddle.right() > (ball.x - ball.radius) ) and ( rightPaddle.top() < (ball.y + ball.radius) and rightPaddle.bottom() > (ball.y - ball.radius) ):
        ball.bounce( rightPaddle.top(), rightPaddle.bottom(), rightPaddle.height )
开发者ID:LeonardoChirivi,项目名称:pygames,代码行数:32,代码来源:pong.py

示例3: Ball

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

myball = Ball(10.0, 15.0, 0.0, -5.0)
print "The x coordinate of the myball object is ", myball.x
print "The y coordinate of the myball object is ", myball.y
myball.x = 2.

print "Now the x coordinate of the myball object is ", myball.x
开发者ID:CS98,项目名称:TheOneRepo,代码行数:10,代码来源:ball_example1.py


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