def blit_screen(screen,text): for dx in range(-8, text.width): screen.blit(text, -dx, 1) pew.show(screen) pew.tick(1 / 12)
#Selecting initial position of the apple apple_x, apple_y = 6, 4 screen.pixel(apple_x, apple_y, 2) #Selecting the initial position of the first noise nx=random.getrandbits(3) ny=random.getrandbits(3) noise=[(nx, ny)] while True: screen.pixel(noise[0][0], noise[0][1],1) ##Now let's implement a loop for the game # Here we are going to print the snake #Here we print the head of the snake x, y = snake[-1] screen.pixel(x, y, 3) pew.show(screen) pew.tick(1 / game_speed) #Here we change the velocity of the snake depending on the key input keys = pew.keys() if keys & pew.K_UP and dy == 0: dx, dy = 0, -1 elif keys & pew.K_LEFT and dx == 0: dx, dy = -1, 0 elif keys & pew.K_RIGHT and dx == 0: dx, dy = 1, 0 elif keys & pew.K_DOWN and dy == 0: dx, dy = 0, 1 #gate switch