import pygame
import random
import time
from Apple import Apple

SCREEN_WIDTH = 800
SCREEN_HEIGHT = 608

#tworzenie tła
background = pygame.Surface((SCREEN_WIDTH,SCREEN_HEIGHT))

for i in range(25):
    for j in range(19):
        image = pygame.image.load("images/background.png")
        mask = (random.randrange(0,20),random.randrange(0,20),random.randrange(0,20))
        #zlewamy maske z konkretnym kafelkiem, aby zmienić minimalny kolor
        image.fill(mask, special_flags=pygame.BLEND_ADD)
        #rozmiar kafelka 32x32
        background.blit(image,(i*32,j*32))

pygame.init()
screen = pygame.display.set_mode([SCREEN_WIDTH, SCREEN_HEIGHT])
clock = pygame.time.Clock()

apple = Apple()
appleGroup = pygame.sprite.Group()
appleGroup.add(apple)

isGameWorks = True

while isGameWorks:

    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                isGameWorks = False
        elif event.type == pygame.QUIT:
            isGameWorks = False

    #rysowanie tła
    screen.blit(background,(0,0))
    #rysowanie jabłek
    for apple in appleGroup:
        screen.blit(apple.image, apple.rect)
    #wyczyszczenie ekranu
    pygame.display.flip()
    #ustawienie stałego fps 30
    clock.tick(30)

time.sleep(3)
pygame.quit()

