Please refer to this post for how you can insert your code on the forums nicely
Please feel free to edit your post, and use those code tags in the future.
Okay, onto your issue… If I understood you correctly, you want to disallow diagonal movement?
You can move up, down , left , or right, but not a combination?
I would say you can solve that by doing this:
if(v != 0) {
// move up/down
// just don't write any code that deals with 'h'
}
else {
if(h != 0) {
// here you could only be moving left / right
}
}
As mentioned, while I was posting, the obvious problem was that you were stuck in the while loop because ‘v’ never changes. Be sure to delete that code.