windows
Получаю ошибку pygame.error: Passed a NULL pointer. Что делать?
Python:
import pygame
clock = pygame.time.Clock()
pygame.init()
screen = pygame.display.set_mode((378,133))
pygame.display.set_caption('pygame itproger game')
icon = pygame.image.load('images/icon.webp').convert_alpha()
pygame.display.set_icon(icon)
bg = pygame.image.load('images/download.jpg').convert_alpha()
walkl = [
pygame.image.load('nleft/111.png'),
pygame.image.load('nleft/222.png'),
pygame.image.load('nleft/333.png'),
pygame.image.load('nleft/444.png'),
]
walkr = [
pygame.image.load('nright/555.png'),
pygame.image.load('nright/666.png'),
pygame.image.load('nright/777.png'),
pygame.image.load('nright/888.png'),
]
ghost = pygame.image.load('images/download.jpg').convert_alpha()
ghostlis = []
anim = 0
bg_x = 0
player_speed = 5
player_x = 150
player_y = 250
isjump = False
jump_count = 8
ghostimer = pygame.USEREVENT+1
pygame.time.set_timer(ghostimer, 2500)
label = pygame.font.Font('fonts/RobotoMono-Italic-VariableFont_wght.ttf',40)
l_label = label.render('Вы проиграли',False,(237, 29, 14))
relabel = label.render('Играть заново', False,(237, 29, 14))
relare= relabel.get_rect(topleft=(180,120))
bullets_left = 5
bullet = pygame.image.load('images/pyla.png')
bullets = []
gameplay = True
running = True
while running:
screen.blit(bg,(bg_x,0))
screen.blit(bg, (bg_x+378, 0))
if gameplay:
player_rect = walkl[0].get_rect(topleft = (player_x, player_y))
if ghostlis:
for(i,el)in enumerate(ghostlis):
screen.blit(ghost,el)
el.x-=10
if el.x <-10:
ghostlis.pop(i)
if player_rect.colliderect(el):
gameplay = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
screen.blit(walkl[anim],(player_x,player_y))
else:
screen.blit(walkr[anim], (player_x, player_y))
if keys[pygame.K_LEFT] and player_x>50:
player_x -=player_speed
elif keys[pygame.K_RIGHT] and player_x <200:
player_x += player_speed
if not isjump:
if keys[pygame.K_SPACE]:
is_jump = True
else:
if jump_count>=-8:
if jump_count>0:
player_y-=(jump_count**2)/2
else:
player_y += (jump_count ** 2) / 2
else:
isjump = False
jump_count = 8
if anim ==3:
anim =0
else:
anim+=1
bg_x-=2
if bg_x==-378 :
bg_x=0
else:
screen.fill((189, 97, 91))
screen.blit(l_label,(180,100))
screen.blit(relabel, relare)
mouse = pygame.mouse.get_pos()
if relare.collidepoint(mouse) and pygame.mouse.get_pressed()[0]:
gameplay = True
player_x =150
ghostlis.clear()
bullets.clear()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
if event.type== ghostimer:
ghostlis.append(ghost.get_rect(topleft=(620,250)))
clock.tick(50)