I don't really have time to study ur code right now, but what I would do is just have a char variable called direction, set to 'l', 'r', 'u', or 'd', since pacman can never stop there's no need for 'n', and since he can't change directions mid-tile, only at intersections, I would store another char variable called userDir that is taken from key input, and is always changeable (because you can tell pacman to turn mid-tile, he just won't do it yet) then when he reaches the intersection set direction to userDir. If userDir stays the same pacman will also therefore keep going in that direction. of course check for collision right after setting direction to userDir. Every repaint update his movement and the direction of his image based on the direction variable, not based on userDir. When checking for collision, don't write a separate test for every direction, all you need to do in a tile-based world is say something like if(tiles
- [y] == false) movePacman(); where tile is your world, stored in boolean form (wall == true, space == false) or of course whatever form you want, and where x and y are the coordinates of pacman's goal tile (only do this right at the intersection). This is just what I would do, but I think it's pretty efficient, it shouldn't take up any time at all. Not sure if that helped or not...