import pygame, sys, time, math from pygame.locals import * pygame.init() displaysurface = pygame.display.set_mode((1920,1080)) background = pygame.Surface((1920,1080)) tag = 255 mySurface = pygame.Surface((41,41)) mySurface.fill((tag,255-tag,0)) mySurface2 = pygame.Surface((41,41)) mySurface2.fill((255-tag,tag,0)) k = 0 base_font = pygame.font.Font(None, 32) pos1 = [940, 520] pos2 = [0, 0] direction = 90 ddirection = 0 while True: zombiespeed = 10 xdist = pos1[0] - pos2[0] ydist = pos1[1] - pos2[1] dist = abs(xdist) + abs(ydist) pos2[0] += xdist / dist * zombiespeed/17 pos2[1] += ydist / dist * zombiespeed/17 for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() key = pygame.key.get_pressed() if key[pygame.K_LEFT]: ddirection = 2 if key[pygame.K_RIGHT]: ddirection = -2 if not (key[pygame.K_LEFT] or key[pygame.K_RIGHT]): ddirection = 0 direction += ddirection / 500 pos1[0] += math.sin(direction) / 2 pos1[1] += math.cos(direction) / 2 if pos1[0] > 1880: break if pos1[0] < 0: break if pos1[1] > 1040: break if pos1[1] < 0: break rect1 = mySurface.get_rect(topleft=pos1) rect2 = mySurface2.get_rect(topleft=pos2) if rect1.colliderect(rect2): break displaysurface.blit(background, (0,0)) displaysurface.blit(mySurface, pos1) displaysurface.blit(mySurface2, pos2) k += 1 user_text = str(k / 1000) + "s" text_surface = base_font.render(user_text, True, (0, 255, 0)) displaysurface.blit(text_surface, (10, 10)) pygame.display.update() displaysurface.blit(background, (0,0)) base_font = pygame.font.Font(None, 100) user_text = "Game over! Your final time: " + str(k / 1000) + "s" text_surface = base_font.render(user_text, True, (255, 255, 255)) displaysurface.blit(text_surface, (400, 520)) pygame.display.update() time.sleep(3)