Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, random
- class number(pygame.sprite.Sprite):
- def __init__(self, numeral):
- super().__init__()
- self.image1 = pygame.Surface((50, 50))
- self.image1.fill((255, 255, 100))
- self.image2 = font.render(f'{numeral}', True, (200, 200, 200))
- self.image = self.image2
- self.rect = self.image.get_rect()
- self.number = numeral
- self.rect.center = (random.randrange(50 ,750), random.randrange(50 ,550))
- def show_number(self):
- self.image = self.image2
- def hide_number(self):
- self.image = self.image1
- pygame.init()
- window = pygame.display.set_mode((800, 600))
- font = pygame.font.Font('freesansbold.ttf', 50)
- run = True
- clock = pygame.time.Clock()
- block_grp = pygame.sprite.Group()
- limit = 3
- timer = 0
- score = 0
- speed = 0
- for x in range(limit):
- block = number(x+1)
- block_grp.add(block)
- temp = True
- while temp:
- clock.tick(30)
- window.fill((255, 255, 255))
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- run = False
- print("Quit")
- temp = False
- if event.type == pygame.MOUSEBUTTONDOWN:
- print("MBDOWN")
- mouseposition = pygame.mouse.get_pos()
- for d in block_grp:
- if d.rect.collidepoint(mouseposition):
- speed = d.number
- print("Clicked Number")
- temp = False
- block_grp.empty()
- window.blit(font.render(f'Select speed', True, (255, 150, 200)), (370, 10))
- block_grp.update()
- block_grp.draw(window)
- pygame.display.update()
- while run:
- window.fill((255,255,255))
- for x in range(limit):
- block = number(x+1)
- block_grp.add(block)
- response = True
- current_number = 1
- while response:
- clock.tick(30)
- timer += 1
- window.fill((255, 255, 255))
- if timer > speed*30:
- for x in block_grp:
- x.hide_number()
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- run = False
- response = False
- if event.type == pygame.MOUSEBUTTONDOWN and timer > 150:
- mouseposition = pygame.mouse.get_pos()
- for d in block_grp:
- if d.rect.collidepoint(mouseposition):
- if d.number == current_number:
- d.kill()
- block_grp.remove(d)
- print(1)
- current_number += 1
- else:
- run = False
- response = False
- if len(block_grp) == 0:
- limit += 1
- response = False
- timer = 0
- score += 1
- window.blit(font.render(f'{score}', True, (255, 150, 200)), (370, 10))
- block_grp.update()
- block_grp.draw(window)
- pygame.display.update()
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement