My main task for this evening is to add some Artificial Intelligence (AI) to the ghosts. At the moment they’re just picking random directions and they’re not even doing that very well. My plan is to let them know the coordinates of Wobman so they have a ‘target’ to head for.
I have to rewrite the ghost movement code to take this ‘targeting’ into account. I don’t feel any nostalgia over deleting the random movement code. The targeting proves more complex than I anticipated. It isn’t just a case of looking at Wobmans coordinates and moving in that direction, as that direction may not be available to the ghost. So, what I did was try to move towards him and if that isn’t possible, choose a random direction. This direction can be any except the one opposite to that in which you are currently moving. So, if the ghost is going left, he can’t decide to go right. This should stop them from jiggling backwards and forwards like idiots.
I try this code out. Whoa! They chase you like bloodhounds. All four of them homing in on me like Wobman seeking missiles. Maybe I’ll make this Level 20 or something. For now, I’ll have to make them a bit dumber. I add an ‘intelligence’ setting for each ghost. This just says how often to check on Wobman’s coordinates. The higher the number, the dumber they are. After a few tweaks (it’s amazing how little you have to check), I have a level one-ish setting. The ghosts seem fairly individual in their tracking methods, which is good.
I add in the collision detection, which is extremely simple, between Wobman and the ghosts, and code in 3 lives and a game loop. I now have a pretty much complete game done in less than a week!