所以這裏是我的問題,我在使我的盜賊喜歡遊戲的開始,我堅持讓敵人追逐玩家,它必須是簡單明瞭的東西,但我的技能在相當低的......因此,這裏是我的怪獸級怪物蔡斯pygame
class monster():
def __init__(self , mright, mleft, mup, mdown):
self.mright = pygame.image.load(mright).convert_alpha()
self.mleft = pygame.image.load(mleft).convert_alpha()
self.mup = pygame.image.load(mup).convert_alpha()
self.mdown = pygame.image.load(mdown).convert_alpha()
self.sqrx = 7
self.sqry = 2
self.x = 210
self.y = 60
self.direction = self.mdown
char = character(right , left , up , down , Level)
def chase(self,direction):
if self.sqrx > char.sqrx :
self.sqrx -= 1
self.x = self.sqrx * size_sprite
self.direction = self.mleft
if self.sqrx < char.sqrx :
self.sqrx += 1
self.x = self.sqrx * size_sprite
self.direction = self.mright
if self.sqry > char.sqry :
self.sqry -= 1
self.y = self.sqry * size_sprite
self.direction = self.mup
if self.sqry < char.sqry :
self.sqry += 1
self.y = self.sqry * size_sprite
self.direction = self.mdown
而且遊戲循環
while gameon:
pygame.time.Clock().tick(30)
for event in pygame.event.get():
if event.type == QUIT:
gameon = 0
on = 0
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
gameon = 0
elif event.key == K_RIGHT:
char.move('right')
elif event.key == K_LEFT:
char.move('left')
elif event.key == K_UP:
char.move('up')
elif event.key == K_DOWN:
char.move('down')
level.display(window)
window.blit(monst.direction , (monst.x , monst.y))
window.blit(char.direction , (char.x , char.y))
pygame.display.flip()
您在代碼中有錯誤的縮進。在'chase'中你總是設置'self.direction = self.mdown' – furas
@furas self.direction只是字符 – Haza
的精靈,但是'chase(self,direction):'always set' self.direction = self.mdown ' - 不管你使用什麼'方向'。 (順便說一下:「評論」是對所有代碼發表評論的地方,不僅僅是答案/解決方案) – furas