window.blit(self.esright[self.Walking//3], (self.x,self.y))
IndexError: list index out of range
이 문제를 해결하는 방법을 잘 모르겠습니다. 고치려고했지만 같은 오류가 계속 발생합니다.
# this makes the enemy move right and left
def draw(self,window):
self.move()
if self.Walking + 1 >= 33:
self.Walking = 0
if self.vel > 0:
window.blit(self.esright[self.Walking//3], (self.x,self.y))
self.Walking += 1
else:
window.blit(self.esleft[self.Walking//3], (self.x,self.y))
self.Walking += 1
적의 계급
# ---------------------------------------------- # this for bird my g LOl
class bird:
def __init__(self,x,y,height,width,end):
self.x = x
self.y =y
self.esright = [pygame.image.load("bird1.png"),
pygame.image.load("bird2.png"),
pygame.image.load("bird3.png"),
pygame.image.load("bird4.png")
]
self.esleft = [pygame.image.load("b1.png"),
pygame.image.load("b2.png"),
pygame.image.load("b3.png"),
pygame.image.load("b4.png")
]
self.esright = [pygame.transform.scale(image,(image.get_width()//5,image.get_height()//5)) for image in self.esright]
self.esleft = [pygame.transform.scale(image,(image.get_width()//5,image.get_height()//5)) for image in self.esleft]
self.height = height
self.width = width
self.distance = 80
self.speed = 8
self.vel = 3
self.path = [x,end]
self.Walking = 0
self.hitbox = (self.x + 17, self.y + 2, 31, 57)
self.rect = pygame.Rect(x,y,height,width)
# enemys health
self.health = 10
self.soko = 0
self.visible = True
# this makes the enemy move right and left
def draw(self,window):
self.move()
if self.Walking + 1 >= 33:
self.Walking = 0
elif self.vel > 0:
window.blit(self.esright[self.Walking//3], (self.x,self.y))
self.Walking += 1
else:
window.blit(self.esleft[self.Walking//3], (self.x,self.y))
self.Walking += 1
# this moves the enemy left and right
def move(self):
if self.visible:
if self.vel > 0:
if self.x + self.vel < self.path[1]:
self.x += self.vel
else:
self.vel = self.vel * -1
self.Walking = 0
else:
if self.x - self.vel > self.path[0]:
self.x += self.vel
else:
self.vel = self.vel * -1
self.Walking = 0
# the hit box for the enemy the health
pygame.draw.rect(window, (255,0,0), (self.hitbox[0], self.hitbox[1] - 20, 70, 10)) # NEW
pygame.draw.rect(window, (0,255,0), (self.hitbox[0], self.hitbox[1] - 20, 70 - (5 * (10 - self.health)), 10))
self.hitbox = (self.x + 47, self.y + 31, 50, 72)
# THIS PART MAKES the enemy not scroll with the player
def scroll(self,sx, sy):
self.x += sx
self.y += sy
self.path[0] += sx
self.path[1] += sx
# define the enemy class
black = (0,0,0)
bird1 = bird(300,199,104,64,500)
birds = [bird1]
페페 스페 스페 페스 페페 스페 페스 페스 페스 페페 스페 스페 스페 스페 스페 스페 스페 스페 스페 스페 스페 스페 스페 스페 스페 스페 스페 스페
변경 self.Walking//3
에 self.Walking % 4
당신이이 같은 반복 될 때마다 계산하려면 :
0 1 2 3 0 1 2 3 0 1...etc
변경 self.Walking//3
에 int(self.Walking / 4) % 4
당신이이 같은 반복 될 때마다 계산하려면 :
0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3 0 0 0 0 1 1 1 1...etc
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다