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)))