Пожалуйста помогите советом, как в программе сделать определённое кол-во противников и так, чтобы после определённого кол-ва убитых была победа.

Bogan__5

Новичок
Пользователь
Май 10, 2023
2
0
1
Python:
import pygame

pygame.init()
screen = pygame.display.set_mode((1800, 1000))
pygame.display.set_caption("igra")
icon = pygame.image.load('idle.png')
pygame.display.set_icon(icon)

gameplay = True
label = pygame.font.Font('RifficFree-Bold.ttf', 100)
lose_label = label.render('ВЫ ПРОИГРАЛИ!', False, (193, 196, 199))
restart_label = label.render('Играть заново', False, (115, 132, 149))
restart_label_rect = restart_label.get_rect(topleft=(400, 700))
bag = pygame.image.load('fon.png')
player = pygame.image.load('idle.png')
player_speed = 5
player_x = 0
player_y = 675
is_jump = False
jump_count = 7
bag_x=0
fon_sound = pygame.mixer.Sound('fon.mp3')
fon_sound.play()
ghost = pygame.image.load('prot.jpg')
ghost_list_in_game = []
ghost_timer = pygame.USEREVENT + 1
pygame.time.set_timer(ghost_timer, 5000)

running = True
while running:

    screen.blit(bag, (bag_x, 0))
    screen.blit(bag, (bag_x + 1800, 0))
    screen.blit(player, (player_x, player_y))

    if gameplay:
            
        player_rect = player.get_rect(topleft=(player_x, player_y))

        if ghost_list_in_game:
            for (i, el) in enumerate(ghost_list_in_game):
                screen.blit(ghost, el)
                el.x -= 10

                if el.x < -10:
                    ghost_list_in_game.pop(i)

                if player_rect.colliderect(el):
                    gameplay = False

        keys = pygame.key.get_pressed()
        if keys[pygame.K_LEFT] and player_x > 0:
            player_x -= player_speed
        elif keys[pygame.K_RIGHT] and player_x < 1750:
            player_x += player_speed

        if not is_jump:
            if keys[pygame.K_SPACE]:
                is_jump = True
        else:
            if jump_count >= -7:
                if jump_count > 0:
                    player_y -= (jump_count ** 2) / 2
                else:
                    player_y += (jump_count ** 2) / 2
                jump_count -= 1
            else:
                is_jump = False
                jump_count = 7

        bag_x -= 1
        if bag_x == -1800:
            bag_x = 0
    else:
        screen.fill((87, 88, 89))
        screen.blit(lose_label, (400, 500))
        screen.blit(restart_label, (400, 700))

        mouse = pygame.mouse.get_pos()
        if restart_label_rect.collidepoint(mouse) and pygame.mouse.get_pressed()[0]:
            gameplay = True
            player_x = 0
            ghost_list_in_game.clear()

    pygame.display.update()

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            pygame.quit()
        if event.type == ghost_timer:
            ghost_list_in_game.append(ghost.get_rect(topleft=(1800, 675)))
 

Вложения

  • fon.png
    fon.png
    129,2 КБ · Просмотры: 0
  • prot.jpg
    prot.jpg
    19,3 КБ · Просмотры: 0
  • idle.png
    idle.png
    2,5 КБ · Просмотры: 0
  • bullet.png
    bullet.png
    385 байт · Просмотры: 0

regnor

Модератор
Команда форума
Модератор
Июл 7, 2020
2 580
457
83
делаете счетчик, после убийства увеличиваете этот счетчик, в цикле while проверяете этот счетчик на каждой итерации
 

Форум IT Специалистов