import pygame
import random
from pygame.examples.aliens import Player
pygame.init()
sc = pygame.display.set_mode((1500, 800))
clock = pygame.time.Clock()
hp = 100
dl=0
dx=7
dy=7
ix=7
iy=7
plaerX, plaerY=80, 400
plaer = pygame.draw.rect(sc, (50, 50, 50), (plaerX, plaerY , 100, 100), 0)
image = pygame.image.load("foot-soldier-clipart-md.png")
image = pygame.transform.scale(image,(80,150))
imageX, imageY=plaerX, plaerY
provol= pygame.image.load("prov.png")
provol.set_colorkey((255,255,255))
provol = pygame.transform.scale(provol,(250,70))
p = pygame.transform.rotate(provol, 90)
vrag = pygame.image.load("free-sticker-military-6250586.png")
vrag.set_colorkey((255,255,255))
vrag = pygame.transform.scale(vrag, (40, 90,))
phon = pygame.image.load("hon.png")
phon1 = pygame.transform.scale(phon, (1555, 888,))
class Enemy:
    def __init__(self):
        self.x = 1488
        self.y = random.randint(100, 700)
        self.size = 50
        self.speed = random.randint(7, 14)
    def move(self):
        self.x -=self.speed
    def draw(self):
        return sc.blit(vrag,(self.x,self.y))
    def get_rect (self):
        return pygame.Rect(self.x, self.y, 40, 90)

    def draw_png(self):
        return sc.blit(vrag,(self.x,self.y))
enemies = [Enemy() for i in range(13)]
class Bullet:
    def __init__(self, PlaerX, PlaerY):
        self.x = plaerX+80
        self.y = plaerY+75
        self.size = 10
        self.speed = 15
        self.active = True
    def move(self):
        self.x += self.speed
    def draw(self):
        if self.active:
            return pygame.draw.rect(sc, (255, 255,0), (self.x, self.y, self.size, 5))
    def check_collision(self, enemy):
        enemy_rect = pygame.Rect(enemy.x, enemy.y, 40, 90)
        bullet_rect = pygame.Rect(self.x, self.y, self.size, 5)
        return bullet_rect.colliderect(enemy_rect)
bullets = []
cooldown = 0
shoot_delay = 6

go=True
while go:
    dl+=5
    if hp<=0:
        go=False
    Keys = pygame.key.get_pressed()
    sc.fill((87, 88, 87))
    sc.blit(phon1, (0, 0))
    for bullet in bullets[:]:
        bullet.move()
        bullet.draw()
        for enemy in enemies[:]:
            if bullet.check_collision(enemy):
                if bullet in bullets:
                    bullets.remove(bullet)
                enemies.remove(enemy)
                break
        if bullet.x > 1500:
            if bullet in bullets:
                bullets.remove(bullet)
    for e in enemies:
        e.move()
        enemy_rect = e.draw()
    plaer_rect = pygame.Rect(plaerX,plaerY, 80, 150)
    for enemy in enemies[:]:
        enemy_rect=enemy.get_rect()
        if plaer_rect.colliderect(enemy_rect):
            hp-=50
            enemies.remove(enemy)
            if hp <= 0:
                go =False
    font = pygame.font.Font(None, 36)
    hp_text = font.render(f"HP:{hp}", True, (255, 255, 255))
    sc.blit(hp_text, (10, 10))
    if cooldown > 0:
        cooldown -= 1
    if Keys[pygame.K_LEFT]:
        plaerX -= dx
    if Keys[pygame.K_RIGHT] and plaerX<100:
        plaerX += dx
    if Keys[pygame.K_UP]:
        plaerY -= dy
    if Keys[pygame.K_DOWN]:
        plaerY += dy
    if Keys[pygame.K_LEFT]:
        imageX -= ix
    if Keys[pygame.K_RIGHT]:
        imageX += ix
    if Keys[pygame.K_UP]:
        imageY -= iy
    if Keys[pygame.K_DOWN]:
        imageY += iy
    if plaerX<=0:
        go=False
    sc.blit(image, (plaerX, plaerY))
    sc.blit(p, (140, 0))
    sc.blit(p, (140, 250))
    sc.blit(p, (140, 500))
    sc.blit(p, (140, 750))
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            go = False
            pygame.quit()
        if event.type == pygame.MOUSEBUTTONDOWN and cooldown==0:
            if event.button == 1:
                bullets.append(Bullet(plaerX, plaerY))
                cooldown = shoot_delay

    clock.tick(20)