162
else:
self.state = STATE_GAME_OVER
def show_stats(self):
if self.font:
font_surface = self.font.render("SCORE: " +
str(self.score) + "LIVES: " + str(self.lives), False,
WHITE)
self.screen.blit(font_surface, (205,5))
def show_message(self,message):
if self.font:
size = self.font.size(message)
font_surface = self.font.render(message,False,
WHITE)
x = (SCREEN_SIZE[0] - size[0]) / 2
y = (SCREEN_SIZE[1] - size[1]) / 2
self.screen.blit(font_surface, (x,y))
def run(self):
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
self.clock.tick(50)
self.screen.fill(BLACK)
self.check_input()
if self.state == STATE_PLAYING:
self.move_ball()
self.handle_collisions()
elif self.state == STATE_BALL_IN_PADDLE:
self.ball.left = self.paddle.left + self.
paddle.width / 2
self.ball.top = self.paddle.top - self.ball.
height
self.show_message("PRESS SPACE TO LAUNCH
THE BALL")
elif self.state == STATE_GAME_OVER:
self.show_message("GAME OVER. PRESS ENTER
TO PLAY AGAIN")
Достарыңызбен бөлісу: