import os.path

import pygame
from os import path
import random

img_dir = path.join(path.dirname(file), 'img')

# game_folder = os.path.dirname(file)
# img_folder = os.path.join(game_folder,'img')


WIDHT = 1280  # ШИРИНА ИГРОВОГО ОКНА
HEIGHT = 720  # ВЫСОТА
FPS = 60  # КАДРЫ В СЕКУНДУ

WHITE = (255, 255, 255)  # БЕЛЫЙ
BLACK = (0, 0, 0)  # ЧЕРНЫЙ
RED = (255, 0, 0)  # КРАСНЫЙ
GREEN = (0, 255, 0)  # ЗЕЛЕНЫЙ
BLUE = (0, 0, 255)  # СИНИЙ
ORANGE = (255, 183, 115)  # ОРАНЖЕВЫЙ
BROWN = (105, 75, 0)

pygame.init()
pygame.mixer.init()
screen = pygame.display.set_caption("Котость")
clock = pygame.time.Clock()

snake_block = 10
snake_speed = 15


class cat(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        # self.image = pygame.Surface((snake_block, snake_block))
        self.image = pygame.image.load('img/player1.png').convert_alpha()
        self.image = pygame.transform.scale(self.image, (snake_block, snake_block))
        self.rect = self.image.get_rect()
        self.rect.x = WIDHT / 2
        self.rect.y = HEIGHT / 2
        self.dx = 0
        self.dy = 0
        self.body = []  # список
        self.lenght = 1
        self.score = 0

    def update(self):
        self.rect.y += self.dy
        self.rect.x += self.dx

        self.body.append([self.rect.x, self.rect.y])
        if len(self.boby) > self.lenght:
            del self.body[0]

        for segment in self[:-1]:
            if segment[0] == self.rect.x and segment[1] == self.rect.y:
                return False
        return True

    def draw_body(self, surface):
        for segment in self.body[:-1]:
            pygame.draw.rect(surface,BROWN,segment[0], segment[1],snake_block,snake_block)

     def grow(self):
        self.lenght += 1
        self.score += 1


 class Food(pygame.sprite.Sprite):
      def __init__(self):
        super().__init__()
        self.image = pygame.Surface((snake_block, snake_block))
         self.image.fill(LIME)
         self.rect = self.image.get_rect()
            self.respawn()

player_img = pygame.image.load(path)