这是我遇到问题的代码的相关部分。player.x 和 player.y 在调试控制台中收到“AttributeError: type object ‘player’ has no attribute ‘x’”错误。我有一个名为“player”的单独类,我想在它四处移动时获得它的 x 和 y 坐标,以便敌人可以向它移动。这是播放器类的开始部分,也是相关的:class player(object): def __init__(self, x, y, sprintMultiplier, fps): self.x = x self.y = y self.vel = 1/fps * 150class enemy(object): def __init__(self, fps, difficulty): pass def draw(self, window): self.moveTowardsPlayer() window.blit(self.downStanding, (self.x, self.y)) def moveTowardsPlayer(self): dx, dy = self.x - player.x, self.y - player.y dist = math.hypot(dx, dy) dx, dy = dx/dist, dy/dist self.x += dx * self.vel self.y += dy * self.vel
添加回答
举报
0/150
提交
取消