本文整理汇总了Python中ball.Ball.change_x方法的典型用法代码示例。如果您正苦于以下问题:Python Ball.change_x方法的具体用法?Python Ball.change_x怎么用?Python Ball.change_x使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ball.Ball
的用法示例。
在下文中一共展示了Ball.change_x方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import change_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()
示例2: str
# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import change_x [as 别名]
if event.key == K_w:
paddle1.change_y += 6
elif event.key == K_s:
paddle1.change_y -= 6
elif event.key == K_UP:
paddle2.change_y += 6
elif event.key == K_DOWN:
paddle2.change_y -= 6
# Updates the game objects
for paddle in paddle_list:
paddle.update()
ball.update()
if ball.rect.right >= constants.screen_width or ball.rect.x <= 0:
if ball.change_x >= 0:
paddle1.score += 1
else:
paddle2.score += 1
ball.change_x = 6
ball.change_y = 6
ball.rect.topleft = (random.randint(0, 800), random.randint(0, 600))
if paddle1.score >= 10 or paddle2.score >= 10:
scoreBoard.update(str(paddle1.score) + " | " + str(paddle2.score))
text_functions.showText("Game Over", (constants.screen_width/2, constants.screen_height/2), screen)
pygame.time.wait(500)
pygame.display.update()
terminate()
scoreBoard.update(str(paddle1.score) + " | " + str(paddle2.score))
pygame.display.update()
clock.tick(constants.fps)