本文整理汇总了Python中ball.Ball.brickCollide方法的典型用法代码示例。如果您正苦于以下问题:Python Ball.brickCollide方法的具体用法?Python Ball.brickCollide怎么用?Python Ball.brickCollide使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ball.Ball
的用法示例。
在下文中一共展示了Ball.brickCollide方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gameLoop
# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import brickCollide [as 别名]
#.........这里部分代码省略.........
self.ballLaunched = True
# Go back to menu
if event.key == K_m:
self.ballSprites.empty()
self.paddleSprite.empty()
self.level.brickSprites.empty()
return "menu"
############# BALL MOVER ###############################
if self.ballLaunched:
for ball in self.ballSprites:
ballLost = ball.move(self.width,
self.height,
seconds,
self.paddle)
# Check if ball went past paddle
if ballLost:
ball.kill()
if not self.ballSprites:
self.mainBall = Ball((self.paddle.x, self.paddle.y),
self.paddle.height)
self.ballSprites.add(self.mainBall)
for i in range(self.numBalls):
ball = Ball((self.paddle.x, self.paddle.y),
self.paddle.height)
self.ballSprites.add(ball)
self.ballLaunched = False
# Lose a life, fill in circle where one used to be
self.lives -= 1
self.drawScore()
self.drawName()
pygame.draw.circle(self.screen,
(0, 0, 0),
(self.lifeX + ((self.lives - 1)*10), self.lifeY),
self.lifeRadius)
# End game if lives are gone
if self.lives == 0:
return "lost"
############# COLLISION DETECTION ###########################
# Collision detection between ball and paddle
hitPaddle = pygame.sprite.spritecollide(self.paddle,
self.ballSprites,
False)
if hitPaddle:
# For levels that have constant rotation
if self.level.alwaysRotating:
if self.level.rotation == 360:
self.level.rotation = 90
else:
self.level.rotation += 90
for ball in hitPaddle:
ball.paddleCollide(self.paddle)
# Collision detection between ball and brick
if not self.level.brickSprites:
try:
BreakoutMain.levels[self.currentLevel + 1]
self.currentLevel += 1
self.ballSprites.empty()
self.paddleSprite.empty()
self.level.brickSprites.empty()
self.ballLaunched = False
return "next"
except IndexError:
return "won"
else:
for ball in self.ballSprites:
hitBricks = pygame.sprite.spritecollide(ball,
self.level.brickSprites,
True)
ball.brickCollide(hitBricks)
for brick in hitBricks:
self.screen.blit(self.level.background,
(brick.rect.x, brick.rect.y),
brick.rect)
self.score += 1
# Redraw score
self.drawScore()
############# SPRITE REFRESH #################################
# Redraw lives left
self.drawLives()
# Redraw sprites
self.paddleSprite.draw(self.screen)
self.ballSprites.draw(self.screen)
if self.level.rotation != 0:
rotatedScreen = pygame.transform.rotate(self.screen, self.level.rotation)
self.screen.blit(rotatedScreen, (0, 0))
self.level.rotated = True
pygame.display.flip()
# Keep track of time elapsed
self.elapsed = self.clock.tick(60)