0

i have another issue, and this time with a IndexError that i cant solve, the error that jumps onto screen is:

self.image = self.image_list[self.count],
IndexError: list index out of range

rigto = [pygame.image.load("img/Iconos/guy1.png"), pygame.image.load("img/Iconos/guy2.png"), pygame.image.load("img/Iconos/guy3.png"), pygame.image.load("img/Iconos/guy4.png")]
class Player:
    def __init__(self, x, y, image_list):
    self.image_list = image_list
    self.count = 0

    self.image = self.image_list[self.count]
    self.rect = self.image.get_rect(topleft = (x, y))

def update(self): # update se utiliza para la posicion del jugador y su movilidad
    dx = 0
    dy = 0
    self.count += 1
    frame = self.count // 10
    if frame >= len(self.image_list):
        self.count = 0
        frame = 0
    self.image = self.image_list[self.count]
    key = pygame.key.get_pressed()
    if key[pygame.K_a]:
        dx -= 5
        self.direction = -1
    if key[pygame.K_d]:
        dx += 5
        self.direction = 1
    if key[pygame.K_w]:
        dy -= 5
    if key[pygame.K_s]:
        dy += 5
    if key[pygame.K_z]:
        pygame.mixer.music.play(-1, 0.0, 5000)
        draw_text("Tienes " + str(money) + " monedas", font_score, (0, 0, 0), 800, 10)
    # update player coordinates
    self.rect.x += dx
    self.rect.y += dy

def draw(self):
    pantalla.blit(self.image, self.rect)
jugador1 = Player(500, 500, rigto)
  • `self.image = self.image_list[frame]` instead of `self.image = self.image_list[self.count]` – Rabbid76 Jan 01 '22 at 19:37
  • You have no idea what this code does, do you. Stack Overflow is not a debug service. You need to learn the basics before asking a question. With a basic knowledge of Python, you will find it easy to answer such questions yourself. Please read [Python debugging tips](https://stackoverflow.com/questions/1623039/python-debugging-tips) and please do not ask questions like these. – Rabbid76 Jan 01 '22 at 19:40

0 Answers0