本文整理汇总了Python中Ball.Ball.reset方法的典型用法代码示例。如果您正苦于以下问题:Python Ball.reset方法的具体用法?Python Ball.reset怎么用?Python Ball.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ball.Ball
的用法示例。
在下文中一共展示了Ball.reset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NetworkControlledPong
# 需要导入模块: from Ball import Ball [as 别名]
# 或者: from Ball.Ball import reset [as 别名]
#.........这里部分代码省略.........
self.ball.vely = 0
self.ball.velx = 0
self.paused = True
def resume(self):
self.ball.vely = self.tmpBallVelY
self.ball.velx = self.tmpBallVelX
self.paused = False
def run(self):
"""Runs the game. Contains the game loop that computes and renders
each frame."""
print 'Waiting for enough controllers'
while not self.started:
if self.handleEvents() == False:
self.uiServer.stop()
return 0
else:
time.sleep(0)
print 'Enough controllers registered'
print 'Starting Event Loop'
self.running = True
self.paused = False
while self.running:
self.clock.tick(30)
self.running = self.handleEvents()
self.manageBall()
for sprite in self.sprites:
sprite.update()
self.sprites.clear(self.window, self.background) # clears the window where the sprites currently are, using the background
dirty = self.sprites.draw(self.window) # calculates the 'dirty' rectangles that need to be redrawn
pygame.display.update(dirty) # updates just the 'dirty' areas
print 'Quitting. Thanks for playing'
self.uiServer.stop()
return 0
def handleEvents(self):
"""Poll for PyGame events and behave accordingly. Return false to stop
the event loop and end the game."""
for event in pygame.event.get():
if event.type == QUIT:
return False
elif event.type == USEREVENT:
if self.ball.velx == 0 and self.ball.vely == 0 and not self.paused:
self.ball.serve()
if event.key.lower() == "up":
self.paddleMap[event.id].up()
if event.key.lower() == "down":
self.paddleMap[event.id].down()
if event.key.lower() == "stop":
return False
return True
def manageBall(self):
self.ball.rect.x += self.ball.velx
self.ball.rect.y += self.ball.vely
if self.ball.rect.top < 0:
self.ball.rect.top = 1
self.ball.vely *= -1
self.pongsound.play()
elif self.ball.rect.bottom > 400:
self.ball.rect.bottom = 399
self.ball.vely *= -1
self.pongsound.play()
if self.ball.rect.left < 0:
self.scoreImage.right()
self.ball.reset()
return
elif self.ball.rect.right > 800:
self.scoreImage.left()
self.ball.reset()
return
collided = pygame.sprite.spritecollide(self.ball, [self.leftpaddle, self.rightpaddle], dokill=False)
if len(collided) > 0:
hitpaddle = collided[0]
self.ball.velx *= -1
self.ball.rect.x += self.ball.velx
self.ball.vely += hitpaddle.velocity/3.0
self.pingsound.play()