Guest User

Untitled

a guest
Jul 18th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.36 KB | None | 0 0
  1.    while True:
  2.      
  3.            
  4.         # keyboard input
  5.         # Player movement
  6.         pygame.mouse.set_visible(0)
  7.         playerleft,playertop = pygame.mouse.get_pos()
  8.         px, py = playerleft - playerwidth/2, playertop - playerheight/2
  9.              
  10.         # exit
  11.         for event in pygame.event.get():
  12.             if event.type == pygame.QUIT:
  13.                 pygame.quit()
  14.                 break
  15.  
  16.         # bouncing the balls around the screen
  17.  
  18.         for i in range (ballnum):
  19.             if ballpos[i][0]>width or ballpos[i][0]<0:
  20.                 speed[i][0] = speed[i][0]*-1
  21.                 ballpos[i][0] += seconds*speed[i][0]
  22.             if ballpos[i][1]>height or ballpos[i][1]<0:
  23.                 speed[i][1] = speed[i][1]*-1          
  24.                 ballpos[i][1] += seconds*speed[i][1]
  25.  
  26.         #collision
  27.  
  28.         for i in range (ballnum):        
  29.             if abs(ballpos[i][0]-px)<20 and abs(ballpos[i][1]-py)<20:
  30.                 ballvisible[i] = False
  31.                 score += 10
  32.                 ballpos[i] = [width + 100, height + 100]
  33.  
  34.  
  35.         #timer incrementor
  36.  
  37.         seconds = clock.tick()/1000.0
  38.         timer += seconds
  39.         displaytimer = math.trunc(timer)
  40.  
  41.         #image display updates
  42.         seconds = clock.tick()/1000.0
  43.         screen.blit(background, (0,0))
  44.         screen.blit(player, (px,py))
  45.         scoretext = gamefont.render("Player Score: " + str(score), 2, [0,0,0])
  46.         screen.blit(scoretext, [scoreXpos, 20])
  47.         timertext = gamefont.render("Timer: " + str(displaytimer), 1, [0,0,0])
  48.         screen.blit(timertext, [timerXpos, 50])
  49.  
  50.             # ball blitted through a for loop
  51.         for i in range(ballnum):
  52.             if ballvisible[i]:
  53.                 ballpos[i][0] += seconds*speed[i][0]
  54.                 ballpos[i][1] += seconds*speed[i][1]
  55.                 ballimage = ball[i]
  56.                 x = ballpos[i][0]
  57.                 y = ballpos[i][1]
  58.                 screen.blit(ballimage, (x,y))
  59.             else:
  60.                 ballimage = ball[i]
  61.                 x = width-50
  62.                 y = height-(i+1)*ballspace
  63.                 screen.blit(ballimage, (x,y))
  64.  
  65.         pygame.display.update()
  66.  
  67.         #back to start screen
  68.         if score == ballnum*10:
  69.                 pygame.time.delay(2000)
  70.                 game()
  71.  
  72. if __name__ == '__main__':
  73.     game()
Add Comment
Please, Sign In to add comment