self.pos = [(38,38),(119,63),(181,21),(35,189),(119,157),(169,219),(15,323),(95,303),(183,319)]
background = "">
screen.blit(background, (0,0))
pygame.display.flip()
flag = False
score = 0
allowed_time = 600 #change this variable to control the speed of the game. In miliseconds.
time_to_run = 200 #change this variable to play longer.
hit = False
life = 3
score = 0
time_elapsed = 0
IMG.MICE = load_image('mice.png', -1)
IMG.MICE=pygame.transform.scale(IMG.MICE, (50,50))
IMG.DOG = load_image('dog.png', -1)
IMG.DOG=pygame.transform.scale(IMG.DOG, (50,50))
IMG.CAT = load_image('cat.png', -1)
actors = [Mice(), Mice(), Mice(), Mice(), Dog(), Cat()]
while True:
screen.blit(background, (0,0))
r = randint(0,5)
k = randint(0,8)
actors[r].draw(screen,k)
pygame.display.update()
time = pygame.time.Clock()
time_passed = 0
while True:
time_passed = time.tick()+time_passed
time_elapsed = time.tick()+time_elapsed
if time_passed > allowed_time:
break
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
flag = True
break
pressed_key = pygame.key.get_pressed()
if pressed_key[K_q] and k==0:
hit = True
break
if pressed_key[K_w] and k==1:
hit = True
break
if pressed_key[K_e] and k==2:
hit = True
break
if pressed_key[K_a] and k==3:
hit = True
break
if pressed_key[K_s] and k==4:
hit = True
break
if pressed_key[K_d] and k==5:
hit = True
break
if pressed_key[K_z] and k==6:
hit = True
break
if pressed_key[K_x] and k==7:
hit = True
break
if pressed_key[K_c] and k==8:
hit = True
break
if life < 0:
break
if flag is True:
break
if hit is True:
if r==4 or r==5:
life = life-1
else:
score = score+1
print(score)
if time_elapsed > time_to_run:
break
hit = False
background = "">
background.fill((255,255,0))
score = str(score)
score = "Your score is "+ score
print(score)
while True:
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
sys.exit()
screen.blit(background, (0,0))
my_font = pygame.font.SysFont("arial", 28)
score_surface = my_font.render(score, True, (0,0,0))
screen.blit(score_surface, (34, 24))
my_font_1 = pygame.font.SysFont("arial", 16)
quit_surface = my_font_1.render("Press esc to Quit", True, (0,0,0))
screen.blit(quit_surface, (64, 300))
pygame.display.flip()
if __name__ == '__main__':main()