def getMove(win,playerX,playerY):
#Define variables.
movePos = 75
moveNeg = -75
running = 1
#Run while loop constantly to update mouse\'s coordinat
As has been mentioned, the solution is that you're not using the returned values to update your playerX, playerY
which can be fixed with the mentioned
playerX, playerY = getMove(win,playerX,playerY)
What I want to address is the logic in your if
statements. The way you've constructed your if
statements will lead to only an X OR Y being updated, not both. For example, if mouseX, mouseY
were both greater than playerX, playerY
repectively, you'd get to the first line of your if
statement and it would be evaluated as True
and update playerX
accordingly, BUT because the first statement has been executed, none of the other elif
statements will execute, leading to you only updating the playerX
variable.
What you want to do is split the if
statement into two separate statements (one for X and one for Y) so that the adjustments of X,Y are independent of each other. Something similar to
if mouseX >= playerX:
playerX = movePos + playerX
running = 0
elif mouseX <= playerX:
playerX = moveNeg + playerX
running = 0
#By having the second if, it allows you to check Y even if X has changed
if mouseY >= playerY:
playerY = movePos + playerY
running = 0
elif mouseY <= playerY:
playerY = moveNeg + playerY
running = 0