0
\$\begingroup\$

I have a set of moving chess pieces and am now trying to implement the rules to prevent them from going anywhere. The pawns use this code to move: (Sorry for the blurriness, the IDE did it automatically when I zoomed out so I could get it all.)Code

When I go to move the Pawn, it won't move at all. Weirdly, when I had the if statement at the top set to true, it would work just fine, just excluding the moving double on the first move.

What is causing this problem, and how can I fix it?

\$\endgroup\$
0
\$\begingroup\$

The reason the pieces are not moving is that it never does the first section of code, and when it runs the second section, the only place it lets it move is the spot it is already in.

It never runs the first section because when you click on the pawn the first time it changes the value of the variable before it even moves. In the second section, the mouse_y >= y && mouse_y <= (y + 64) is the 64 by 64 grid the pawn is in as its location is determined by the top left corner.

To fix this, you would make it so that it does not change until after it has moved instead of when the player clicks on it, and change the y + 64 to y + 128.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy