嗨,伙計,我的游戲有問題,當你運行它時我收到這個錯誤,“第 283 行,在 bullets.pop(0)”,“IndexError:從空列表中彈出”,我認為這是因為項目符號列表是空的,它不能彈出它們,但我不知道如何修復它。如果你能幫助我,我將不勝感激。這是代碼,謝謝。import pygameimport mathimport randompygame.init()win = pygame.display.set_mode((800, 400))pygame.display.set_caption("Pandemic")clock = pygame.time.Clock()score = 0walkup = [pygame.image.load("Soldier-1up.png"), pygame.image.load("Soldier-2up.png"), pygame.image.load("Soldier-3up.png")]walkdown = [pygame.image.load("Soldier-1down.png"), pygame.image.load("Soldier-2down.png"), pygame.image.load("Soldier-3down.png")]walkright = [pygame.image.load("Soldier-1right.png"), pygame.image.load("Soldier-2right.png"), pygame.image.load("Soldier-3right.png")]walkleft = [pygame.image.load("Soldier-1left.png"), pygame.image.load("Soldier-2left.png"), pygame.image.load("Soldier-3left.png")]bg = pygame.image.load("map.png")ch = pygame.image.load("Soldier-1up.png")bulletimg = pygame.image.load("bullet.png")walkvirus1 = [pygame.image.load("virus1.png"), pygame.image.load("virus2.png"), pygame.image.load("virus3.png")]walkvirus2 = [pygame.image.load("1virus1.png"), pygame.image.load("1virus2.png"), pygame.image.load("1virus3.png")]background1 = pygame.image.load("menu.png")class player(object): def __init__(self, x, y, width, height): self.x = x self.y = y self.width = width self.height = height self.vel = 5 self.walkcount = 0 self.right = False self.left = False self.up = False self.down = False self.standing = True self.hitbox = (self.x, self.y, self.width, self.height) self.life = 3
IndexError:從pygame中的空列表中彈出
慕蓋茨4494581
2023-03-01 14:44:24