本文整理汇总了Python中Ball.Ball.vel[0]方法的典型用法代码示例。如果您正苦于以下问题:Python Ball.vel[0]方法的具体用法?Python Ball.vel[0]怎么用?Python Ball.vel[0]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ball.Ball
的用法示例。
在下文中一共展示了Ball.vel[0]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from Ball import Ball [as 别名]
# 或者: from Ball.Ball import vel[0] [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:
#.........这里部分代码省略.........