我正在尝试制作一个游戏,我想在玩家移动之前保存玩家的位置(oldPosition),以便我以后可以使用它。问题是,当 World.UpdateContents() 运行时,oldPosition 与 self.position 一起更新。当 self.position 发生变化时,如何防止 oldPosition 发生变化?
def Move(self, direction):
oldPosition = self.position
print oldPosition
if direction == "Up":
if self.position[0] - 1 in World.worldMap[0]:
self.position[0] -= 1
if direction == "Down":
if self.position[0] + 1 in World.worldMap[0]:
self.position[0] += 1
if direction == "Left":
if self.position[1] - 1 in World.worldMap[1]:
self.position[1] -= 1
if direction == "Right":
if self.position[1] + 1 in World.worldMap[1]:
self.position[1] += 1
print oldPosition
World.UpdateContents(world, oldPosition, self.position, self.icon)