Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- from random import randint
- pygame.init()
- BLACK = (0, 0, 0)
- WHITE = (255, 255, 255)
- GREEN = (0, 255, 0)
- RED = (255, 0, 0)
- BLUE = (0, 0, 255)
- def sign (d):
- if d>0 : return 1
- else: return -1
- global score
- global flag
- flag=False
- score= 0
- size = [800,600]
- screen = pygame.display.set_mode(size)
- done = False
- class NoTarget:
- def __init__ (self):
- self.x = randint(15,800-15)
- self.y = randint(15,600-15)
- self.r = randint(2,15)
- self.color = (255,0,0)
- def move (self):
- pygame.draw.rect(screen,self.color,([self.x,self.y],(15,15)),0)
- def intersection(self):
- if Gamer[1]+15>self.y and Gamer[1]<self.y+15 and Gamer[0]+15>self.x and Gamer[0]<self.x+15:
- return True
- return False
- class Target:
- def __init__ (self):
- self.x = randint(15,800-15)
- self.y = randint(15,600-15)
- self.r = randint(2,15)
- self.color = (0,100,255)
- def move (self):
- pygame.draw.rect(screen,self.color,([self.x,self.y],(15,15)),0)
- def intersection(self):
- if Gamer[1]+15>self.y and Gamer[1]<self.y+15 and Gamer[0]+15>self.x and Gamer[0]<self.x+15:
- return True
- return False
- def ChangeOfStation(self):
- self.x = randint(15,800-15)
- self.y = randint(15,600-15)
- myfont = pygame.font.SysFont("monospace", 50)
- clock = pygame.time.Clock()
- c = []
- for i in range(score+1):
- c.append(NoTarget())
- target = Target()
- while done == False:
- # обработчик событий
- clock.tick(90)
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- done = True
- elif event.type == pygame.MOUSEMOTION:
- Gamer = pygame.mouse.get_pos()
- elif event.type ==pygame.KEYDOWN:
- key = pygame.key.get_pressed()
- if key[pygame.K_ESCAPE] == 1:
- done = True
- # логика
- # перерисовка
- screen.fill([0,0,0])
- label = myfont.render(str(int(score)), 1, RED)
- screen.blit(label, (0, 0))
- if target.intersection() and not flag:
- score+=1
- c.append(NoTarget())
- target.ChangeOfStation()
- for i in range(score+1):
- c[i].move()
- if c[i].intersection():
- flag=True
- if flag:
- label = myfont.render("GAME OVER", 1, RED)
- screen.blit(label, (100, 100))
- labelOne = myfont.render("PRESS 'ESCAPE' TO EXIT", 1, RED)
- screen.blit(labelOne, (100, 200))
- target.move()
- pygame.draw.rect(screen,(255,255,255),(Gamer,(15,15)),0)
- pygame.display.flip()
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement