Advertisement
Guest User

Урряяяя

a guest
May 28th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.88 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. class Target:
  34.     def __init__ (self):
  35.         self.x = randint(15,800-15)
  36.         self.y = randint(15,600-15)
  37.         self.r = randint(2,15)
  38.         self.color = (0,100,255)
  39.     def move (self):
  40.         pygame.draw.rect(screen,self.color,([self.x,self.y],(15,15)),0)
  41.     def intersection(self):
  42.         if Gamer[1]+15>self.y and Gamer[1]<self.y+15 and Gamer[0]+15>self.x and Gamer[0]<self.x+15:  
  43.             return True
  44.         return False
  45.     def ChangeOfStation(self):
  46.         self.x = randint(15,800-15)
  47.         self.y = randint(15,600-15)        
  48. myfont = pygame.font.SysFont("monospace", 50)
  49. clock = pygame.time.Clock()
  50.  
  51. c = []
  52. for i in range(score+1):
  53.     c.append(NoTarget())
  54. target = Target()
  55.  
  56.  
  57. while done == False:
  58.     # обработчик событий
  59.     clock.tick(90)
  60.     for event in pygame.event.get():
  61.         if event.type == pygame.QUIT:
  62.             done = True
  63.         elif event.type == pygame.MOUSEMOTION:
  64.             Gamer = pygame.mouse.get_pos()
  65.         elif event.type ==pygame.KEYDOWN:
  66.             key = pygame.key.get_pressed()
  67.             if key[pygame.K_ESCAPE] == 1:
  68.                 done = True                
  69.            
  70.            
  71.        
  72.                                                    
  73.     # логика
  74.                          
  75.    
  76.    
  77.    
  78.            
  79.                
  80.    
  81.     # перерисовка
  82.     screen.fill([0,0,0])
  83.    
  84.     label = myfont.render(str(int(score)), 1, RED)
  85.     screen.blit(label, (0, 0))
  86.     if target.intersection() and not flag:
  87.         score+=1
  88.         c.append(NoTarget())
  89.         target.ChangeOfStation()
  90.        
  91.     for i in range(score+1):
  92.             c[i].move()
  93.             if c[i].intersection():
  94.                             flag=True    
  95.     if flag:
  96.         label = myfont.render("GAME OVER", 1, RED)
  97.         screen.blit(label, (100, 100))
  98.         labelOne = myfont.render("PRESS 'ESCAPE' TO EXIT", 1, RED)
  99.         screen.blit(labelOne, (100, 200))          
  100.     target.move()
  101.     pygame.draw.rect(screen,(255,255,255),(Gamer,(15,15)),0)
  102.     pygame.display.flip()    
  103. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement