Pac-Man Diary #08

Oh my, and I thought last night was bad. Things start off okay, I manage to implement the ghosts changing into just eyes when you eat them. Simple enough, just hide the appropriate sprite leaving just the eyes. The problem started when I began programming them to go back to the hut when eaten and respawn when they get there. Unfortunately, they decide they don’t actually want to respawn, they’re perfectly happy just being eyes and they have no intention of coming out.

Of course, such behaviour is not acceptable. It takes me over an hour of scrutinizing my code and pulling my hair out to discover the problem. The ghosts target variable is being overwritten as soon as it enters the door to the hut. So they never know that they’ve actually arrived. Adding an ‘eaten’ flag to the hut check fixes the problem instantly.

At least one pair of eyes is still refusing to go back to the central hut, but I’m too tired to check it out right now. Despite these problems and the feeling of treading water I think I’m quite pleased with the overall progress.

Also, I found a nice website called Sounds of Eating with lots of Pac-Man information on it including which graphic is displayed for each level up to 255! In fact, levels 13-255 have the same Key icon. At least I can complete my Sprites bitmap now! Oh, and the article on Billy Mitchell really has to be read to be believed.

Pac-Man Diary #07

I would like to get the Power Pills working tonight. They have have a different code from standard pills in the array so I know when one has been eaten. Changing the ghost sprites to the blue edible ones is a little tricky, but not too bad. I change the collision routines so that you don’t die when you come into contact with an edible ghost and add a timer.

I also want them to start flashing between the blue and the white ghosts sprites for the last few seconds which acts as a warning to the player that they are about to become deadly again. I spend quite a lot of time fine tuning this so it performs like the original arcade. Still not sure if it’s quite right, but it’ll do for now.

Don’t seem to have achieved too much tonight, never mind. Maybe tomorrow will be better.

The latest code is available for download.

Pac-Man Diary #06

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!

Pac-Man Diary #05

Pills, pills…I need some pills! Well, at least for my game anyway. As I discovered earlier, the best method is to have the pills in the with the maze bitmap. I edit it in paint ( I will order PSP, I’m just too busy at the moment). Ok, load it in. Looks ok. Now to use that dirty word ‘collision’ again. I have to check when he’s eaten a pill. I have a couple of ideas on how to implement this, but I decide on setting up another array to mimic the layout of all the pills. I then use the same array coords I use for collision checking (with some offsets) to check if there’s a pill at that point. After some jiggling around with offsets this seems to work just fine. I realize I need a blank out for the pills so this gets added to the sprite bitmap too.

I need to check it properly so I add in a score above the maze. Hmmm….how much for a pill? 10 points is a nice round number. I must check out the original Namco Pac-Man in M.A.M.E to see what you get. Oh yeah, baby. Now I can move around the maze eating pills and getting loads of points. Cool! My red ghost is still wondering around aimlessly and keeps getting himself locked in the central holding area. Oh well, serves him right for being so dumb.

Anyway, I’m on a roll today. Time to stick in some animation. This proves to be rather easy in DarkBasic. Just load in the frames and update the sprite frame displayed as you move. Takes about 10 minutes to code it. 

Right, might as well add the other 3 ghosts. Before I do that, I make the ghost movement subroutine generic so that I can use it for all the ghosts – why write the same thing 4 times? This takes a while but is worth it in the long run. Now adding the other ghosts is a breeze. Each one takes only 5 minutes to code in. Now I have 4 animated ghosts wondering around, Pacman is animated and eating pills, and the score is toting up as you play. Am I good or what? And it’s only 10pm! 

Right, now I’m in the unfortunate position of choosing between adding Pacman/ghost collision detection and animation or playing WWII Online with my virtual friends. WWII Online wins…

Pac-Man Diary #04

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.

Adding a ghost
Adding a ghost

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!

Pac-Man Diary #03

I spend some time screen dumping from M.A.M.E. to capture all the animations for Pac-Man and the ghosts. Pac-Man has 15 different poses. At first I’m fooled into thinking the ghosts are a complete sprite, then I realize that the eyes are actually a separate sprite overlayed onto the ghosts.

an and the ghosts. Pac-Man has 15 different poses. At first I’m fooled into thinking the ghosts are a complete sprite, then I realize that the eyes are actually a separate sprite overlayed onto the ghosts.

This reduces the number of ghost sprites I need to create considerably – only 2 frames of animation in 4 different colours and 4 more for the eadible ghosts (2 blue/brown, 2 white/red). 12 sprites every ghost frame! Nice. The eyes take up 4 sprites for looking up, down, left and right. Having these as a separate sprite also enables you to create the eyes only animation that occurs after you’ve eaten a ghost.


I also get the pills, but now I’m wondering whether the pills should be pre-drawn in the main bitmap. Hmmm. I think so. I’ll fix that later. I manage to get the cherry and strawberry, but due to my very mediocre skills at Pac-Man I fail to get beyond the 2nd level. I need more practice before I can get the rest of the fruit!

I’ve also decided on a name for my Pac-Man clone. It’s going to be called…tune in tomorrow to find out! Only joking, it’s going to be called Wobman. Don’t ask.

Pac-Man Diary #02

Today is collision detection day. Mmmm…my favourite. I use the term ‘day’ loosely, as it’s actually 10pm. I have to go to work you see, and this takes up all my day when I could be doing….anyway, I digress.

Suddenly, I have a remarkable brain wave – why not create a second bitmap of the maze made of simple white solid blocks, then just use the POINT command to check for collisions! I later discover that this amazing technique has been used in platform games for years and I’m humbled again. Anyway, how will DarkBasic cope with it? Not very well as it turns out. The POINT command seems to be extremely slow. At first I thinks it’s just because I’m switching bitmaps to do the check – but no, it’s just as slow when checking the same bitmap. This is BAD NEWS. I make a mental note to post a query on the forums. I have to think up an alternative before I go to bed or I’ll never sleep.

I spend an hour creating DATA statements for the maze to read into an array which I’ll can use for collision checking instead. This is considerably faster. Success at last! Pac-Man is now plodding around my maze without going off in any illegal directions. It’s only when I’m nodding off that I realize I could have just read the bitmap to create the array data rather than typing it all in. Oh well, live and learn.

Pac-Man Diary #01

I’m not sure why, but I’ve decided to keep a diary of my development of a clone of Namco’s original Pac-Man using DarkBasic (this later changed to BlitzPlus – CG).

Who knows, maybe someone will find it interesting or useful!

The Maze
The Maze

Ok, first things first. I ran the original Namco Pac-Man (or is it Puckman?) in M.A.M.E and took a screenshot so I could nab the bitmap of the maze. Then I loaded it into Paint (my 30 day trial on PSP finally ran out on day 358!), and cleared all the pills and ghosts to leave just the plain maze. Using the default 640×480 mode I loaded this into DarkBasic and ran it. Good… fine, just need to centre it on the screen. Also nabbed one frame of Pac-Man himself, it’s the full circle frame so he’s just a yellow ball at the moment. I’ve decided to store all my sprites in another bitmap as 16×16 tiles as this fits exactly into the corridors of the maze.

Added some keyboard reads so I could move him around the maze pretending that all the colliision detection is in place. Keyboard control seems a bit fiddley, must look into that later.