Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while True:
- # keyboard input
- # Player movement
- pygame.mouse.set_visible(0)
- playerleft,playertop = pygame.mouse.get_pos()
- px, py = playerleft - playerwidth/2, playertop - playerheight/2
- # exit
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- break
- # bouncing the balls around the screen
- for i in range (ballnum):
- if ballpos[i][0]>width or ballpos[i][0]<0:
- speed[i][0] = speed[i][0]*-1
- ballpos[i][0] += seconds*speed[i][0]
- if ballpos[i][1]>height or ballpos[i][1]<0:
- speed[i][1] = speed[i][1]*-1
- ballpos[i][1] += seconds*speed[i][1]
- #collision
- for i in range (ballnum):
- if abs(ballpos[i][0]-px)<20 and abs(ballpos[i][1]-py)<20:
- ballvisible[i] = False
- score += 10
- ballpos[i] = [width + 100, height + 100]
- #timer incrementor
- seconds = clock.tick()/1000.0
- timer += seconds
- displaytimer = math.trunc(timer)
- #image display updates
- seconds = clock.tick()/1000.0
- screen.blit(background, (0,0))
- screen.blit(player, (px,py))
- scoretext = gamefont.render("Player Score: " + str(score), 2, [0,0,0])
- screen.blit(scoretext, [scoreXpos, 20])
- timertext = gamefont.render("Timer: " + str(displaytimer), 1, [0,0,0])
- screen.blit(timertext, [timerXpos, 50])
- # ball blitted through a for loop
- for i in range(ballnum):
- if ballvisible[i]:
- ballpos[i][0] += seconds*speed[i][0]
- ballpos[i][1] += seconds*speed[i][1]
- ballimage = ball[i]
- x = ballpos[i][0]
- y = ballpos[i][1]
- screen.blit(ballimage, (x,y))
- else:
- ballimage = ball[i]
- x = width-50
- y = height-(i+1)*ballspace
- screen.blit(ballimage, (x,y))
- pygame.display.update()
- #back to start screen
- if score == ballnum*10:
- pygame.time.delay(2000)
- game()
- if __name__ == '__main__':
- game()
Add Comment
Please, Sign In to add comment