Found a problem with the maze collision. Pac-Man…err…I mean Wobman is able to turn a corner when he isn’t fully in the corridor. After some investigation I discover this is due to the calculations being in done purely in Integers – thus, positions like 17.5 are rounded to 17. This is what is making the program think it’s a valid move.
I change parts of the positional calculations to use Real numbers and after adding some brain-numbing (to me anyway) math, I manage to get it fixed. At last, perfect maze movement. Still the annoying fiddly keyboard controls when moving from a horizontal corridor into a vertical one. I must look into that later. Hmmm…I’m sure I’ve said that before somewhere.
Time to add a ghost to the scene. I grab the red ghost and a pair of eyes from my sprite bitmap. They’re sharing coordinates so only one set needed. I’m just going to put in random direction changes for now.
Deciding when he reaches a wall and has to turn is easy enough, however, it proves much more difficult to know when he’s at a junction part way along a corridor. My first attempt and the ghost moves around as if he’s got a firework up his rear end. He’s moving backward and forward like a yoyo. I decide to put in some code to stop him reversing on himself.
This smooths out his movement nicely and also makes it easier for me to judge those junctions. Oooh, starting to look a bit like a game now!