This was shown Traceback (most recent call last):
File "C:/Users/PC GAMER/Desktop/pygame sprite/oo.py", line 46, in <module> redrawGameWindow() File "C:/Users/PC GAMER/Desktop/pygame sprite/oo.py", line 35, in redrawGameWindow win.blit(walk_right[walk_Count//3], (x, y)) IndexError: list index out of range
I am extremely new to python in general and pygame I don't really understand what's wrong with this although I know what its trying to say that the item in the list that I'm trying to get is not available but I don't really know what to do if possible please kindly explain how to fix this thankyou for taking your time to read this as my English is not great and thank you for your time in general
import pygame
pygame.init()
Clock = pygame.time.Clock()
win = pygame.display.set_mode((500, 500))
pygame.display.set_caption("Hello")
x = 100
y = 400
width = 64
height = 64
vel = 10
walk_right = [pygame.image.load("R1.png"), pygame.image.load("R2.png"), pygame.image.load("R3.png"),
pygame.image.load("R4.png"), pygame.image.load("R5.png"), pygame.image.load("R6.png"),
pygame.image.load("R7.png"), pygame.image.load("R8.png")]
walk_left = [pygame.image.load("L1.png"), pygame.image.load("L2.png"), pygame.image.load("L3.png"),
pygame.image.load("L4.png"), pygame.image.load("L5.png"), pygame.image.load("L6.png"),
pygame.image.load("L7.png"), pygame.image.load("L8.png")]
bg = pygame.image.load("bg.jpg")
char = pygame.image.load("standing.png")
left = False
right= False
walk_Count = 0
jump_count = 10
jump = False
run = True
def redrawGameWindow():
global walk_Count
if walk_Count + 1 >= 27:
walk_Count = 0
if left:
win.blit(walk_left[walk_Count//3], (x, y))
elif right:
win.blit(walk_right[walk_Count//3], (x, y))
walk_Count += 1
else:
win.blit(char, (x, y))
pygame.display.update()
win.blit(bg, (0, 0))
#Mainloop
while run:
redrawGameWindow()
Clock.tick(27)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
if keys[pygame.K_RIGHT] and x < 450:
right = True
left = False
x += vel
elif keys[pygame.K_LEFT] and x > -10:
x -= vel
left = True
right = False
else:
right = False
left = False
walk_Count = 0
if not jump:
if keys[pygame.K_SPACE]:
left = False
right = False
jump = True
else:
if jump_count >= -10:
neg = 1
if jump_count < 0:
neg = -1
y -= (jump_count ** 2) /2 * neg
jump_count -= 1
else:
jump = False
jump_count = 10
pygame.quit()