def getMove(win,playerX,playerY):
#Define variables.
movePos = 75
moveNeg = -75
running = 1
#Run while loop constantly to update mouse's coordinates.
while(running):
mouseCoord = win.getMouse()
mouseX = mouseCoord.getX()
mouseY = mouseCoord.getY()
print "Mouse X = ", mouseX
print "Mouse Y = ", mouseY
if mouseX >= playerX:
playerX = movePos + playerX
running = 0
elif mouseX <= playerX:
playerX = moveNeg + playerX
running = 0
elif mouseY >= playerY:
playerY = movePos + playerY
running = 0
elif mouseY <= playerY:
playerY = moveNeg + playerY
running = 0
return playerX,playerY
def main():
#Create game window.
win = GraphWin("Python Game", 500, 500)
drawBoard(win)
#Define variables.
playerX = 75
playerY = 125
keyX = 325
keyY = 375
running = 1
#Create Key and Player objects, draw the key, but don't draw the player yet.
key = Text(Point(keyX,keyY),"KEY")
key.draw(win)
while(running):
print "player X = ", playerX
print "Player Y = ", playerY
drawBoard(win)
getMove(win,playerX,playerY)
player = Circle(Point(playerX,playerY),22)
player.setFill('yellow')
player.draw(win)
main()
我正在使用图形库来创建游戏。我的播放器和钥匙被绘制在正确的位置。但是,当调用 getMove 函数时,我的 playerX 和 playerY 没有更新。我添加了调试打印语句以在运行游戏时找到它们的值,它始终是 75 和 125。求助!