I realized that making pacman change direction into a new tunnel was very hard since the key had to be pressed at the exact pixel to avoid collision. This would have led to frustrating gameplay. The solution was to keep track of the arrow key that was pressed last - the game knows where the player would like to go and checks at each step if the move can be made. Making turns is now much easier.
The ghosts now check for collisions and make a random decision for the new direction. Pacman follows keyboard input but the icon does not represent the correct direction yet. However, everything stays within the map and makes legal moves.
After adding the ghosts, I worked on implementing continuous motion - not step by step. The ghosts and pacman all move smoothly now, but only pacman checks for collisions - the ghosts can still go through walls and through each other.