Advertisement
Guest User

так лучше

a guest
May 28th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.07 KB | None | 0 0
  1. import pygame
  2. from random import randint
  3. pygame.init()
  4.  
  5. BLACK = (0, 0, 0)
  6. WHITE = (255, 255, 255)
  7. GREEN = (0, 255, 0)
  8. RED = (255, 0, 0)
  9. BLUE = (0, 0, 255)
  10.  
  11. def sign (d):
  12.     if d>0 : return 1
  13.     else: return -1
  14. global score
  15. global flag
  16. flag=False
  17. score= 0
  18. size = [800,600]
  19. screen = pygame.display.set_mode(size)
  20. done = False
  21. class NoTarget:
  22.     def __init__ (self):
  23.         self.x = randint(15,800-15)
  24.         self.y = randint(15,600-15)
  25.         self.r = randint(2,15)
  26.         self.color = (255,0,0)
  27.     def move (self):
  28.         pygame.draw.rect(screen,self.color,([self.x,self.y],(15,15)),0)
  29.     def intersection(self):
  30.         if Gamer[1]+15>self.y and Gamer[1]<self.y+15 and Gamer[0]+15>self.x and Gamer[0]<self.x+15:
  31.             return True
  32.         return False
  33.     def ChangeOfStation(self):
  34.             self.x = randint(15,800-15)
  35.             self.y = randint(15,600-15)      
  36. class Target:
  37.     def __init__ (self):
  38.         self.x = randint(15,800-15)
  39.         self.y = randint(15,600-15)
  40.         self.r = randint(2,15)
  41.         self.color = (0,100,255)
  42.     def move (self):
  43.         pygame.draw.rect(screen,self.color,([self.x,self.y],(15,15)),0)
  44.     def intersection(self):
  45.         if Gamer[1]+15>self.y and Gamer[1]<self.y+15 and Gamer[0]+15>self.x and Gamer[0]<self.x+15:  
  46.             return True
  47.         return False
  48.     def ChangeOfStation(self):
  49.         self.x = randint(15,800-15)
  50.         self.y = randint(15,600-15)        
  51. myfont = pygame.font.SysFont("monospace", 50)
  52. clock = pygame.time.Clock()
  53.  
  54. c = []
  55. for i in range(score+1):
  56.     c.append(NoTarget())
  57. target = Target()
  58.  
  59.  
  60. while done == False:
  61.     # обработчик событий
  62.     clock.tick(90)
  63.     for event in pygame.event.get():
  64.         if event.type == pygame.QUIT:
  65.             done = True
  66.         elif event.type == pygame.MOUSEMOTION:
  67.             Gamer = pygame.mouse.get_pos()
  68.         elif event.type ==pygame.KEYDOWN:
  69.             key = pygame.key.get_pressed()
  70.             if key[pygame.K_ESCAPE] == 1:
  71.                 done = True                
  72.            
  73.            
  74.        
  75.                                                    
  76.     # логика
  77.                          
  78.    
  79.    
  80.    
  81.            
  82.                
  83.    
  84.     # перерисовка
  85.     screen.fill([0,0,0])
  86.    
  87.     label = myfont.render(str(int(score)), 1, RED)
  88.     screen.blit(label, (0, 0))
  89.     if target.intersection() and not flag:
  90.         score+=1
  91.         c.append(NoTarget())
  92.         target.ChangeOfStation()
  93.         for i in range(score+1):
  94.             c[i].ChangeOfStation()
  95.     for i in range(score+1):
  96.             c[i].move()
  97.             if c[i].intersection():
  98.                             flag=True
  99.                
  100.     if flag:
  101.         label = myfont.render("GAME OVER", 1, RED)
  102.         screen.blit(label, (100, 100))
  103.         labelOne = myfont.render("PRESS 'ESCAPE' TO EXIT", 1, RED)
  104.         screen.blit(labelOne, (100, 200))          
  105.     target.move()
  106.     pygame.draw.rect(screen,(255,255,255),(Gamer,(15,15)),0)
  107.     pygame.display.flip()    
  108. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement