O
O
O2topGG2020-05-02 16:02:26
Python
O2topGG, 2020-05-02 16:02:26

People help not showing sprite in pygame?

Here is the code

import pygame

pygame.init()#Инициализируем окно
win = pygame.display.set_mode((500, 500))#Со3даем окно 500 на 500px

pygame.display.set_caption('Cube')#Называем наше окно

walkRight = [pygame.image.load('right_1.png'),
            pygame.image.load('right_2.png'), 
            pygame.image.load('right_3.png'), 
            pygame.image.load('right_4.png'), 
            pygame.image.load('right_5.png'), 
            pygame.image.load('right_6.png')]

walkLeft = [pygame.image.load('left_1.png'), 
            pygame.image.load('left_2.png'), 
            pygame.image.load('left_3.png'), 
            pygame.image.load('left_4.png'), 
            pygame.image.load('left_5.png'), 
            pygame.image.load('left_6.png')]

bg = pygame.image.load('bg.jpg')
playerStand = pygame.image.load('idle.png')

clock = pygame.time.Clock()

x = 50 #Положение куба по х
y = 435 #Положение куба по игрику
width = 60 #Ширина куба
height = 71 #Высота куба
speed = 10 #Скорость куба

isJump = False
jumpCount = 10

left = False
right = False
animCount = 0

def drawWindow():
    global animCount
    win.blit(bg, (0,0))

    if animCount + 1 >= 30:
        animCount = 0

        if left:
            win.blit(walkLeft[animCount // 5], (x, y))
            animCount += 1
        elif right:
            win.blit(walkRight[animCount // 5], (x, y))
            animCount += 1
        else:
            win.blit(playerStand, (x, y))

    
    pygame.display.update()#Постоянное обновление

run = True
while run:
    clock.tick(30)#цыкл выполняется каджые 0,1 секунду

    for event in pygame.event.get():
        if event.type == pygame.QUIT: #если в масие ивент обнаружена команда закрыть то закрыть
            run = False

    keys = pygame.key.get_pressed()
    if keys[pygame.K_LEFT] and x > 5:
        x -= speed
        left = True
        right = False

    elif keys[pygame.K_RIGHT] and x < 500 - width - 5:
        x += speed
        left = False
        right = True
    else:
        left = False
        right = False
        animCount = 0

    if not(isJump):
        if keys[pygame.K_SPACE]:
            isJump = True
    else:
        if jumpCount >= -10:
            if jumpCount < 0:
                y += (jumpCount ** 2) / 2
            else:
                y -= (jumpCount ** 2) / 2
            jumpCount -= 1
        else:
            isJump = False
            jumpCount = 10
    drawWindow()
    
pygame.quit()#Так чтоб наверняка закрылось


And here is the error
Traceback (most recent call last):
  File "C:\Users\Володимир\Desktop\Game\game.py", line 8, in <module>
    walkRight = [pygame.image.load('right_1.png'),
pygame.error: Couldn't open right_1.png

And so with all the sprites

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
IDzone-x, 2020-06-10
@O2topGG

It looks like you wrote the code according to the Gosha Dudar guide, right?
I also had such an error, you just need to take each file into sukobok and write open in them.
Better take this course, it's more informative
https://younglinux.info/pygame.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question